running pypi server locally.

Reading Time: 2 minutes

Last Updated: 5/10/2024:

It might be the case that you need to run a pypi server locally.

A pypi server is basically a HTTP server that hosts wheel files. yes – it does a little bit more than just that but the use is pretty simplistic. If using just a HTTP server one could place files in the “simple” directory pretty much. Each directory represents a repository. Each of the module “wheels” can be placed in the directory by that name. Simple right?

Now you might wonder what the benefits for this are. The simplest answer is that you are in an air-gapped secure area but still need to deploy pythonic solutions. Or, you could be having trouble with pythons ability to either suppress using a certificate or using a proxy. Either way it keeps queries local. The downside? The files are local and so you may need to spend some time collecting and updating the local “wheel” to maintain your environment.

So, you may not always need to know how to do this. But when you need to, it’s a handy skill to have ready.

You can install “pypi-server” by installing the wheel directly.

pip install pypiserver-2.1.1-py2.py3-none-any.whl

Note: if this is a fresh installation you may also need to install the preqs. As of this writing (5/9/2024) it only required the packaging module.

pip install packaging-24.0-py3-none-any.whl

The Server can then be run directly. In this case I serving things off a Microsoft environment. I am using a drive letter m: with a directory named “wheels” as my base.

In my case, to run pypi-server on windows

pypi-server run -p 8080 m:\wheels

On your requesting workstation you might want to set some PIP config vars to make requests easier. You can substitute “localhost” with the ip or name of the workstation that you used.

pip config set global.index "http://localhost:8080"
pip config set global.index-url "http://localhost:8080/simple"

There are some common “wheels” which you might want to populate in the beginning.
* wheel
* setuptools

Now all you have to do is collect / deploy your wheels. Please be verify the name of the wheel. You don’t want to pick up some wheel with a similar name that … perhaps has a bug still, or worse is infected? (just saying). Keeping your searches to pypi and applying some due diligence should help.

Pro-Tip: (I just wanted to say that)

You can use the PIP download command to download the wheel you want. As a bonus it pulls the associated dependencies. That can save your sanity.


To clear settings:

pip config unset global.index
pip config unset global.index-url

To list settings:

pip config list
This entry was posted in Programming, Python. Bookmark the permalink.