How can I install a conda environment when offline?
Asked Answered
V

11

57

I would like to create a conda environment on a machine that has no network connection. What I've done so far is:

On a machine that is connected to the internet:

conda create -n python3 python=3.4 anaconda

Conda archived all of the relevant packages into \Anaconda\pkgs. I put these into a separate folder and moved it to the machine with no network connection. The folder has the path PATHTO\Anaconda_py3\win-64

I tried

conda create -n python=3.4 anaconda --offline --channel PATHTO\Anaconda_py3

This gives the error message

Fetching package metadata:
Error: No packages found in current win-64 channels matching: anaconda

You can search for this package on Binstar with

    binstar search -t conda anaconda

What am I doing wrong? How do I tell conda to create an environment based on the packages in this directory?

Vaginismus answered 30/7, 2015 at 16:54 Comment(1)
What does "conda archived" mean? What argument in the command prompt are you using and with reference to what?Animalist
F
23

You could try cloning root which is the base env.

conda create -n yourenvname --clone root

Fraze answered 15/4, 2016 at 10:29 Comment(4)
This no longer works as of 25 Sep 2017. I disconnected from the network, then ran conda create -n offline --clone root (also tried an existing environment) and got the error: CondaError: CondaHTTPError: HTTP None None for url <https://repo.continuum.io/pkgs/free/win-64/jpeg-9b-vc14_0.tar.bz2> Elapsed: None An HTTP error occurred when trying to retrieve this URL. HTTP errors are often intermittent, and a simple retry will get you on your way. CondaError: CondaHTTPError: HTTP None None for url <https://repo.continuum.io/pkgs/free/win-64/jpeg-9b-vc14_0.tar.bz2> Elapsed: None...Carlin
Steven, did you manage to find a viable alternative solution?Animalist
Steven C. Howell, it doesnt work for you because you added offline flag which is not part of the command, works in 2019 with conda version 4.7.11Padgett
@Padgett if I read his command right, that is actually just the name of the new environment so it must've been a different issueNipping
H
19

Short answer: copy the whole environment from another machine with the same OS.

Why

Dependency. A package depends on other packages. When you install a package online, the package manager conda analyzes the package dependencies and install all the required packages for you.

The dependency is especially heavy in anaconda. Cause anaconda is a meta package depends on another 160+ packages.

Meta packages,are packages do not contain actual softwares and simply depend on other packages to be installed.

It's totally absurd to download all these dependencies one by one and install them on the offline machine.

Detail Solution

  1. Get conda installed on another machine with same OS. Install the packages you need in an isolated virtual environment.

    # create a env named "myvenv", name it whatever you want
    # and install the package into this env
    conda create -n myvenv --copy anaconda
    

    --copy is used to

    Install all packages using copies instead of hard- or soft-linking.

  2. Find where the environments are stored with

    conda info
    

    The 1st value of key "envs directories" is the location. Go there and package the whole sub-folder named "myvenv" (the env name in previous step) into an archive.

  3. Copy the archive to your offline machine. Check "envs directories" from conda info. And extract the environment from the archive into the env directory on the offline machine.

  4. Done.

Headmistress answered 25/9, 2019 at 17:3 Comment(2)
In conda create -n myvenv --copy anaconda, what does 'anaconda' stand for?Hillhouse
For "--copy anaconda". The "anaconda" word is invalid. I changed to "conda create -n myvenv --copy".Baggage
W
4

In addition to copying the pkgs folder, you need to index it, so that conda knows how to find the dependencies. See this ticket for more details and this script for an example of indexing the pkgs folder.

Using --unknown as @asmeurer suggests will only work if the package you're trying to install has no dependencies, otherwise you will get a "Could not find some dependencies" error.

Cloning is another option, but this will give you all root packages, which may not be what you want.

Waggish answered 6/5, 2016 at 5:33 Comment(0)
T
4

A lot of the answers here are not 100% related to the "when offline" part. They talk about the rest of OP's question, not reflected in question title.

If you came here because you need offline env creation on top of an existing Anaconda install you can try:

conda create --offline --name $NAME

You can find the --offline flag documented here

Tortile answered 24/2, 2020 at 14:5 Comment(2)
This works offline. Tested and verified on Windows Server 2019. You can activate the env, then install tarballs with conda install c:\path\to\tar.bz2 -- Note: you will have to install a Python tarball first.Predictory
If you are working on an offline machine, you can make offline mode active by default with conda config --set offline True, so you don't need --offline flag every time. It works fine for me so far.Rensselaerite
D
3

Have you tried without the --offline?

conda create -n anaconda python=3.4 --channel PATHTO\Anaconda_py3

