Search code examples
pythonpipvirtualenv

Pip ERROR: No matching distribution found for python


I'm tidying up a python project for public distribution.

It uses a virtual environment and has a requirements.txt file containing all dependencies.

I would like this environment to include a dependency on the specific version of python I built it with. I seem to remember that this is good practice.

So I attempted to install python using pip, which kind of seems the obvious thing to do, although pip itself was installed using the standard python download (for version 3.12.0)

So I tried two possible commands:

pip install python

OR

pip install python==3.12.0

However, pip gives the following error messages for the first:

ERROR: Could not find a version that satisfies the requirement python (from versions: none)
ERROR: No matching distribution found for python

and a similar message for the second.

I also found that the same occurs if I try to use pip outside the virtual environment (though that isn't something I intend to do - I did this to pin down the exact source of the problem). Thus, this seems to be an issue with pip, not an issue with virtual environments.

I looked around but couldn't see any queries from others who experienced the same problem.

This suggests it's a dumb thing to do, so maybe nobody else has tried it. Or alternatively, and this is a bit like the question 'why haven't aliens contacted us' it's because every time they do it, it works fine so there's nothing worth remarking on (like, maybe the aliens contact us all the time, but we just don't notice, a theory I'm not averse to).

I found a 'standard' method for installing a specific version of python in a virtual environment here

But it seems odd that pip can't be used to install python.

Is the problem an error or a design feature? I'm flagging it as an error, because if there is something wrong with my setup, I want to know.


Solution

  • requirements.txt file is a file containing all required python packages, such as libraries, frameworks, etc. You don't need to specify python version there.


    If you want to specify python version you can do it in setup.py or pyproject.toml: https://packaging.python.org/en/latest/tutorials/packaging-projects/#configuring-metadata

    See requires-python section there.


    Also, I found this thread helpful: Enforcing python version in setup.py

    Check most liked answer there