Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm doesn't use selected virtualenv

PyCharm seems to ignore the configured virtualenv, and use the base interpreter instead.

In my project at /Users/janos/dev/git/github/bashoneliners I have a virtualenv subdirectory, strictly with my project's dependencies installed in it:

$ . virtualenv/bin/activate
(virtualenv)janos at kronos in ~/dev/git/github/bashoneliners on master
$ pip -V
pip 1.5.6 from /Users/janos/dev/git/github/bashoneliners/virtualenv/lib/python3.4/site-packages (python 3.4)
(virtualenv)janos at kronos in ~/dev/git/github/bashoneliners on master
$ pip freeze
Django==1.9
Markdown==2.6.5
PyJWT==1.4.0
defusedxml==0.4.1
oauthlib==1.0.3
pep8==1.6.2
pyflakes==1.0.0
python-social-auth==0.2.13
python3-openid==3.0.9
requests==2.9.1
requests-oauthlib==0.6.0
six==1.10.0
tweepy==3.5.0

But if I add this virtualenv as Project Interpreter in PyCharm, it shows completely different packages:

enter image description here

These packages are the same as in my system's base interpreter /opt/local/bin/python. This drives me nuts, I really need to use the packages from the virtualenv, not from my system.

This is with PyCharm Community Edition 5.0.3.

I didn't have this problem before with older versions of PyCharm. I tried creating a completely new virtualenv, both on the command line and using PyCharm, and invalidating caches and restarting, but nothing seems to work. PyCharm always shows the same list of packages, and the packages of the virtualenv. Even if I create an empty virtualenv within PyCharm, it doesn't start empty, but filled with the same list of packages.

My project works perfectly when I run things on the command line, such as running Django management commands, unit tests, everything. I only have problems in PyCharm.

If I try to install packages, for example Django, using PyCharm, I get this error:

enter image description here

Of course permission denied on /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages, that's the system interpreter. It should be trying to install the package there, but in /Users/janos/dev/git/github/bashoneliners/virtualenv.

Clearly it's not using pip from the virtualenv, but from the system. I need to make to use the one from the virtualenv.

like image 660
janos Avatar asked Jan 01 '16 21:01

janos


1 Answers

This is logged as a bug in the issue tracking system of JetBrains, so hopefully it will get sorted out soon.

https://youtrack.jetbrains.com/issue/PY-18074

A possible workaround is to fall back to a previous version of PyCharm:

https://confluence.jetbrains.com/display/PYH/Previous+PyCharm+Releases

As of 2016 Jan 6, virtualenv works fine for me in PyCharm 4.5.4. Some of the virtualenv previously registered using PyCharm 5.0.3 appear invalid, but that's fine. I actually deleted all registered interpreters and re-added only the virtualenv I needed.

An odd thing with this older version is that sometimes PyCharm shows the incorrect Python version (2.7 instead of 3.5), but it shows the correct list of modules as per the virtualenv, and the editor doesn't show build errors, so the Python version mixup doesn't seem to cause problems (just a bit scary).

like image 168
janos Avatar answered Oct 03 '22 04:10

janos