python venv 复制,无法将Python venv克隆到另一台PC

I want to clone my existing venv to another PC but simply copy paste is not working. When I copy the venv and paste to the second machine and run

pip list

It only list pip and setup_tools as the installed dependencies.

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. Now, when I run

pip list

It shows all the dependencies but, when I try to launch the jupyter notebook as

jupyter notebook

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.

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. (The same stands for attempting to move venvs within a machine.)

Instead, recreate the environment on the new machine:

On the old machine, run pip freeze -l > packages.txt in the virtualenv.

Move packages.txt over to the new machine.

Create a new virtualenv on the new machine and enter it.

Install the packages from the txt file: pip install -r packages.txt.

EDIT: If you don't have internet access on the second machine, you can continue from step 2 with:

Run pip wheel -w wheels -r packages.txt in the venv on the first machine. This will download and build *.whl packages for all the packages you require. Note that this assumes both machines are similar in OS and architecture!

Copy the wheel files over to the new machine.

Create a new virtualenv on the new machine and enter it.

Install the packages from wheels in the new virtualenv: pip install *.whl.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值