This works for me if I am not connected to the Internet if I do have anaconda already on the machine but in another location. If you are connected to the Internet when you run this command you will probably get an error associated with not finding something on Binstar.

Dendrology answered 2/8, 2015 at 21:1 Comment(2)
What is the file/directory you are referencing to with PATHTO\Anaconda_py3? I tried this on 25 Sep 2017, with ~AppData\Local\Continuum\Anaconda3\python.exe but got the following: "WARNING: The remote server could not find the noarch directory for the requested channel with url: file:///C:/Users/593260/AppData/Local/Continuum/Anaconda3/python It is possible you have given conda an invalid channel. Please double-check your conda configuration using conda config --show."Carlin
Note that the above command would fail outright as written, separate to the --channel flag or lack of internet because it will try to assign the environment to the name python=3.4. A proper environment name should following the -n flag. I tried editing the answer but a reviewer discarded my edit.Carlin
M
3

I'm not sure whether this contradicts the other answers or is the same but I followed the instructions in the conda documentation and set up a channel on the local file system.

Then it's a simple matter of moving new package files to the local directory, running conda index on the channel sub-folder (which should have a name like linux-64).

I also set the Anaconda config setting offline to True as described here but not sure if that was essential.

Hope that helps.

Motherhood answered 24/5, 2019 at 0:13 Comment(0)
B
1

The pkgs directory is not a channel. The flag you are looking for is --unknown, which causes conda to include files in the pkgs directory even if they aren't found in one of the channels.

Bustee answered 31/7, 2015 at 19:35 Comment(2)
to be more explicit: conda create --unknown --offline -n python3 python=3Ourself
As of 25 Sep 2017, this seems to work, then fails with the following: "CondaError: RuntimeError('EnforceUnusedAdapter called with url repo.continuum.io/pkgs/free/win-64/…\nThis command is using a remote connection in offline mode.\n',)..." (repeated 3x)Carlin
B
1

Here's what worked for me in Linux -

(a) Create a blank environment - Just create an empty directory under $CONDA_HOME/envs. Verify with - conda info --envs.

(b) Activate the new env - source activate

(c) Download the appropriate package (*.bz2) from https://anaconda.org/anaconda/repo on a machine with internet connection and move it to the isolated host.

(d) Install using local package - conda install . For example - conda install python-3.6.4-hc3d631a_1.tar.bz2, where python-3.6.4-hc3d631a_1.tar.bz2 exists in the current dir.

That's it. You can verify by the usual means (python -V, conda list -n ). All related packages can be installed in the same manner.

Bacteria answered 13/3, 2018 at 14:52 Comment(0)
B
0

I found the simplest method to be as follows:

  1. Run 'conda create --name name package' with no special switches
  2. Copy the URL of the first package it tried (unsuccessfully) to download
  3. Use the URL on a connected machine to fetch the tar.bz2
  4. Copy the tar.bz2 to the offline machine's /home/user/anaconda3/pkgs
  5. Deploy the tar.bz2 in place
  6. Delete the now unneeded tar.bz2
  7. Repeat until the 'conda create' command succeeds
Backhander answered 27/4, 2016 at 16:24 Comment(2)
What do you mean by "deploy the tar.biz. in place" here? I'm facing slow conda download issue, that conda install would timeout. I'm in China behind the evil censorship of Internet traffic. Although the censorship applies to all download, but I found download through conda is much slower than the other download, say ftp, or http download.Antefix
I mean open a Nautilus window on /home/user/anaconda3/pkgs, right-click the tar.bz2, and select "Extract here".Backhander
C
0

Here's a solution that may help. It's not very pretty but it gets the job done. So i suppose you have a machine where you have a conda environment in which you've installed all the packages you need. I will refer to this as ENV1 You will have to go to this environment directory and locate it. It is usually found in \Anaconda3\envs. I suggest compressing the folder but you could just use it as is. Copy the desired environment folder into your offline machine's directory for anaconda environments. This first step should get your new environment to respond to commands like conda activate.

You will notice though that software like spyder and jupyter don't work anymore (probably because of path differences). My solution to this was to clone the base environment in the offline machine into a new environment that i will refer to as ENV2. What you need to do then is copy the contents of ENV2 into those of ENV1 and replace files.

This should overwrite the files related to spyder, jupyter.. and keep your imported packages intact.

Copula answered 4/9, 2020 at 11:26 Comment(0)
E
0

Here is my solution. On the machine with network connection, I created the environment: conda create --name py37 python=3.7

There will be a folder generated at: C:\ProgramData\Anaconda2\envs\py37 Zipped this folder and copied to machine without network connection. Unzipped it to the same folder structure.

I can activate the py37 environment and execute my Python script at the destination machine. It was a quick verification and I have not thoroughly run my script.

Emasculate answered 23/4 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.