This error is often encountered by Linux users trying to install Python packages
from the requirements.txt. This issue occurs only while using a virtual
environment, specifically the virtualenv module of Python. When someone used
pip freeze > requirements.txt
to write the pip freeze's output requirements to
a file, a bug of that library leads to this error. It writes the requirement
pkg-resources==0.0.0
to the file, this will lead to the described error. There
are multiple ways to fix this, depending on whether you are the maintainer of
the requirements or merely a user. As the maintainer of the repository, we
strongly suggest you switch from virtualenv to venv. Since Python 3.3, the venv
module is a built-in module. To change your virtual environment, you may follow
the steps below.
How to fix pkg-resources==0.0.0 (5min)
- Clear the dependencies
- Write your dependencies and filter out the pkg-resources
pip freeze | grep --invert-match pkg-resources > requirements.txt
- Remove the virtualenv, Assuming it is stored in a folder called "venv"
rm -rf venv
Make sure you have your virtual enmvironment activated
- Write your dependencies and filter out the pkg-resources
- Create a new virtual environment
- Create a clean venv
python3 -m venv venv
- Activate it
source venv/bin/activate
- Reinstall requirements
pip install -r requirements.txt
- Create a clean venv
Done! The error should no longer occur.
If you are not the maintainer of the repository we suggest you recommend this post to the maintainer. While the maintainer is working on fixing this, you can install the dependencies similarly to the freeze command above, by filtering the packages for it:
cat requirements.txt | grep --invert-match pkg-resources | xargs -n 1 pip install
Explanation
cat will output the content of the requirements, grep will filter it for pkg-resources==0.0.0, and xargs -n 1 will execute pip install for each line returned by the preceding commands.
We hope this solves your issue. If you encounter any problems, please don't hesitate to leave a comment. We will try to help you as soon as possible!
What is pkg-resources?
In essence: pkg-resources is a development dependency of packages which use
setuptools. Usually it should not be part of any actual packages. This
is clearly a bug in virtualenv
.