Last updated: Apr 8, 2024
Reading timeยท3 min
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.
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
.
pip install --upgrade setuptools # ๐๏ธ or with pip3 pip3 install --upgrade setuptools
If you get an error that pip
is not in your PATH environment variable, try
running the following commands instead.
# 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
If the error persists, reinstall the setuptools
module.
First, reinstall the module by running the following command.
pip uninstall setuptools # Or with pip3 pip3 uninstall setuptools
Now install the module with the following command.
pip install setuptools # Or with pip3 pip3 install 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.
# 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.
# Windows python -m pip install setuptools # macOS or Linux python3 -m pip install setuptools # Windows alias py -m pip install setuptools
If the error persists, update your versions of pip, setuptools and wheel.
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.
# 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.
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:
Open your terminal in the same folder where the get-pip.py
script is
downloaded and run the following command.
# 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.
setuptools
is automatically installedIf 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.
# ๐๏ธ 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.