Reputation: 24111
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.
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.
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.
How can I tell PyCharm where to find this library?
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?
Upvotes: 21
Views: 32517
Reputation: 9086
The following works for me on Community edition 2019.3
To set globally for a project:
File/Settings/Project/Project Interpreter
Upvotes: 0
Reputation: 1273
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:
File > Settings > Build,Execution,Deployment > Console > Python Console
In the options there, you'll find a place to define Environment Variables. Set LD_LIBRARY_PATH there.
Upvotes: 11
Reputation: 141
Edit your pycharm.desktop
, specify the environment variable in exec, like below:
[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
Upvotes: 3
Reputation: 476
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
Upvotes: 36
Reputation: 21
Have you selected the right python interpreter in your project's settings? See here.
I had a similar issue and changing the interpreter solved it without having to create a new icon.
Upvotes: 2
Reputation: 6140
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
.
Did you follow all of the cuda installation procedure?
If you type env
on the command line, do you see a path to cuda in your 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:
Upvotes: 14