简体   繁体   中英

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.

I tried looking for dependencies and install 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 ??

PS: I forgot to mention that I am using anaconda in both machines. 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. from a copy <dir> in the online computer ??

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. I also used --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. You need to put ///. Also remember to put --override-channels flag to prevent connection to default channels.

It sounds like Conda-pack is what you are looking for.

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.

Had this problem the other day, very simple implementation.

First make a .txt file which contains all your python libraries. Now you can just pass this .txt file to whatever machine you want the solution to be installed under and issue the following command :

pip install -r packages.txt

Where "packages" is the name of your .txt file. Hope this helps!

Edit using Conda :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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