问题
I'm a newbie with PyCharm and Mac OS. I created a python project in PyCharm with VirtualEnv, and I didn't select the option of 'Inherit global site packages'. After working on this project for a while, I realized I need to inherit some packages that are installed globally.
There is a workaround here, which creates a shared Virtual Environment and uses it: Create shared virtual env. However, I wonder whether there is any way to make changes to current project, rather than creating a new project or creating a shared virtual environment?
A separate question: assuming that I have a project that inherits global packages. If after the project's creation, I installed other packages globally, will those packages available in this project?
Thank you very much for your help. Any suggestion is appreciated.
回答1:
I figured this out when clicking around.
In Pycharm, go to File -> Settings... -> Project -> Project Interpreter, click on the gear icon next to the menu:
Then choose "Show all...", and select the virtual environment you want to change, click this icon to add global packages' path into this venv's path
then click ok or apply to make it work. Usually, your global packages' path is "/path-to-python/Lib/site-packages", for my desktop is:
Now you can use all your global packages within the venv. For any system other than Windows, this should work fine as well.
But you won't see any global packages in pycharm's package viewer for this venv, which totally makes sense, because pycharm can only manager the venv for you, not the global one.
For your separate question: Yes. Because you only add global path into your venv, not like copying all package files into it. After adding the global path, all global packages should work inside your venv at any time.
来源:https://stackoverflow.com/questions/52921165/make-a-pycharm-project-inheriting-global-site-packages-after-creating-the-proje