No module named 'pkg_resources' in Python [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 8, 2024
3 min

banner

# No module named 'pkg_resources' in Python

The error "No module named 'pkg_resources'" occurs when you don't have the setuptools package installed.

To solve the error, open your terminal and run the pip install setuptools command.

shell
Traceback (most recent call last): File "/var/www/bin/pip", line, in <module> from pkg_resources import load_entry_point ImportError: No module named pkg_resources

Open your terminal and run the following command to install setuptools.

shell
pip install --upgrade setuptools # ๐Ÿ‘‡๏ธ or with pip3 pip3 install --upgrade setuptools

upgrade setuptools

If you get an error that pip is not in your PATH environment variable, try running the following commands instead.

shell
# python2 and Windows python -m pip install --upgrade setuptools # for Python3 on macOS or Linux python3 -m pip install --upgrade setuptools # ๐Ÿ‘‡๏ธ using an alias on Windows py -m pip install --upgrade setuptools

upgrade setuptools using python m pip

If the error persists, reinstall the setuptools module.

First, reinstall the module by running the following command.

shell
pip uninstall setuptools # Or with pip3 pip3 uninstall setuptools

uninstalling setuptools

Now install the module with the following command.

shell
pip install setuptools # Or with pip3 pip3 install setuptools

installing setuptools

If you get an error that pip is not in your PATH environment, variable try running the following commands instead.

The following command uninstalls the module.

shell
# Windows python -m pip uninstall setuptools # macOS or Linux python3 -m pip uninstall setuptools # Windows alias py -m pip uninstall setuptools

And the following command installs it.

shell
# Windows python -m pip install setuptools # macOS or Linux python3 -m pip install setuptools # Windows alias py -m pip install setuptools

# Update your versions of pip, setuptools and wheel

If the error persists, update your versions of pip, setuptools and wheel.

shell
pip install --upgrade pip setuptools wheel # or with pip3 pip3 install --upgrade pip setuptools wheel

If you get an error that pip is not in your PATH, run one of the following commands instead.

shell
# Windows python -m pip install --upgrade pip setuptools wheel # macOS or Linux python3 -m pip install --upgrade pip setuptools wheel # using a Windows Alias py -m pip install --upgrade pip setuptools wheel

If the error is resolved, you don't have to try any of the other suggested solutions.

# Using the official get-pip.py script to install setuptools

If the error persists, use the official get-pip script to install setuptools.

To download the script from https://bootstrap.pypa.io/get-pip.py:

  1. Clicking on the link.
  2. Right-click in your browser window.
  3. Select "Save as".

Open your terminal in the same folder where the get-pip.py script is downloaded and run the following command.

shell
# Windows python get-pip.py # macOS or Linux python3 get-pip.py # Windows alias py get-pip.py

The script will take care of installing and upgrading setuptools in the environment.

# Create a virtual environment where setuptools is automatically installed

If the error persists, try creating a virtual environment.

The venv module is available by default in Python 3.3 and later, and installs setuptools into the created environment.

shell
# ๐Ÿ‘‡๏ธ Use the correct version of Python when creating VENV python -m venv venv # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Install the modules in your requirements.txt file # (if you have one) pip install -r requirements.txt

If the python -m venv venv command doesn't work, try the following 2 commands:

  • python3 -m venv venv (macOS or Linux)
  • py -m venv venv (Windows)

Make sure to use the correct activation command depending on your operating system.

Your virtual environment will use the version of Python that was used to create it.

The setuptools module is guaranteed to be installed in the virtual environment.

If the error persists, follow the instructions in my ModuleNotFoundError: No module named 'setuptools' article.

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev