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:
How do I refresh the virtual environment
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.
I had similar issue mainly with local packages except I used pip install -e .
and anaconda environment. This worked for me:
Ctrl + Shift + A
shortcut Instead of the first step you can use Help -> Find Action
and then type " Rescan ... ".
The only advantage of this solution is you don't have to restart PyCharm which is really annoying. But it does "Rescan", so does not help with speed much.
I have no enough reputation to comment on @Nerxis post. To complement his answer, I couldn't find " Rescan Available Python Modules and Packages " on Help > Find Action
but it was on the Preferences
search bar. You can define the key binding in Preferences > Keymap > Plugins > Python
, in my case there was no key binding.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.