python:加载共享库时出错:libpython3.4m.so.1.0:无法打开共享对象文件:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43333207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
提问by user785099
I have created a python virtual environment using virtualenv, after activating it, I can see where is Python installed,
我使用virtualenv创建了一个python虚拟环境,激活后可以看到Python安装在哪里,
(virtualenv-test) bash-4.1$ whereis python
python: /usr/bin/python2.6 /usr/bin/python2.6-config /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/X11R6/bin/python2.6 /usr/X11R6/bin/python2.6-config /usr/X11R6/bin/python /usr/bin/X11/python2.6 /usr/bin/X11/python2.6-config /usr/bin/X11/python /usr/include/python2.6 /usr/share/man/man1/python.1.gz
(virtualenv-test) bash-4.1$ which python
/data/virtualenv-test/bin/python
(virtualenv-test) bash-4.1$ whereis python
python: /usr/bin/python2.6 /usr/bin/python2.6-config /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/X11R6/bin/python2 .6 /usr/X11R6/bin/python2.6-config /usr/X11R6/bin/python /usr/bin/X11/python2.6 /usr/bin/X11/python2.6-config /usr/bin/X11 /python /usr/include/python2.6 /usr/share/man/man1/python.1.gz
(virtualenv-test) bash-4.1$ which python
/data/virtualenv-test/bin/python
However, after typing python, I got the following error message, what can be the underlying reason?
但是,在键入 python 后,我收到以下错误消息,潜在原因是什么?
(virtualenv-test) bash-4.1$ python
python: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directory
回答by williezh
- Someone said that this way can fix the problem (I don't know whether it work, because I fix the problem another way): add py3.4's lib path to the $LD_LIBRARY_PATH environment variable First find out the lib path of python3.4(in the folder which it installed), like me is: /opt/python361/lib, then add it to environment variable:
- 有人说这种方式可以解决问题(不知道行不行,因为我用另一种方式解决了问题):将py3.4的lib路径添加到$LD_LIBRARY_PATH环境变量中 首先找出python3.4的lib路径(在它安装的文件夹中),像我一样是:/opt/python361/lib,然后将其添加到环境变量中:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/python361/lib
- I met the similar problem when use virtualenv with python3.6, and I fix the follow way:
- First, edit
sudo vi /etc/ld.so.conf, add lib path of python3.x to this file(like me is: /opt/python361/lib), and save the modify of this conf file; - Then, active this file by
sudo /sbin/ldconfig -v. That's all.
- First, edit
- 我在 python3.6 中使用 virtualenv 时遇到了类似的问题,我修复了以下方法:
- 首先编辑
sudo vi /etc/ld.so.conf,将python3.x的lib路径添加到这个文件中(比如我是:/opt/python361/lib),并保存这个conf文件的修改; - 然后,通过
sudo /sbin/ldconfig -v. 就这样。
- 首先编辑
回答by Pobe
export LD_LIBRARY_PATH=[your python path to libpython3.4m.so]
export LD_LIBRARY_PATH=[your python path to libpython3.4m.so]
libpython3.4m.sois under your python source from which you built it.
libpython3.4m.so在您构建它的python源下。
Put it in your .bashrc to set it at login automatically.
将它放在您的 .bashrc 中以在登录时自动设置它。
I can't force virtualenv to 3.4 on my machine but you can see that under libof your virtualenv there's just a bunch of symlink to your local python installation. I guess libpython3.4m.sois fetch by one of those.
我无法在我的机器上强制 virtualenv 为 3.4,但是您可以看到在lib您的 virtualenv下,只有一堆指向本地 python 安装的符号链接。我想libpython3.4m.so是由其中之一获取的。
回答by buxizhizhoum
Another way is adding LDFLAGS="-Wl,-rpath /usr/local/lib"in configure, for example
另一种方法是添加LDFLAGS="-Wl,-rpath /usr/local/lib"配置,例如
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
/usr/local/libis the path where libpython3.*.sofiles are in
/usr/local/lib是libpython3.*.so文件所在的路径
回答by A. Attia
For Python 3.6, it was fixed by
对于 Python 3.6,它被修复了
sudo apt-get install libpython3.6-dev
回答by Sina
Kudos to above, For python 3.X you can fix this issue with:
感谢以上,对于python 3.X,您可以通过以下方式解决此问题:
sudo apt-get install libpython3.x-dev
No need to any changes to environment path manually.
无需手动更改环境路径。
回答by Jake
On python 3.8, I resolved this by deleting the virtualenv directory (./venvin my case) and recreating using python's built-in venvmodule installed of the pip-installed virtualenv. I'm on arch linux and also first did sudo pacman -Syu. Python was originally installed using just sudo pacman -S python.
在 python 3.8 上,我通过删除 virtualenv 目录(./venv在我的例子中)并使用venv安装了 pip-installed 的python 内置模块重新创建来解决这个问题virtualenv。我在 arch linux 上,也是第一次使用sudo pacman -Syu. Python 最初仅使用sudo pacman -S python.
$ rm -r ./venv
$ python -m venv venv
$ . ./venv/bin/activate
$ python --version
Python 3.8.1

