无法将 Python venv 克隆到另一台 PC
Unable to clone Python venv to another PC
我想将我现有的 venv 克隆到另一台 PC,但简单地复制粘贴是行不通的。当我复制 venv 并粘贴到第二台机器和 运行
pip list
它只列出 pip 和 setup_tools 作为已安装的依赖项。
我尝试了另一种方法来克隆包。
我在第二台机器上创建了一个新的 venv 并将第一个 venv 的所有文件复制到那个新的 venv 并跳过新 venv 中具有相同名称的现有文件。现在,当我 运行
pip list
它显示了所有依赖项,但是,当我尝试启动 jupyter notebook 时
jupyter notebook
它给出了以下错误。
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.
我不知道如何让事情正常进行。请帮忙!
编辑
问题是我在第二台机器上没有互联网连接。实际上它是一台应用了一些安全协议的远程机器,没有互联网连接是安全的一部分!我的错:'(
您不能 copy-paste 从一台机器到另一台机器,因为其中的脚本可能引用系统位置。 (同样代表试图在机器内移动 venvs。)
相反,在新机器上重新创建环境:
- 在旧机器上,运行
pip freeze -l > packages.txt
在 virtualenv.
- 移动
packages.txt
到新机器。
- 在新机器上新建virtualenv并进入
- 从 txt 文件安装包:
pip install -r packages.txt
。
编辑: 如果您无法在第二台机器上访问互联网,您可以从第 2 步继续:
- 运行
pip wheel -w wheels -r packages.txt
在第一台机器上的 venv 中。这将为您需要的所有包下载并构建 *.whl
包。请注意,这假设两台机器在 OS 和体系结构方面相似!
- 将 wheel 文件复制到新机器上。
- 在新机器上新建virtualenv并进入
- 在新的 virtualenv 中安装来自 wheels 的包:
pip install *.whl
.
永远不要在机器之间复制虚拟环境。正确的做法是使用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
我想将我现有的 venv 克隆到另一台 PC,但简单地复制粘贴是行不通的。当我复制 venv 并粘贴到第二台机器和 运行
pip list
它只列出 pip 和 setup_tools 作为已安装的依赖项。 我尝试了另一种方法来克隆包。 我在第二台机器上创建了一个新的 venv 并将第一个 venv 的所有文件复制到那个新的 venv 并跳过新 venv 中具有相同名称的现有文件。现在,当我 运行
pip list
它显示了所有依赖项,但是,当我尝试启动 jupyter notebook 时
jupyter notebook
它给出了以下错误。
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.
我不知道如何让事情正常进行。请帮忙!
编辑
问题是我在第二台机器上没有互联网连接。实际上它是一台应用了一些安全协议的远程机器,没有互联网连接是安全的一部分!我的错:'(
您不能 copy-paste 从一台机器到另一台机器,因为其中的脚本可能引用系统位置。 (同样代表试图在机器内移动 venvs。)
相反,在新机器上重新创建环境:
- 在旧机器上,运行
pip freeze -l > packages.txt
在 virtualenv. - 移动
packages.txt
到新机器。 - 在新机器上新建virtualenv并进入
- 从 txt 文件安装包:
pip install -r packages.txt
。
编辑: 如果您无法在第二台机器上访问互联网,您可以从第 2 步继续:
- 运行
pip wheel -w wheels -r packages.txt
在第一台机器上的 venv 中。这将为您需要的所有包下载并构建*.whl
包。请注意,这假设两台机器在 OS 和体系结构方面相似! - 将 wheel 文件复制到新机器上。
- 在新机器上新建virtualenv并进入
- 在新的 virtualenv 中安装来自 wheels 的包:
pip install *.whl
.
永远不要在机器之间复制虚拟环境。正确的做法是使用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