I'm not able to add specific directory to python path

I've installed numpy and scipy via pip into ~/.local/lib/python3.8/site-packages. In the normal system terminal, importing numpy works. Then I tried it to use in Pycharm:

Attempt 1:

I've added the folder to the interpreter paths, which then shows up in the "external libraries" correctly. Intellisense in editor does also work when I import the numpy package. BUT: the directory is not in the python path and importing doesn't work when I run the code. See following screenshot:

 

Attempt 2:

Secondly, I tried to add this path in the project structure as "Source", which makes some kind of reference inside the project, but importing still doesn't work:

Attempt 3:

As a third attempt, I added the folder manually inside the script, which works:

 

However, attempt 3 is an annoying workaround. I don't understand why attempt 1 + 2 don't work. Any ideas?

Pycharm Version: 2020.02

System: Linux Mint 20

 

Many Thanks in advance!

5 comments
Comment actions Permalink

Hi,

I tried to reproduce your scenario by installing numpy to custom dir using `pip install --target`, then added this dir to interpreter paths and it worked, so your first attempt it correct, however I'm not sure why the path wasn't added to sys.path.

Could you please try to delete and recreate the project interpreter, then add the path again. If that doesn't work, please provide for further investigation:

1. Logs from **Help | Collect Logs and Diagnostic Data**

2. <ide_config_dir>/options/jdk.table.xml file

https://www.jetbrains.com/help/pycharm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#config-directory

You can use our uploading service at https://uploads.jetbrains.com/ , and provide upload ID in your reply.

0
Comment actions Permalink

Hi, many thanks for trying to reproduce it.

I tried to delete and add the interpreter and added the path again - same behaviour.

This is the log file you asked for ("show log in file browser didn't show any effect, so I browsed to ~/.var/app/com.jetbrains.PyCharm-Community/cache/JetBrains/PyCharmCE2020.2/log, hope this is correct):

Upload id: 2020_11_02_Di1xuT5pV57KX9c6 (file: threadDump-20201102-185341.txt)

The file jdk.table.xml I couldn't find. Under "~/.config/" there is no folder "JetBrains", as suggested in https://www.jetbrains.com/help/pycharm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html?_ga=2.9466165.123137394.1604338957-1136857134.1603533892#plugins-directory  Is there any different location to search for this file?

Could it be, that PyCharm on Linux Mint is a problem? Seems that there is a mess with the directories...

Thanks for your help anyways!

 

0
Comment actions Permalink

The default config directory location described here https://www.jetbrains.com/help/pycharm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#config-directory, but can be changed by modifying platform properties https://www.jetbrains.com/help/pycharm/tuning-the-ide.html#configure-platform-properties

If you're not sure where the config is located, try searching your file system for "jdk.table.xml" file.

Also, uploaded log is just one thread dump. The log directory should contain at least "idea.log" file which is what needed.

Could you please find and upload logs and jdk table file? Also, please provide directory listing of the custom site-packages folder.

0
Comment actions Permalink

jdk.table.xml (it was under ~/.var/app/com.jetbrains.PyCharm-Community/config/JetBrains/PyCharmCE2020.2/options although I never changed the config path):

Upload id: 2020_11_03_DMdqwna6XFm2uMzQ (file: jdk.table.xml)

 

Here is the log file (hope it's the correct file now, it was under ~/.var/app/com.jetbrains.PyCharm-Community/cache/JetBrains/PyCharmCE2020.2)

Upload id: 2020_11_03_UokapTaEz5i2UsPx (file: log.zip)

 

Directory listing of my site-packages:

~/.local/lib/python3.8/site-packages$ ls -1
certifi
certifi-2020.6.20.dist-info
cycler-0.10.0.dist-info
cycler.py
dateutil
kiwisolver-1.2.0.dist-info
kiwisolver.cpython-38-x86_64-linux-gnu.so
matplotlib
matplotlib-3.3.2.dist-info
matplotlib-3.3.2-py3.8-nspkg.pth
mpl_toolkits
numpy
numpy-1.19.2.dist-info
numpy.libs
__pycache__
pylab.py
python_dateutil-2.8.1.dist-info
scipy
scipy-1.5.3.dist-info
scipy.libs

 

You write about a "custom site package folder": For package installation, I just used "python3 -m pip install xyz" without any additional path name, which caused the packages to install into "~/.local/lib/python3.8/site-packages/", so I assumed, this would be the default path for pip on Linux.

Also, I'd like to recall, that when running python3 in normal system terminal, sys.path does include "~/.local/lib/python3.8/site-packages", without adding it somewhere manually.

0
Comment actions Permalink

Thank you for the data.

Ah, so you did not intentionally installed to "~/.local/lib/..."? 

While I'm still not sure why PyCharm didn't this path to interpreter paths, if you don't have a particular need to install packages into that specific directory, I can suggest a workaround to use virtualenv.

Simply create a new virtualenv interpreter and install numpy, scipy, and any other package you need from PyCharm (https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html). This should give you an environment where you can import those packages.

0

Please sign in to leave a comment.