Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pycharm

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?

like image 855
user2830451 Avatar asked Oct 22 '18 00:10

user2830451


People also ask

How do I inherit global packages in PyCharm?

Select the Inherit global site-packages checkbox if you want that all packages installed in the global Python on your machine to be added to the virtual environment you're going to create. This checkbox corresponds to the --system-site-packages option of the virtualenv tool.

How do I install PyCharm packages for all projects?

Expand the list of the available versions in the upper-right corner of the tool window. Select the required version or keep it the latest. Click the Install button next to the version list. Once PyCharm notifies you about successful installation, you should see the package in the list of the installed packages.


1 Answers

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: enter image description here

  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 enter image description here

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: enter image description here

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.

like image 96
Brandon Avatar answered Oct 18 '22 21:10

Brandon