How add default packages to all new python's venvs

I use Python and pip trhough the asdf version manager, and in my older PC, when I create a new venv it already came with some default packages. I’m now using a newer verison of python (3.9.12) and pip (22.0.4), and it does not come with basic and essential things, such as the gnureadline, to be able to see the commands history in the python’s shell. It’s really annoying having to install it again in all new venvs and I’m trying to avoid an alias to create a venv and install what I want inside it. There is a way to set some default packages to all venvs?

>Solution :

There is an option:

                      Give the virtual environment access to the system
                      site-packages dir.

So if you use python3 -m venv --system-site-packages .venv then you may install the packages you want available to all envs at the system level. You’ll have to be hygienic about the packages installed at the system level.

If the system python on your distribution is a hot mess, and you can’t remove things you don’t want visible in venvs from it, then you’ll want to look for another option.

One possibility is just to install common packages to some target directory:

python3 -m pip install dep1 dep2 --target=/path/to/common

And then make this directory of packages always visible:

export PYTHONPATH=/path/to/common

Leave a Reply