Python

Python

Python

 View Only

Installing PyPI packages without an internet connection

By Seo Hyun Jeong posted Tue February 28, 2023 11:19 AM

  

pip is the package manager for Python allowing users to install packages from PyPI.

Users can install packages with a pip install command followed by the name of the desired package:

pip install <package name>

When the above command gets executed, pip looks for the suitable distribution from PyPI, and installs the required dependencies in your Python environment to ensure the package will work without any further steps. This installation method requires an internet connection otherwise the installation fails. A different method is required to download the package on a machine without an internet connection.

 

You can follow the instructions to install the package without an internet connection.

1. Download the dependencies:

Look at pyproject.toml or setup.py from the target packages’ source and download the dependencies archive file. Please note that the dependency package might also have dependencies to build and install. You should also confirm if you have any missing packages.

2. Download the target and dependency source distributions:

Go to github and download the archive file. You can download the archive file from Releases/Tags or clone the repository as <package name>-main.zip format.

3. Transfer the files to the machine.

4. Build the dependency.

Run the following command to build the dependency:

pip install <dependency archive file>

 

5. Build the target package.

Run the following command to build the target package:

pip install <target archive file>

Note: Some packages (e.g. pandas) might still look for dependencies that are already installed. By adding the --no-build-isolation option, pip will not try installing the dependencies.

The following example shows installing Flask==2.2.2  packages using the above instructions.

1. Download the dependencies.

  • Check required dependencies from Flask/setup.py specified under install_requires:
install_requires=[ "Werkzeug >= 2.2.2", "Jinja2 >= 3.0", "itsdangerous >= 2.0", "click >= 8.0", "importlib-metadata >= 3.6.0; python_version < '3.10'" ]

 

  • Check the dependency’s dependency package.

 Jinja2 and Werkzeug are dependent on the MarkupSafe package.

install_requires=["MarkupSafe>=2.1.1"]

2. Download the target and dependency source distributions.

In this example, we have downloaded the following tar files with the latest version from Tags:

flask-2.2.2.tar.gz
click-8.1.3.tar.gz
itsdangerous-2.1.2.tar.gz
markupsafe-2.1.1.tar.gz    
jinja-3.1.2.tar.gz                 
werkzeug-2.2.2.tar.gz

3. Transfer the files to the machine.

4. Build the dependency.

We recommend using an isolated environment such as the virtual environment module, venv.
Run the pip install commands below to set up the environment for Flask:

python3 -m venv venv
. ./venv/bin/activate
pip install click-8.1.3.tar.gz
pip install itsdangerous-2.1.2.tar.gz
pip install markupsafe-2.1.1.tar.gz   
pip install jinja-3.1.2.tar.gz                 
pip install werkzeug-2.2.2.tar.gz

5. Build Flask.

Finally, all requirements are installed, and it is ready to install our target package Flask. With the same command pip install flask-2.2.2.tar.gz, the Flask package will be successfully installed.

You can double-check if Flask is in your Python environment and ready to be used, by running the pip list command. 

>>> pip list

Package      Version

------------ -------

click        8.1.3

Flask        2.2.2

itsdangerous 2.1.2

Jinja2       3.1.2

MarkupSafe   2.1.1

pip          22.2.2

setuptools   63.2.0

Werkzeug     2.2.2

 

You can see the list of packages you installed and Flask==2.2.2.

Note: If you have another machine with an internet connection and the same platform, you can skip steps 1 to 3 and easily acquire downloadable links for the target and dependency packages by running the following command:

pip install -v -v -v Flask| grep “Added” &>  Flask.log
0 comments
40 views

Permalink