简体   繁体   English

如何在不同机器之间复制Python模块

[英]How to copy modules of Python between different machines

I have two machine that one does not have internet access.我有两台机器,其中一台不能上网。 I want to install modules with anaconda and copy them to offline computer from the other computer that has internet access.我想用 anaconda 安装模块并将它们从可以访问互联网的另一台计算机复制到离线计算机。

I tried looking for dependencies and install tar.我尝试寻找依赖项并安装 tar。 files manually one by one and sent them to the offline machine but it is very time-consuming.手动一个一个的文件发送到离线机器,但非常耗时。

What is the easiest way?什么是最简单的方法? Does miniconda helpful ?? miniconda 有用吗??

PS: I forgot to mention that I am using anaconda in both machines. PS:我忘了提到我在两台机器上都使用了anaconda。 So I guess I need to create an env., install packages then export it for offline computer.所以我想我需要创建一个环境,安装包然后将它导出到离线计算机。 Are there any other way to install number of packages to offline comp.有没有其他方法可以将多个软件包安装到离线 comp. from a copy <dir> in the online computer ??从在线计算机中的副本<dir> ??

Edit: I tried conda install --file C:\\Users\\myName\\Desktop\\OfflineInstall\\packagelist.txt --channel file://C:\\Users\\myName\\Desktop\\OfflineInstall\\pkgs2 but offline machine still tried to connect internet.编辑:我试过conda install --file C:\\Users\\myName\\Desktop\\OfflineInstall\\packagelist.txt --channel file://C:\\Users\\myName\\Desktop\\OfflineInstall\\pkgs2但离线机器仍然尝试连接互联网. I also used --no-deps我也用过--no-deps

Edit2: For those who stuck on the same problem, I solved using conda install --file C:\\Users\\myName\\Desktop\\OfflineInstall\\packagelist.txt --channel file:///C:\\Users\\myName\\Desktop\\OfflineInstall\\pkgs2 --override-channels The tricky way is the file:/// prefix. Edit2:对于那些conda install --file C:\\Users\\myName\\Desktop\\OfflineInstall\\packagelist.txt --channel file:///C:\\Users\\myName\\Desktop\\OfflineInstall\\pkgs2 --override-channels同样问题的人,我使用conda install --file C:\\Users\\myName\\Desktop\\OfflineInstall\\packagelist.txt --channel file:///C:\\Users\\myName\\Desktop\\OfflineInstall\\pkgs2 --override-channels棘手的方法是file:///前缀。 You need to put ///.你需要把///。 Also remember to put --override-channels flag to prevent connection to default channels.还要记住放置--override-channels标志以防止连接到默认通道。

It sounds like Conda-pack is what you are looking for.听起来Conda-pack正是您要找的。

Installing:安装:

$ conda install conda-pack

On the source machine:在源机器上:

# Pack environment my_env into my_env.tar.gz
$ conda pack -n my_env

On the target machine:在目标机器上:

# Unpack environment into directory `my_env`
$ mkdir -p my_env
$ tar -xzf my_env.tar.gz -C my_env

# Use python without activating or fixing the prefixes. Most python
# libraries will work fine, but things that require prefix cleanups
# will fail.
$ ./my_env/bin/python

# Activate the environment. This adds `my_env/bin` to your path
$ source my_env/bin/activate

# Run python from in the environment
(my_env) $ python

# Cleanup prefixes from in the active environment.
# Note that this command can also be run without activating the environment
# as long as some version of python is already installed on the machine.
(my_env) $ conda-unpack

The caveat being that conda-pack will take the whole environment.需要注意的是 conda-pack 将占用整个环境。

Had this problem the other day, very simple implementation.前几天遇到了这个问题,非常简单的实现。

First make a .txt file which contains all your python libraries.首先创建一个包含所有 python 库的 .txt 文件。 Now you can just pass this .txt file to whatever machine you want the solution to be installed under and issue the following command :现在,您只需将此 .txt 文件传递​​到您想要安装解决方案的任何机器,然后发出以下命令:

pip install -r packages.txt

Where "packages" is the name of your .txt file.其中“packages”是您的 .txt 文件的名称。 Hope this helps!希望这可以帮助!

Edit using Conda :使用 Conda 编辑:

while read requirement; do conda install --yes $requirement; done < requirements.txt

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

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