问题描述
我在我的 linux 系统中使用 virtualenv pyenv
创建了一个虚拟环境.现在我想在另一台计算机上使用虚拟环境.我可以直接复制虚拟环境并在另一台计算机上使用吗?或者我需要做些什么来设置它?
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?
推荐答案
你不应该.另一台计算机可能安装了不同的操作系统、其他软件包或软件包版本,因此无法复制文件.
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.
制作一个脚本,从 requirements.txt
文件安装所有必需的依赖项并使用它.
Make a script which installs all necessary dependencies from a requirements.txt
file and use it.
使用 pip freeze >requirements.txt
获取所有安装的python 包的列表.然后使用 pip install -r requirements.txt
在另一台计算机上的另一个虚拟环境中安装依赖项.
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
.
如果您想在另一台计算机上获得确切的环境(包括系统包),请使用 Docker.
If you want the exact environment, including system packages, on another computer, use Docker.
这篇关于如何在另一台电脑上使用python虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!