[Tutor] moving a virtual environment to a new machine

Mats Wichmann mats at wichmann.us
Mon Jul 20 14:03:19 EDT 2020


On 7/20/20 11:37 AM, Anil Felipe Duggirala wrote:
> hello,
> 
> When I am moving to a new machine, and I have python projects that are
> working with particular virtual environments. What is the best practice
> to recreate these virtual environments in the new machine. Assume, for
> example, that I will be working on the same operating system on the new
> machine.
> 
> I have tried just copying the venv folders to a usb pendrive, but there
> appear to always be symlinks or some kind of links that are not easily
> copied (they may be in a system folder).
> 
> Will simply creating a new environment (in the new machine) an pip
> installing the required packages create a "practically identical"
> virtual environment? does git serve any purpose in achieving this?

virtualenvs can be created with or without symlinks, ones with aren't
going to be very useful unless the target system is set up the same as
the originating one. (this varies by command, "virtualenv" takes a
--always-copy argument, venv takes --copies, etc.).

but recreating them can be useful, and easy enough.  To repopulate a
virtualenv use a "requirements.txt" file (the name isn't magical, that's
just the conventional name), at which point you can:

python -m pip install -r requirements.txt

Helpfully, you can generate that file very easily, inside the original
virtualenv do:

python -m pip freeze > requirements.txt


I guess in some cases you might have to pay attention to versions of
things...



More information about the Tutor mailing list