How do I add paths to my virtualenv so that both PyCharm and the interpreter can find the external packages?

Yesterday, I edited the `bin/activate` script of my virtualenv so that it sets the `PYTHONPATH` environment variable to include a development version of some external package. I had to do this because the of the package uses distutils and does not support the `develop` command à la setuptools. Setting `PYTHONPATH` works fine as far as using the Python interpreter in the terminal is concerned.

However, just now I opened the project settings in PyCharm and discovered that PyCharm is unaware of the external package in question - PyCharm lists neither the external package nor its path. Naturally, that's because PyCharm does not (and cannot reliably) parse or source the `bin/activate` script. I could manually add the path in the PyCharm project settings, but that means I have to repeat myself (once in `bin/activate`, and again in the PyCharm project settings). That's not DRY and that's bad.

Creating, in site-packages, a symlink that points to the external package is almost perfect. This way, at least the source editor of PyCharm can find the package and so does the Python interpreter in the terminal. However, somehow PyCharm still does not list the package in the project settings and I'm not sure if it's ok to leave it like that.

So how can I add the external package to my virtualenv/project in such a way that…

1. I don't have to repeat myself; and…
2. both the Python interpreter and PyCharm would be aware of it?
Where exactly do you expect PyCharm to list the package? The list of packages in Settings | Python Interpreters shows only packages installed into your PyCharm installation using pip or setuptools; it won't show packages installed in any other way, and it shouldn't matter in your situation.
Exactly. I was expecting to see the package in Settings | Python Interpreters. Now I understand that only packages installed through pip or setuptools are shown there.

I have now removed the `PYTHONPATH` from `bin/activate` and, instead, use a symlink in `site-packages`. So it's safe to leave it like that (with my external package not showing up in Settings | Python Interpreters), right?

Hi! Sorry to necro this post.  I'm using PyCharm on windows and I, too, often want to import the development version of a different project into my code.  I used powershell to create a symlink in the site-packages dir in the projects virtual environment library.  From the python console i can import the packages I need and they work, but in the code editor the imports are marked as 'unresolved reference' errors.

Any idea how I can get the editor to stop showing the errors? 


I edited bin/activate.csh to add the extra path(in bold) to the following variable : 

setenv VIRTUAL_ENV "/Users/sufyanelahi/dev/axiom-v1.5.0/env/school:/Applications/"


Please sign in to leave a comment.