Solve - No module named 'pkg_resources' in Python


Borislav Hadzhiev

Last updated: Apr 20, 2022


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.

# 👇️ 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.

# 👇️ 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.

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 by clicking on the link, right-clicking and selecting "Save as" in your browser.

Open your terminal in the location where the file is downloaded and run the following command.

# 👇️ On Linux or MacOS python # 👇️ using python 3 python3 # 👇️ On Windows py

The 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.

# 👇️ 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.