17

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tao
  • 205
  • 1
  • 2
  • 6

3 Answers3

24

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.

warvariuc
  • 57,116
  • 41
  • 173
  • 227
4

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
Vishnu Upadhyay
  • 5,043
  • 1
  • 13
  • 24
  • Thanks. First i run the command pip freeze > requirement.txt and when i moved the code to other pc i did: pip install -r requirement.txt. – rodrigorf Feb 19 '18 at 20:19
-1

If your goal is to make sure that everything including your OS are the same in both computers then you can use virtual box and vagrant on top to setup a virtual box and then create your virtualenv using either requirements or any other way to reproduce it.

https://docs.vagrantup.com/v2/getting-started/

Nick Sorros
  • 121
  • 1
  • 6