[英]How to use python virtual environment in another computer
I have created an virtual environment by using virtualenv pyenv
in my linux system. 我在linux系统中使用
virtualenv pyenv
创建了一个虚拟环境。 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?
或者我需要做些什么来设置它?
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. 创建一个脚本,从
requirements.txt
文件中安装所有必需的依赖项并使用它。
Use pip freeze > requirements.txt
to get the list of all python packages installed. 使用
pip freeze > requirements.txt
获取所有安装的python包的列表。 Then install the dependencies in another virtual environment on another computer using pip install -r requirements.txt
. 然后使用
pip install -r requirements.txt
在另一台计算机上的另一个虚拟环境中安装依赖项。
If you want the exact environment, including system packages, on another computer, use Docker. 如果您想在另一台计算机上使用包括系统软件包在内的确切环境,请使用Docker。
You can use copy and paste it in another directory or computer, but its not a best way to use virtualenv. 您可以将其复制并粘贴到另一个目录或计算机中,但这不是使用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
你像requirement.txt任何txt文件notedown您的要求更好,运行使用
pip freeze > requirement.txt
写在所有要求requirement.txt
script using pip
. 脚本使用
pip
。
pip install -r requirement.txt
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/ https://docs.vagrantup.com/v2/getting-started/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.