Last updated: Apr 20, 2022
Check out my new book
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
python3 -m pip install --upgrade setuptools.
Open your terminal and run the following command to install
# 👇️ 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
# 👇️ 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 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.
# 👇️ On Linux or MacOS python get-pip.py # 👇️ using python 3 python3 get-pip.py # 👇️ On Windows py get-pip.py
get-pip.py script installs or upgrades
pip and installs
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
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.
setuptools module is guaranteed to be installed in the virtual