Pycharm, virtualenv, and editable modules not being found in PYTHONPATH

I am having trouble with pycharm and virtualenv's. 

Packages installed in a virtualenv with "pip -e" (editable repos, basically) are being ignored. The -e flag puts them in /<virtualenv name>/src/ instead of /<virtualenv>/lib/python2.7/site-packages/. 

 

Scripts run from the command line with an active virtualenv work fine. In pycharm, after setting up the venv in my project settings, it finds every script except the packages installed with the -e flag. Running the script in pycharm also fails at the first import using a package installed with the -e flag.

The -e is what we use to bring in other module, but keeping their .git directory intact, inside our projects.

To reproduce:

 - Create a venv: "virtualenv venv --no-site-packages"

 - Create a requirements.txt file with a line like this: "-e git+ssh://git@github.com:7999/my/package.git#egg=package"

- Activate the venv "source venv/bin/activate"

- Install the requirements.txt WITH the virtualenv active: "pip install --upgrade -r requirements.txt --ignore-installed"

- Add the virtualenv location to pycharm, https://www.jetbrains.com/help/pycharm/2016.1/creating-virtual-environment.html?origin=old_help

- See the -e package be ignored by pycharm.

 

Also tested in intellij. Same behavior.

 

 

 

9
4 comments

Exact same problem here. Anyone with a solution to this or is this a PyCharm bug?

0

I managed to get this working by adding the package directory (<virtualenv>/src/<package>) to the "Interpreter Paths" in the interpreter configuration.

Open the "Project Interpreters" dialog (Settings -> Project Interpreter -> Gear icon -> More... ->).  Select the interpreter, and one of the buttons on the right is "Show paths for selected interpreter".  You can add the new path here.

Kind of a pain, and there might be an better way to get there, but I think this could be automatically detected by PyCharm.

1

As of writing this can be circumvented by:

1. Open Settings -> Project -> Project Structure

2. Navigate to your .venv/src directory in the tree

3. Mark it as a sources root.

Source Folders: .venv/src should appear in the right hand column

0

Please sign in to leave a comment.