0

I would like to install a python virtualenv with relative paths, so that I can move the virtualenv to another machine (that has the same operative systems). I googled about a solution, some suggests using the --portable options of the virtualenv command, but it is not available on my system. Maybe it is old?

Apart from changing the paths by hand, are there any other official way to create a portable virtualenv?

I am planning to use this on OSX and Linux (without mixing them of course).

buscon
  • 15
  • 5
  • 1
    *"move the virtualenv to another machine*" This is usually a bad idea. You should create a new virtualenv and install the same dependencies – DeepSpace Sep 27 '22 at 14:14
  • 1
    You will not be able to move virtual environment between machines with different operating systems. It might be possible between machines that have very similar setups. – Klaus D. Sep 27 '22 at 14:15
  • Might wanna ask the question why you want to do what you are doing too. IIRC virtualenvironment or venv comes with Python...sooo you would be missing VENV probably only if you do not have Python? – Jason Chia Sep 27 '22 at 14:19
  • Thanks for your comments, I probably have to look for another solution, probably something that @TommyD posted below. – buscon Sep 27 '22 at 18:32

1 Answers1

0

The goal of virtualvenv is to create isolated Python environments.

The basic problem being addressed is one of dependencies and versions, and indirectly permissions.

Creating portable installations is not the supported use case:

Created python virtual environments are usually not self-contained. A complete python packaging is usually made up of thousands of files, so it’s not efficient to install the entire python again into a new folder. Instead virtual environments are mere shells, that contain little within themselves, and borrow most from the system python (this is what you installed, when you installed python itself). This does mean that if you upgrade your system python your virtual environments might break, so watch out.

You could always try to run a virtual environment on another machine that has the same OS, version and packages. But be warned, for having tried it myself in the past it is very fragile and prone to weird errors.

There are other tools to do what you are looking for depending on your use case and target OS (e.g. single executable, MSI installer, Docker image, etc.). See this answer.

TommyD
  • 731
  • 8
  • 14