Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to created nested virtual environments for python?

While working on some automation scripts, I found the need to have some common packages available to all the scripts (like ipython and spyder) and installing only the, let's call it differential packages for each script. Is there a way to have nested virtual environment in python? That is, some way to set the environments so that python would first looks at the innermost environment; if not found, it would look on the second innermost environment and so on until reaching the system wide environment for a package?

The closest I could find was to use the venv module with the --system-site-packages option but I couldn't achieve what I looking for: first, I don't want to install packages on the system using root permissions; second, I couldn't find a way to nest virtual environments using this option.

What's the best way to achieve this nested virtual environments structure, if there's one?

like image 325
user13079354 Avatar asked Oct 28 '22 00:10

user13079354


1 Answers

No, there isn't any such "nesting" feature in venv.

I think your best bet would be to define the common packages in a requirements file and then install those at the time when you create a new virtual environment

pip install -r requirements-common.txt
like image 147
wim Avatar answered Nov 15 '22 05:11

wim