Create a fresh virtual environment using the Python version the project was built for, then install from its requirements file. Most pip failures on old projects are mismatches: a Python too new for the project's pinned packages, packages that conflict with each other, or a system Python that refuses installs outside a virtual environment, which is what the "externally-managed-environment" error means.
What's the problem
pip install -r requirements.txt fails. You see "externally-managed-environment", "Could not find a version that satisfies the requirement", "ResolutionImpossible", "metadata-generation-failed", or a compiler error. The project used to install, on someone else's machine, years ago.
Why it happens
- The system Python is protected. Many operating systems now mark their own Python as externally managed, so pip refuses to install into it and points you to a virtual environment.
- Your Python is too new, or too old. Packages pinned years ago may not support today's Python, so pip finds no matching version.
- The pins conflict. Two packages require incompatible versions of a third, and pip's resolver can't satisfy both.
- Packages need compiling. Older versions of scientific, image or database packages build from source when no prebuilt version matches your Python, and fail without the right compilers and system libraries.
- The old environment was half-broken. A virtual environment copied between machines or Python versions doesn't work. Environments are rebuilt, not moved.
How to fix it
- Find the Python version the project expects. Check
runtime.txt,.python-version,pyproject.toml(requires-python), theDockerfileand any build settings. - Install that version with your system's tools or a version manager such as pyenv, alongside your current Python.
- Create a fresh virtual environment with it:
python -m venv .venv, then activate it. - Install from the requirements file:
python -m pip install -r requirements.txt. - If pip can't find a version, the pinned version doesn't support this Python, or the package was renamed. Check the package's page on PyPI.
- If it reports conflicts, read which packages disagree and loosen or update one pin at a time.
- Once it installs and runs, record exact versions for every dependency (a lockfile, for example with pip-tools), then upgrade Python and packages in steps.
When to call Preventionlabs
If the right Python and a fresh environment get it installing, you're through the hardest part. Call us when the pinned packages no longer exist for any supported Python, the conflicts chain, or the code depends on library behaviour that's since changed. A resurrection delivers an app that builds and starts on maintained dependencies, deployed in your own hosting account.
Submit your project for a free assessmentFree assessment. $10,000 AUD flat to get it live, only if we take it on and you go ahead.
Sources
- Python: venv: Creation of virtual environmentsofficial docs
A virtual environment is created on top of an existing Python installation, known as the virtual environment’s “base” Python, and by default is isolated from the packages in the base environment, so that only those explicitly installed in the virtual environment are available.
- Python Packaging Authority: Externally Managed Environmentspackaging specification
This specification defines an EXTERNALLY-MANAGED marker file that allows a Python installation to indicate to Python-specific tools such as pip that they neither install nor remove packages into the interpreter’s default installation environment, and should instead guide the end user towards using Python Virtual Environments.
- pip: Dependency Resolutionofficial docs
During deployment, you can create a lockfile stating the exact package and version number for each dependency of that package.
- pip: User Guide: Requirements Filesofficial docs
“Requirements files” are files containing a list of items to be installed using pip install like so: