Last updated: Apr 10, 2024
Reading timeยท7 min
The error "Defaulting to user installation because normal site-packages is not writeable" occurs when we use an incorrect version of Python to install a package.
To solve the error, run the python3 -m pip install <package-name>
command.
Defaulting to user installation because normal site-packages is not writeable Collecting numpy Downloading numpy-1.23.4-py2.py3-none-any.whl Installing collected packages: numpy
The most common cause of the error is using an incorrect version of pip
and
Python when installing a package.
python -m pip
command to install the packageOne way to solve the error is to use the python -m pip
command.
# ๐๏ธ For Python 2 (or inside a virtual environment) python -m pip install numpy # ๐๏ธ For Python 3 python3 -m pip install numpy # ๐๏ธ For Windows py -m pip install numpy
Make sure to replace numpy
with the name of the package you're trying to
install.
If the error persists, get your Python version and make sure you are installing the package using the correct Python version.
python --version
For example, my Python version is 3.10.4
, so I would install the package with
python3.10 -m pip install <package-name>
.
python3.10 -m pip install numpy # ๐๏ธ If you get a permissions error use pip3 (NOT pip3.X) sudo python3.10 -m pip install numpy
Notice that the version number corresponds to the version of pip
I'm using.
If that didn't help, try running the pip install
command with the --user
option.
If you have multiple Python versions, make sure your IDE is running the correct Python interpreter.
--user
optionThe error also occurs when we don't have the necessary permissions to install a package.
To solve the error, run the command with the --user
option, e.g.
pip install numpy --user
.
pip install numpy --user pip3 install numpy --user python -m pip install numpy --user python3 -m pip install numpy --user py -m pip install numpy --user
Make sure to replace the numpy
placeholder with the actual name of the package
you are trying to install, e.g. pip install tensorflow --user
.
The --user
option installs the package in the user's home directory.
However, the --user
option wouldn't work if you have a virtual environment
active.
Another thing you could try is to elevate your permissions using sudo
.
sudo pip install numpy sudo pip3 install numpy sudo python -m pip install numpy sudo python3 -m pip install numpy
The sudo
prefix is used to elevate your permissions on macOS or Linux.
On Windows, you have to open CMD as an administrator.
To run CMD as an administrator:
pip install
command.pip install numpy pip3 install numpy python -m pip install numpy python3 -m pip install numpy py -m pip install numpy
If that didn't help, try creating a virtual environment.
pip install
command with the virtual environment active.# ๐๏ธ 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 specific package in the virtual environment pip install numpy
If the python -m venv venv
command doesn't work, try the following 2 commands:
python3 -m venv venv
py -m venv venv
Make sure to use the correct command to activate your virtual environment depending on your operating system and your shell.
Your virtual environment will use the version of Python that was used to create it.
sudo
because then you'd only permit root users to install packages.If you created your virtual environment using sudo
, try changing its
permissions or recreate it without sudo
.
sudo chmod -R 777 venv
The command above assumes that your virtual environment is in a folder called
venv
.
777
means granting all users full access to the contents of the directory.
If that didn't help, try upgrading pip
.
Here are the commands for upgrading pip
on all operating systems.
Which command works depends on your operating system and your version of Python.
# ๐๏ธ If you have pip already installed pip install --upgrade pip # ๐๏ธ If your pip is aliased as pip3 (Python 3) pip3 install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python -m pip install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python3 -m pip install --upgrade pip # ๐๏ธ If you have easy_install easy_install --upgrade pip # ๐๏ธ If you get a permissions error sudo easy_install --upgrade pip # ๐๏ธ If you get a permissions error when upgrading `pip` pip install --upgrade pip --user # ๐๏ธ Upgrade pip scoped to the current user (if you get a permissions error) python -m pip install --user --upgrade pip python3 -m pip install --user --upgrade pip # ๐๏ธ Installing directly from get-pip.py (MacOS and Linux) curl https://bootstrap.pypa.io/get-pip.py | python # ๐๏ธ If you get permissions issues curl https://bootstrap.pypa.io/get-pip.py | sudo python # ๐๏ธ Alternative for Ubuntu/Debian sudo apt-get update && apt-get upgrade python-pip # ๐๏ธ Alternative for Red Hat / CentOS / Fedora sudo yum install epel-release sudo yum install python-pip sudo yum update python-pip
If you get the error "ModuleNotFoundError: No module named 'pip'", click on the following article.
If the commands from the code sample didn't work for you, click on the link above.
After you upgrade pip
,
upgrade setuptools as well.
pip install --upgrade setuptools wheel pip3 install --upgrade setuptools wheel python3 -m pip install --upgrade setuptools wheel
Try to run the pip install
command now that pip
and setuptools
are
upgraded.
You might have multiple versions of pip
installed on your computer. A common
cause of the "Defaulting to user installation" message is pip
being out of
date.
Try running the python --version
command.
python --version
For example, if the output is 3.7
, try running the following command to
upgrade pip
.
pip3.7 install --upgrade pip
If that didn't help, try running CMD as an administrator.
To run CMD as an administrator:
pip install
command.pip install <package-name> pip3 install <package-name> python -m pip install <package-name> python3 -m pip install <package-name>
pip install
command.If opening CMD as an administrator didn't help, try to open PowerShell as an administrator and run the command.
To run PowerShell as an administrator:
pip install
command.The error is often caused when a directory or a file is locked by another process.
If the error persists, change the user's access permissions.
The error is often caused because the user doesn't have access to modify the directory where the package should be installed.
To solve the error, allow the user full access to the Python directory.
To change the access permissions for the user:
C:\Program Files (x86)\Python310
.You can find where Python is installed with either of the following 2 commands.
where python python -c "import os, sys; print(os.path.dirname(sys.executable))"
pip install <package-name>
command again.Once you give "Full access" permissions to the user, you should be able to
pip install
packages without getting any errors.
If you have a virtual environment active, your Python location will be scoped to the specific virtual environment.
You can run the where python
command with your virtual environment active to
find the directory.
If you use a virtual environment, another thing that might help is to:
venv
folder.pyvenv.cfg
file.include-system-site-packages
property to true
.pip install
command.If none of the suggestions helped, try reinstalling Python.
Download the installer for the latest version of Python from the official python.org website.
Start the installer again and click on "Uninstall".
Make sure to tick the following options if you get prompted:
Once the "Add python.exe to PATH" checkbox is checked, click on "Install Now".
After the installation, Python will be installed and configured properly.
If you encounter issues when installing or upgrading pip
or setuptools
check
out the following articles: