Python PyCharm 找不到库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33812902/
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
PyCharm cannot find library
提问by Karnivaurus
I am using PyCharm 5 to run a Python 2.7 (Anaconda) script in Ubuntu. My script imports a module with import tensorflow
, but this causes the error ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory
. So, it seems that the library libcudart.so.7.0
is needed by this module, but it cannot be found.
我正在使用 PyCharm 5 在 Ubuntu 中运行 Python 2.7 (Anaconda) 脚本。我的脚本使用 导入了一个模块import tensorflow
,但这会导致错误ImportError: libcudart.so.7.0: cannot open shared object file: No such file or directory
。所以,libcudart.so.7.0
这个模块好像需要这个库,但是找不到。
Now, I have seen that this library is on my machine in /usr/local/cuda-7.0/targets/x86_64-linux/lib
. So, in PyCharm, I went to Settings->Project Interpreters->Interpreter Paths
. This had a list of paths, such as /home/karnivaurus/Libraries/Anaconda/python2.7
. I then added to this list, the path mentioned above which contains the required library.
现在,我已经看到这个库在我的机器上/usr/local/cuda-7.0/targets/x86_64-linux/lib
。所以,在 PyCharm 中,我去了Settings->Project Interpreters->Interpreter Paths
. 这有一个路径列表,例如/home/karnivaurus/Libraries/Anaconda/python2.7
. 然后我将上面提到的包含所需库的路径添加到此列表中。
However, this did not fix the problem. I still get an error telling me that libcudart.so.7.0
cannot be found. If I run my script from the shell though (python myfile.py
), then it runs fine.
然而,这并没有解决问题。我仍然收到一个错误,告诉我libcudart.so.7.0
无法找到。如果我从 shell 运行我的脚本(python myfile.py
),那么它运行良好。
How can I tell PyCharm where to find this library?
我如何告诉 PyCharm 在哪里可以找到这个库?
I have noticed that if I have print sys.path
in my script, the paths it prints out are entirely different to those in Settings->Project Interpreters->Interpreter Paths
... should they be the same?
我注意到,如果print sys.path
我的脚本中有,它打印出的路径与Settings->Project Interpreters->Interpreter Paths
...中的路径完全不同吗?它们应该相同吗?
采纳答案by ktx
I came across this problem just recently using a remote debugger, however I believe it's still the same solution. I just added the following to the Environment Variables section in the Run/Debug Configuration options found in Run > Edit Configurations... dialog: LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
我最近使用远程调试器遇到了这个问题,但我相信它仍然是相同的解决方案。我刚刚在 Run > Edit Configurations... 对话框中找到的 Run/Debug Configuration 选项中的 Environment Variables 部分添加了以下内容:LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
回答by Laizer
The path to your cuda library seems strange to me. I would expect it to be /usr/local/cuda-7.0/lib64
or /usr/local/cuda-7.0/lib
.
你的 cuda 库的路径对我来说似乎很奇怪。我希望它是/usr/local/cuda-7.0/lib64
或/usr/local/cuda-7.0/lib
。
Did you follow all of the cuda installationprocedure?
您是否遵循了所有cuda 安装程序?
If you type env
on the command line, do you see a path to cuda in your LD_LIBRARY_PATH
?
如果您env
在命令行上输入,您是否在LD_LIBRARY_PATH
?
Update from comments below:
从下面的评论更新:
The issue is that PyCharm was invoked from the desktop, and wasn't getting the right environment variables. Solution is to either:
问题是 PyCharm 是从桌面调用的,并且没有获得正确的环境变量。解决方案是:
- invoke from the command line,
- create a script to set environment and then invoke, and make a link to that script on the desktop,
- or set environment variables on the desktop item
- 从命令行调用,
- 创建一个脚本来设置环境然后调用,并在桌面上创建一个指向该脚本的链接,
- 或在桌面项上设置环境变量
回答by Seb
回答by u5272981
Edit your pycharm.desktop
, specify the environment variable in exec, like below:
编辑您的pycharm.desktop
,在 exec 中指定环境变量,如下所示:
[Desktop Entry]
Version=1.0
Type=Application
Name=Pycharm
Exec=env LD_LIBRARY_PATH=:/usr/local/cuda/lib64:/usr/local/cuda/lib64 /home/cwh/software/pycharm-2016.1.4/bin/pycharm.sh
Icon=/home/cwh/software/pycharm-2016.1.4/bin/pycharm.png
Name[zh_CN]=Pycharm
so pycharm
will find cuda
所以pycharm
会发现cuda
回答by John
While some of these answers are correct, and could work, I haven't seen what the OP specifically asked for, and that is where to set environments for the python console. This can be accomplished inside pycharm at:
虽然其中一些答案是正确的,并且可以工作,但我还没有看到 OP 的具体要求,那就是为 python 控制台设置环境的地方。这可以在 pycharm 中完成:
File > Settings > Build,Execution,Deployment > Console > Python Console
文件 > 设置 > 构建、执行、部署 > 控制台 > Python 控制台
In the options there, you'll find a place to define Environment Variables. Set LD_LIBRARY_PATH there.
回答by David Soroko
The following works for me on Community edition 2019.3
以下对我有用 Community edition 2019.3
To set globally for a project:
为项目全局设置:
- Open
File/Settings/Project/Project Interpreter
- click on the cog icon next to the interpreter
- choose show all
- click on the little folder with tree icon bottom right
- add the path to "Interpreter Paths"
- 打开
File/Settings/Project/Project Interpreter
- 单击解释器旁边的齿轮图标
- 选择显示全部
- 单击右下角带有树形图标的小文件夹
- 将路径添加到“解释器路径”