Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use python virtual environment in another computer

I have created an virtual environment by using virtualenv pyenv in my linux system. Now i want to use the virtual environment in another computer. Can i direct copy the virtual environment and use it in another computer? Or need i do something to set up it?

like image 328
Tao Avatar asked Oct 16 '14 08:10

Tao


2 Answers

You should not. The other computer can have a different operating system, other packages or package versions installed, so copying the files will not work.

The point of a virtual environment is to be able to replicate it everywhere you need it.

Make a script which installs all necessary dependencies from a requirements.txt file and use it.

Use pip freeze > requirements.txt to get the list of all python packages installed. Then install the dependencies in another virtual environment on another computer using pip install -r requirements.txt.

If you want the exact environment, including system packages, on another computer, use Docker.

like image 126
warvariuc Avatar answered Oct 17 '22 17:10

warvariuc


You can use copy and paste it in another directory or computer, but its not a best way to use virtualenv. you better notedown your requirements in any txt file like requirement.txt and run the use pip freeze > requirement.txt to write all the requirements in requirement.txt

script using pip.

pip install -r requirement.txt
like image 4
Vishnu Upadhyay Avatar answered Oct 17 '22 19:10

Vishnu Upadhyay