6

first of all I have managed to install Ansible on a server which has no internet access. But I wonder if my approach is correct.

At first I downloaded the necessary dependencies via pip3.

pip3 download ansible -d .

This resulted in the following files downloaded:

ansible-2.9.4.tar.gz                          
cryptography-2.8-cp34-abi3-manylinux1_x86_64.whl  
MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl  
PyYAML-5.3.tar.gz
cffi-1.13.2-cp36-cp36m-manylinux1_x86_64.whl  
Jinja2-2.11.1-py2.py3-none-any.whl                
pycparser-2.19.tar.gz                              
six-1.14.0-py2.py3-none-any.whl

Now that I have made these files available on my remote computer, I tried to use

pip3 install ansible-2.9.4.tar.gz

to install ansible.

This resulted in the following error:

Processing ./ansible-2.9.4.tar.gz
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 
'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 
0x7f00726f9ef0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /simple/jinja2/

So I tried to install Jinja2 manually:

pip3 install jinja2-2.11.1-py2.py3-none-any.whl

But this did not work either:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection
 broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 
0x7fd303a23940>: Failed to establish a new connection: [Errno -2] Name or service not known',)': 
/simple/markupsafe/

After Markupsafe was installed, Jinja2 could be installed as well. In the end with pip3 install ansible-2.9.4.tar.gz I successfully installed ansible.

Now my question is. Is there a way to tell pip to use the downloaded files to install the dependencies or is there an easier approach to install a specific python package with all its dependencies offline?

Thanks for your help and best regards. yabberth

yabberth
  • 165
  • 1
  • 2
  • 6

2 Answers2

6

Is there a way to tell pip to use the downloaded files to install the dependencies or is there an easier approach to install a specific python package with all its dependencies offline?

I believe what you're looking for are the --no-index and --find-links options to pip install. Per the official pip install option documentation:

--no-index

Ignore package index (only looking at --find-links URLs instead).

-f, --find-links

If a url or path to an html file, then parse for links to archives. If a local path or file:// url that’s a directory, then look for archives in the directory listing.

With these options you can do ex. local installation:

pip3 install --no-index --find-links /some/path <package name>

or remote installation (e.g. via HTTP):

pip3 install --no-index --find-links http:\\remotes\server <package name>

In your case, you should be able to simply use ansible for the package name ex.:

pip3 install --no-index --find-links /some/path ansible

pip3 install --no-index --find-links http:\remotes\server ansible

Though the full file name can be used if you wish:

pip3 install --no-index --find-links /some/path ansible-2.9.4.tar.gz

pip3 install --no-index --find-links http:\remotes\server ansible-2.9.4.tar.gz

Assuming all the required dependencies reside in the same location (as listed in your original question), they should be installed as normal (i.e. without having to install each dependency in order manually).


Requirements

Another option might be to make a requirements file with the proper dependency installation order e.g.:

ex. requirements.txt

/path/to/MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl 
/path/to/Jinja2-2.11.1-py2.py3-none-any.whl 
/path/to/ansible-2.9.4.tar.gz
# ...                          

Then use e.g. pip3 install -r requirements.txt to install the listed packages. You could use e.g. HTTP links again as well:

ex. requirements.txt

http:\\remotes\server\MarkupSafe-1.1.1-cp36-cp36m-manylinux1_x86_64.whl 
http:\\remotes\server\Jinja2-2.11.1-py2.py3-none-any.whl 
http:\\remotes\server\ansible-2.9.4.tar.gz
# ... 

The clear drawback here is that, assuming one package is dependent on another, you already need to know the order in which certain packages need to be installed.


Other URL Options

You may also want to look at the version control system (VCS) section of pip install documentation, which offers examples of combining pip install with VCS links (i.e. Git, Mercurial, Subversion and Bazaar).


References

pip install

pip install (options)

Anaksunaman
  • 18,227
1

Since you needs is not to have a full mirror, I would suggest to use python-pypi-mirror :

1- Install python-pypi-mirror using pip on a server that have internet connection.

2- Install http.server python module on this server.

3- Create a directory that will server your pip packages.

4- Download the needed packages using python-pypi-mirror to the directory recently created and exposed as an http server (it will contain all its dependencies).

5- Install the needed package remotely.

 pip3 install --trusted-host <http_server> -i http://<http_server>:<http.server_default_port>/simple <package_name>

You will find all the needed instructions here

Reda Salih
  • 1,036