Installing Python Packages Without Internet and Using Source Code as .Tar.Gz and .Whl

installing python packages without internet and using source code as .tar.gz and .whl

This is how I handle this case:

On the machine where I have access to Internet:

mkdir keystone-deps
pip download python-keystoneclient -d "/home/aviuser/keystone-deps"
tar cvfz keystone-deps.tgz keystone-deps

Then move the tar file to the destination machine that does not have Internet access and perform the following:

tar xvfz keystone-deps.tgz
cd keystone-deps
pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index

You may need to add --no-deps to the command as follows:

pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index --no-deps

How to install Python packages from the tar.gz file without using pip install

Thanks to the answers below combined I've got it working.

  • First needed to unpack the tar.gz file into a folder.
  • Then before running python setup.py install had to point cmd towards the correct folder. I did this by pushd C:\Users\absolutefilepathtotarunpackedfolder
  • Then run python setup.py install

Thanks Tales Padua & Hugo Honorem

How to install packages offline?

If the package is on PYPI, download it and its dependencies to some local directory.
E.g.


$ mkdir /pypi && cd /pypi
$ ls -la
-rw-r--r-- 1 pavel staff 237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz
-rw-r--r-- 1 pavel staff 389741 Feb 22 17:10 Jinja2-2.6.tar.gz
-rw-r--r-- 1 pavel staff 70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz
-rw-r--r-- 1 pavel staff 2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz
-rw-r--r-- 1 pavel staff 1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz
-rw-r--r-- 1 pavel staff 488207 Apr 10 18:26 boto-2.3.0.tar.gz
-rw-r--r-- 1 pavel staff 490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz

Some packages may have to be archived into similar looking tarballs by hand. I do it a lot when I want a more recent (less stable) version of something. Some packages aren't on PYPI, so same applies to them.

Suppose you have a properly formed Python application in ~/src/myapp. ~/src/myapp/setup.py will have install_requires list that mentions one or more things that you have in your /pypi directory. Like so:

  install_requires=[
'boto',
'Flask',
'Werkzeug',
# and so on

If you want to be able to run your app with all the necessary dependencies while still hacking on it, you'll do something like this:


$ cd ~/src/myapp
$ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi

This way your app will be executed straight from your source directory. You can hack on things, and then rerun the app without rebuilding anything.

If you want to install your app and its dependencies into the current python environment, you'll do something like this:


$ cd ~/src/myapp
$ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .

In both cases, the build will fail if one or more dependencies aren't present in /pypi directory. It won't attempt to promiscuously install missing things from Internet.

I highly recommend to invoke setup.py develop ... and easy_install ... within an active virtual environment to avoid contaminating your global Python environment. It is (virtualenv that is) pretty much the way to go. Never install anything into global Python environment.

If the machine that you've built your app has same architecture as the machine on which you want to deploy it, you can simply tarball the entire virtual environment directory into which you easy_install-ed everything. Just before tarballing though, you must make the virtual environment directory relocatable (see --relocatable option). NOTE: the destination machine needs to have the same version of Python installed, and also any C-based dependencies your app may have must be preinstalled there too (e.g. say if you depend on PIL, then libpng, libjpeg, etc must be preinstalled).

installing python packages on production system(windows) without internet access and no internal pypi server

Yes there is a way my friend, you need to download first the packages and dependency of them to a folder and use pip package manager with a requirements file like this:
pip install --no-index --find-links=[file://] -r requirements.txt

and if you want to download all the packages first in one hit use this:

pip install --download -r requirements.txt

for more read here:
https://pip.pypa.io/en/stable/user_guide/#installing-from-local-packages
@maverick

Python: install package offline with dependencies with Pip?

This question seems to have already been answered here

However, here is a quick summary:

  1. Upload your package to the Python Package Index (PyPI)
  2. Download the package using pip on a machine with internet connection, then turn the package into a .tar file

    mkdir ~/some_directory
    pip download some_package -d "~/some_directory"
    tar -cvfz some_package.tar some_directory
  3. Once in .tar format, you can install the package without internet connection on a machine with Python.

    tar -xzvf some_package.tar
    cd some_directory
    pip install some_package-x.x.x-py2.py3-x-x.whl -f ./ --no-index

force pip to build from source (tar.gz), not the wheel (.whl)

If you have a .tar.gz file you can simply install it with pip:

pip install foobar.tar.gz

Also, see pip option --no-binary in the documentation. Use :all: to force compilation of all packages, or specify a list of packages to compile.

pip install --no-binary :all: foobar
pip install --no-binary numpy,scipy foobar

To install h5py from sources do

pip install --no-binary h5py h5py

This will still use wheels for all other packages that might be installed as a dependency.

How to forward the library downloaded with pip?

I would utilize wheel in this case, which can make packages that you can bring to your offline machine. For example with numpy

pip wheel numpy
Collecting numpy
Downloading numpy-1.20.2-cp37-cp37m-win_amd64.whl (13.6 MB)
Saved c:\numpy-1.20.2-cp37-cp37m-win_amd64.whl

Then on your other machine copy these wheels and use pip

pip install numpy-1.20.2-cp37-cp37m-win_amd64.whl

You can do a similar thing with requirements.txt to gather a number of wheels at once.

Install python package using conda without internet

PyPI distributions usually come with a setup.py. Here are the steps to download offline.

  1. Find the package you want to download on PyPI
  2. Download the latest distribution to a local directory, should be a tar.gz (tarball) file.
  3. Open Anaconda Prompt/Terminal
  4. cd to the tar.gz parent folder
  5. pip install (filename)

Sometimes a package will have dependencies that need to be installed online. In this case you will need to do the same with the dependency before you can successfuly run the setup.py



Related Topics



Leave a reply



Submit