Search code examples
pythonpycharmvirtualenv

PyCharm: Refresh virtual environment for a project


The problem

I have a few projects in PyCharm, each with its own virtual environment.

Quite often, I add packages to these virtual environments using the CLI, mainly with python setup.py develop from another local package.

The new package appear in Preferences -> Project -> Project Interpreter and the calls to the newly-installed packages runs, but the imports still appear as erroneous, which drives me nuts:

enter image description here

What have I tried

  • Changing the virtual environment to a different one, than switching back, hoping it would reload. Did not work.
  • Restarting PyCharm. Works, but it's fairly slow, so I don't consider it a solution.

How do I refresh the virtual environment


Solution

  • For PyCharm 2018.3.4, I solved this by verifying that the correct source locations are specified under File/Settings/Project::Project Structure. All of the valid source directories should be marked as "Sources" and the venv directory should marked as Excluded, at least that's what worked for me.