How To Install Python Modules Without Internet Access

If you’re like me, you love the convenience of installing modules for your Python interpreter from within the IDE. My personal preference is the PyCharm IDE, and easily adding modules for the interpreter is one of the features I love. Recently, however, I found myself needing to install Python modules on a computer without internet access. Without access to the internet, the IDE cannot simply download and install the modules automatically for you.

So, there I was – I had the IDE, I copied over the code, and I was working on getting everything set up. When I tried to run my code, I found that my next task was to manually install the necessary Python modules without internet!

To accomplish the task at hand, I performed the following steps:

  1. Determine which module I would need next
  2. Download the module using a computer with internet access
  3. Copy the module to the destination computer using a thumb drive
  4. Use Command Prompt to navigate to the module and install it
  5. Repeat steps 1-4 until all necessary modules were installed

Determine Which Module You Need

I was trying to get Python code to run on a computer with no access to the internet. Every time I would try to run the program, I would get an error when the interpreter went to look for a module I didn’t have. If you’re trying to do what I was trying to do, Python will tell you what module you need. For this guide, I’ll use matplotlib as the example case.

A screenshot of the error experienced when the interpreter went to look for the missing matplotlib library. When you want to install Python modules without internet access, you can use the interpreter to determine which modules you're missing. The error text shown is:

import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

Process finished with exit code 1
The error text shown when the Python interpreter couldn’t find the matplotlib library

Use A Computer With Internet Access To Download The Module

Using a computer that is able to access the internet, we now need to download the module from “PyPI”, the Python Package Index. To find modules, I typically just Google “pypi [name of module]”. So, in this case, I Googled “pypi matplotlib”:

Google search result for the search string: "pypi matplotlib".

Nice. I click the link and check to make sure I am satisfied that this appears to be the correct module. Under the name of the library, under the Navigation menu, I click the “Download files” link.

A screenshot of the Download files link on the Python Package Index website.

Selecting The Correct Build Distribution

Next, we need to select the correct distribution. (Here’s some info on Python distribution naming). When manually installing Python modules on a computer that doesn’t have access to the internet, I found that it was easiest to get the job done by using individual .whl files available under the Built Distributions heading.

For many packages, you’ll find a large number of distributions available, and you’ll need to choose the right one. While this can seem a bit daunting at first, primarily you’re looking for three things:

  1. The correct Python version
  2. The correct Operating System
  3. The correct type of CPU

So, for instance, in my case, the destination computer was a 64-bit Windows-based PC with an Intel i7 processor running Python 3.11.

As such, I chose the build with “cp311” (for Python 3.11), “win”, and “amd64” (for a CPU with x86-64 architecture).

Typically, I’ve found it straightforward to find the correct distribution. Worst comes to worst, you get it wrong, you get an error, and you try another build.

Once I click on the link to the build’s wheel file, I’m given my browser’s prompt to Open, Save as, etc.

Save the file to a thumb drive or to a shared network drive, etc., that you will be able to use to transfer the distribution to the computer that doesn’t have access to the internet.

Copy The Module To The Destination Computer

The next step is to take your thumb drive or other media and transfer the module to the destination computer. I made a folder off of the C drive root, C:\Python Packages, that would be easy to navigate to from the command prompt.

Use Command Prompt To Install Python Modules Without Internet Access

You’ve now downloaded your module and copied it to the computer that does not have access to the internet. Next, you’ll use the command prompt to install the module and get you on the road towards having a working Python interpreter!

Open the command prompt, and navigate to the folder you copied your .whl file to in the previous step.

A screenshot of the command prompt, with the user navigating to the directory with the Python module's .whl file. The command prompt is used to install Python modules on a computer without internet access.

Next, you’ll enter the following command, with the full filename for the .whl file at the end of the command:

pip install --no-index --no-dependencies --find-links . nameofwheel.whl

So, in my case, the command I entered at the prompt looked like the following:

The command entered at the prompt to install the previously downloaded matplotlib module. Also shows the successful results of the installation.

Download & Install Additional Python Modules Without Internet Access

Nice! Now, you’ve downloaded, transferred, and seen how to use the command prompt to install Python modules on a computer without internet access. Time to see if that solved your problem.

In my case, I return to PyCharm to try to run my code. I no longer receive the error for the matplotlib module! Of course, I do now have an error for a different module. 😂

An example of an error shown for a missing dependency after installing the matplotlib module. When you install Python modules without internet access, one method is to install modules one at a time, letting the Python interpreter tell you (via an error message) what module you need next.

You see, modules often have “dependencies”; they require other modules for internal use. Typically, when you install a module on a computer that does have access to the internet, the module’s dependencies are pulled and installed automatically for you.

Because we are installing modules offline, however, the installer is unable to pull the next required module from PyPI. Therefore, we have to choose between two courses of action:

  1. Find out the dependencies and download each new module as we go, or
  2. Determine all dependencies in advance, download and install all at once

For me, I find it easier to simply check after each installation if I’m missing any dependencies and to then download the next one. If you wanted, though, you could research your module’s dependencies and download all required modules in advance.

Whichever course of action you choose, at this point, you’ll simply repeat the steps above as necessary until you get past the ModuleNotFoundErrors. At that point, you’ll have installed any Python modules that were missing from your offline computer, and you’ll be ready to work on your code!

Leave a comment

%d bloggers like this: