Virtual env doesn't get a package from top python installation

Welcome,

I don’t know why, but when I make a new virtual environment for python, I can’t import packages that I’ve installed in the top (i.e. system-wide) environment.

For example, when I type:

import gi

In the top python it imports without problems. While I do the same in my venv I get:

Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import gi
ModuleNotFoundError: No module named 'gi'

A special command line option is needed to create a venv that inherits from the system environment: --system-site-packages

2 Likes

Specifically, python -m venv --system-site-packages <path>.

1 Like