I have the latest PyCharm CE and am using it with virtualenv
. I have defined the interpreter as the interpreter in the virtualenv
. The Project Interpreter window in PyCharm lists all the packages I have installed. I confirmed this by running pip freeze > requirements.txt
and running through the packages manually.
My problem is that PyCharm won't find certain includes in its editor windows, like Flask-Login
:
In from flask.ext.login import current_user, login_user, logout_user, login_required
the includes current_user, login_user, logout_user, login_required
are all marked as unresolved references.
Am I missing something?
Calling pip command inside a virtualenv should list the packages visible/available in the isolated environment.
The problem may lay in PyCharm picking up faulty 'Interpreter Paths' for your virtual environment. Go here:
PyCharm (menu) -> Preferences (Menu option) -> Project: <name> (Dropdown) -> Project Interpreter (Menu option) -> 'Settings' button (Looks like a gear) -> More (Menu option) -> Select your virtualenv interpreter -> Click 'Show paths for interpreter' button (on bottom of list window)
Now that you're in this (admittedly tortuously found) location, you should see paths being used by this interpreter. If my theory is correct, these are pointing to global system locations. To add the virtual environment paths, you should click the +
button and add corresponding paths that exist inside your virtual environment. Once you're done with this, it's a good idea to select the global system paths and click -
to remove them. Click apply, and go to File -> Invalidate caches / Restart
to reload PyCharm.
This should get your interpreter to be pointed to the correct location for the libraries you've installed into your virtualenv, and you should no longer be getting the import error. Note that even with this fix you will not see your libraries under the Project Interpreter
, but they should be being loaded.
In the newest version of PyCharm (2016.1.4 in my case):
See image below for better explanation (like they said, 1 picture worth thousands word)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With