Make a PyCharm project inheriting global site-packages, after creating the project?

痞子三分冷 提交于 2020-08-01 08:22:31

问题


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.

  1. In Pycharm, go to File -> Settings... -> Project -> Project Interpreter, click on the gear icon next to the menu:

  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!