How to use python virtual environment on another computer

I created a virtual environment using virtualenv pyenv

on my linux system. Now I want to use a virtual environment on another computer. Can I copy the virtual environment and use it on another computer? Or do I need to do something to customize it?

+4


source to share


3 answers


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

The point of a virtual environment is to be able to copy it wherever you need it.

Make a script that installs all required dependencies on a requirements.txt

file and use it.



Use pip freeze > requirements.txt

to get a list of all installed python packages. Then install the dependencies in a different virtual environment on a different machine using pip install -r requirements.txt

.

If you want the exact environment, including system packages, on a different machine, use Docker.

+10


source


You can use a copy and paste it into another directory or computer, but this is not the best way to use virtualenv. you better notice your requirements in any txt file like require.txt and run use pip freeze > requirement.txt

to write all requirements inrequirement.txt

script with pip

.



pip install -r requirement.txt

      

+3


source


If your goal is to make sure everything, including your OS, is the same on both computers, you can use the virtual box and the tramp on top to set up the virtual box and then build your virtualenv using either the requirements or any other way to play It.

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

-1


source







All Articles