Solve - No module named 'pkg_resources' in Python

avatar

Borislav Hadzhiev

Last updated: Apr 20, 2022

banner

Check out my new book

Solve - No module named 'pkg_resources' in Python #

The Python "No module named 'pkg_resources'" occurs when setuptools is not installed in our Python environment. To solve the error, install the module by running the python3 -m pip install --upgrade setuptools.

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

shell
# 👇️ for Linux or MacOS python3 -m pip install --upgrade pip setuptools wheel # 👇️ Windows py -m pip install --upgrade pip setuptools wheel # 👇️ try upgrading pip pip3 install --upgrade pip setuptools

If the error is not resolved, try to uninstall setuptools and then install the module.

shell
# 👇️ uninstall setuptools pip3 uninstall setuptools # 👇️ install setuptools pip3 install setuptools # 👇️ if you don't have pip setup in PATH python3 -m pip install setuptools

You can also try to upgrade the version of the setuptools package.

shell
pip3 install setuptools --upgrade # 👇️ if you don't have pip setup in PATH python3 -m pip install setuptools --upgrade

Alternatively, you can use the official get-pip script to install setuptools.

Download the script from https://bootstrap.pypa.io/get-pip.py by clicking on the link, right-clicking and selecting "Save as" in your browser.

Open your terminal in the location where the get-pip.py file is downloaded and run the following command.

shell
# 👇️ On Linux or MacOS python get-pip.py # 👇️ using python 3 python3 get-pip.py # 👇️ On Windows py get-pip.py

The get-pip.py script installs or upgrades pip and installs setuptools and wheel if they aren't installed already.

Alternatively, you can create a virtual environment. The venv module is available by default in Python 3.3 and later, and installs pip and setuptools into the created virtual environment.

shell
# 👇️ use correct version of Python when creating VENV python3 -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

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.

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.