简体   繁体   English

如何在另一台计算机上使用python虚拟环境

[英]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.

相关问题 如何将Python/Anaconda虚拟环境从一台电脑复制到另一台电脑? - How to copy Python/Anaconda virtual environment from one computer to another? 如何在虚拟环境中使用 Python 解释器 - How to use a Python interpreter in a virtual environment 在虚拟环境中使用Python 2.7.10 - Use Python 2.7.10 in Virtual Environment 如何从终端的本地计算机文件夹在虚拟环境 Python (Windows 7) 中安装 Django? - How to install Django in a virtual environment Python (Windows 7) from a local computer folder from a terminal? 如何将Python虚拟环境转移给另一个用户? - How do I transfer a Python virtual environment to another user? 如何将完整的 python 虚拟环境从一台机器移动到另一台机器? - How to move full python virtual environment from one machine to another? 如何在 Linux 上的 Python 虚拟环境中安装和使用 Jupyter 实验室? - How to install and use Jupyter lab in a Python virtual environment on Linux? 如何让 Py4Delphi 使用 Python 虚拟环境 - How to get Py4Delphi to use a Python Virtual Environment 如何在Python虚拟环境之外使用Opencv? - How can I use Opencv outside the python virtual environment? 如何在我的虚拟环境中使用Python 3(3.5)作为默认解释器? - How to use Python 3 (3.5) as the default interpreter in my virtual environment?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM