Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
527 views
in Technique[技术] by (71.8m points)

simply use python anaconda without internet connection

I would like to deploy a python environment on production servers that have no access to the internet.

I discovered Python Anaconda distribution and installed it to give it a try. The installation directory is 1.6GB, and I can see in pkgs directory that a lot of libraries are there.

However, when I try to install an environment, conda does not lookup in the local directories...

conda create --offline --use-local --dry-run  --name pandas_etl python
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata:
Solving package specifications:
Error:  Package missing in current linux-64 channels:
  - python

So, what is the point to bundle all those libraries if conda needs to pick them up on online repositories? Maybe am I missing something?

I am looking for a kind of "lots of batteries included python" for convenient deployment.

Note: I use a Linux system and installed the regular anaconda, not the miniconda

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Well, after playing around with Pandas while reading Fabio Nelli book 'Python Data Analytic', I realize how much Pandas is an awesome library. SO, i've been working with Anaconda to make it work in my environment.

1- Download the Anaconda installer and install it (I guess miniconda will be enough)

2- Make a local channel by mirroring the (part of) anaconda repository

Do not try to download individual packages on your workstation to push them to your offline server. Indeed, dependencies will not be satisfied. Packages need to be contained in a channel and indexed in metadata files (repodata.json and repodata.json.bz2) to be properly 'glued' together.

I used wget to mirror a part of the anaconda repository : https://repo.continuum.io/pkgs/ I used something like this to filter out packages in order not to download the whole repo :

wget -r --no-parent -R --regex-type pcre --reject-regex '(.*py2[67].*)|(.*py[34].*)' https://repo.continuum.io/pkgs/free/linux-64/

Beware, not to use something like "only py35" packages. Indeed, many packages in the repo don't have version string in their name; and you'll miss them as dependency.

Well, i guess you can filter more accurately. I fetched about 6GB of packages!

!!!! Do NOT build a custom channel from the part of the repository you just downloaded !!!! (anaconda custom channels) I tried this at first and i had this exception : "RecursionError: maximum recursion depth exceeded while calling a Python object". This is a known pb : https://github.com/conda/conda/issues/2371 ==> the maintainers discuss this : the metadatas maintained in repodata.json and repodata.json.bz2 do not reflect metadatas in individual pkg. They choose to only edit the repo metadata to fix issues instead of each package metadatas. So, if you rebuild the channel metadatas from packages, you miss.

==> So : do not rebuild channel metadata, just keep the repository metadata (repodata.json and repodata.json.bz2 contained in the official anaconda repository). Even if the whole repo is not in your new channel, it'll work (at least, if you did not filter to much while mirroring ;-) )

3- test and use your new channel

conda search -c file://Path_to_your_channel/repo.continuum.io/pkgs/free/ --override-channels

NOTE : Do not include your platform architecture in the path. Exemple : your channel tree is probably : /Path_to_your_channel/repo.continuum.io/pkgs/free/linux-64 Just omit your arch (linux-64 in my case). Conda will find out.

Update :

conda update  -c file://resto/anaconda_repo/repo.continuum.io/pkgs/free/ --override-channels --all

And so on... I guess, you can use the conda conf file of your system user to force using this local channel.

Hope it helps.

Guillaume


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...