简体   繁体   English

无法将 Python venv 克隆到另一台 PC

[英]Unable to clone Python venv to another PC

I want to clone my existing venv to another PC but simply copy paste is not working.我想将我现有的 venv 克隆到另一台 PC,但只是复制粘贴不起作用。 When I copy the venv and paste to the second machine and run当我复制 venv 并粘贴到第二台机器并运行时

pip list点子列表

It only list pip and setup_tools as the installed dependencies.它只列出 pip 和 setup_tools 作为已安装的依赖项。 I tried another way to clone the packages.我尝试了另一种方法来克隆包。 I created a new venv in the second machine and copied all the file of first venv to that new venv with skipping the existing files with the same name in new venv.我在第二台机器上创建了一个新的 venv,并将第一个 venv 的所有文件复制到那个新的 venv,并跳过新 venv 中同名的现有文件。 Now, when I run现在,当我跑

pip list点子列表

It shows all the dependencies but, when I try to launch the jupyter notebook as它显示了所有依赖项,但是,当我尝试将 jupyter notebook 启动为

jupyter notebook jupyter 笔记本

It gives the following error.它给出了以下错误。

Fatal error in launcher: Unable to create process using '"f:\\path\\to\\first_venv\\on_first_machine\\scripts\\python.exe" "C:\\path\\to\\new_venv\\on_the_second_machine\\Scripts\\jupyter.exe" notebook': The system cannot find the file specified.启动器中的致命错误:无法使用“f:\\path\\to\\first_venv\\on_first_machine\\scripts\\python.exe”“C:\\path\\to\\new_venv\\on_the_second_machine\\Scripts\\jupyter.exe”笔记本'创建进程:该系统找不到指定的文件。

I don't know to make things working.我不知道让事情发挥作用。 Please help!请帮忙!

Edit编辑

The problem is I don't have internet connection on the second machine.问题是我在第二台机器上没有互联网连接。 Actually it's a remote machine with some security protocols applied and having no internet connection is part of security !实际上它是一台应用了一些安全协议的远程机器,没有互联网连接是安全的一部分! My bad :'(我的错 :'(

You can't copy-paste venvs from one machine to another since scripts in them may refer to system locations.您不能将 venvs 从一台机器复制粘贴到另一台机器,因为其中的脚本可能会引用系统位置。 (The same stands for attempting to move venvs within a machine.) (同样代表试图在机器内移动 venv。)

Instead, recreate the environment on the new machine:相反,在新机器上重新创建环境:

  1. On the old machine, run pip freeze -l > packages.txt in the virtualenv.在旧机器上,在 virtualenv 中运行pip freeze -l > packages.txt
  2. Move packages.txt over to the new machine.packages.txt移到新机器上。
  3. Create a new virtualenv on the new machine and enter it.在新机器上新建一个virtualenv并输入。
  4. Install the packages from the txt file: pip install -r packages.txt .从 txt 文件pip install -r packages.txtpip install -r packages.txt

EDIT: If you don't have internet access on the second machine, you can continue from step 2 with:编辑:如果您在第二台机器上没有互联网访问权限,您可以从第 2 步继续:

  1. Run pip wheel -w wheels -r packages.txt in the venv on the first machine.在第一台机器上的 venv 中运行pip wheel -w wheels -r packages.txt This will download and build *.whl packages for all the packages you require.这将为您需要的所有包下载并构建*.whl包。 Note that this assumes both machines are similar in OS and architecture!请注意,这假设两台机器在操作系统和架构上相似!
  2. Copy the wheel files over to the new machine.将车轮文件复制到新机器上。
  3. Create a new virtualenv on the new machine and enter it.在新机器上新建一个virtualenv并输入。
  4. Install the packages from wheels in the new virtualenv: pip install *.whl .在新的 virtualenv 中从轮子安装包: pip install *.whl

You should never copy a virtual environment between machines.您永远不应该在机器之间复制虚拟环境。 The correct way is to export the dependencies installed in the environment using pip freeze and create a new virtual environment on the other machine.正确的方法是使用pip freeze导出环境中安装的依赖,并在另一台机器上创建一个新的虚拟环境。

# One the first machine
pip freeze > requirements.txt
# Copy requirements.txt to the other machine, or store in a source repository
# Then install the requirements in the new virtual environment
pip install -r requirements.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM