Python package installation is quite simple using python package manager pip. But how do you install it if you don't have an internet connection to the machine? LOL You know why I was laughing that's why you are reading this post. Servers in any organisations that are in the restricted area are never exposed to the internet. The ideal way of installing packages is like binaries and deb packages. Copy them in a thumb drive and install. You are good to go. We are going to see such practice here. Pip already has a solution for this scenario i.e., `--no-index` and `--find-links`. Let's see how to do it. The first thing to do is, download the python package files(.whl) file from https://pypi.org/ onto a pen drive and copy them to the machine you want to install. Installation: I will install Flask for demo purposes. I have my .whl package ready and copied to local machines under /tmp. I use this below command to install
pip3 install --no-index --find-links=/tmp flask
manny@manny:/tmp$ pip3 install --no-index --find-links=/tmp/ flask
Looking in links: /tmp/
Processing ./Flask-2.0.1-py3-none-any.whl
Requirement already satisfied: Werkzeug>=2.0 in /usr/local/lib/python3.8/dist-packages (from flask) (2.0.1)
Requirement already satisfied: Jinja2>=3.0 in /usr/local/lib/python3.8/dist-packages (from flask) (3.0.1)
Requirement already satisfied: itsdangerous>=2.0 in /usr/local/lib/python3.8/dist-packages (from flask) (2.0.1)
Requirement already satisfied: click>=7.1.2 in /usr/local/lib/python3.8/dist-packages (from flask) (8.0.1)
Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.8/dist-packages (from Jinja2>=3.0->flask) (2.0.1)
Installing collected packages: flask
Successfully installed flask-2.0.1
try importing and you successfully installed your python package. Few things to note: The package installed using this process is visible in the pip list, so you can't uninstall using pip install which is fair enough.
pip3 list|grep -i flask
So fix for that is, use the below command to uninstall which worked for me.
manny@manny:/tmp$ python3 -m pip uninstall flask
Found existing installation: Flask 2.0.1
Uninstalling Flask-2.0.1:
  Would remove:
    /home/manny/.local/bin/flask
    /home/manny/.local/lib/python3.8/site-packages/Flask-2.0.1.dist-info/*
    /home/manny/.local/lib/python3.8/site-packages/flask/*
Proceed (y/n)? y
  Successfully uninstalled Flask-2.0.1