Introduction
In Python, you may encounter the error "defaulting to user installation because normal site-packages is not writeable" when you try to install a package using pip
. This error occurs because the system-level site-packages directory is not writable, so pip
defaults to installing packages in the user-level site-packages directory. This tutorial will explain how to resolve this issue.
Understanding site-packages directories
In Python, there are two types of site-packages directories: system-level and user-level.
- The system-level site-packages directory is located at
/usr/lib/pythonX.Y/site-packages
and is used to store packages that are available to all users on the system. - The user-level site-packages directory is located at
~/.local/lib/pythonX.Y/site-packages
and is used to store packages that are only available to the current user.
The problem
The error "defaulting to user installation because normal site-packages is not writeable" occurs when you try to install a package in the system-level site-packages directory, but do not have the necessary permissions. In this case, pip
defaults to installing the package in the user-level site-packages directory.
Resolving Defaulting to user installation because normal site-packages is not writeable Error in Python
There are two ways to resolve the issue of defaulting to user installation:
Option 1: Install the package using sudo
If you have administrative privileges, you can use sudo
to install the package in the system-level site-packages directory. To do this, run the following command:
sudo pip install <package_name>
For example, to install the requests package, you would run:
sudo pip install requests
Option 2: Install the package in the user-level site-packages directory
If you do not have administrative privileges, you can still install the package in the user-level site-packages directory. To do this, you need to add the --user
option to the pip install
command.
pip install --user <package_name>
For example, to install the requests
package in the user-level site-packages directory, you would run:
pip install --user requests
See also: How to Resolve error: "legacy-install-failure" in Python?
Conclusion
In this tutorial, you learned how to resolve the issue of defaulting to user installation because normal site-packages is not writeable in Python. By either using sudo
or the --user
option, you can install packages in the desired site-packages directory.
Defaulting to user installation because normal site-packages is not writeable FAQs
The error "defaulting to user installation because normal site-packages is not writeable" occurs when you try to install a package using pip
and the system-level site-packages directory is not writable. In this case, pip
defaults to installing the package in the user-level site-packages directory, which is writeable by the current user.
In some cases, you may need to install packages in the system-level site-packages directory so that they are available to all users on the system. For example, if you're setting up a shared server and want all users to have access to the same packages, you'll need to install them in the system-level site-packages directory.
If you don't have administrative privileges, you can still install packages in the user-level site-packages directory. To do this, you need to add the --user
option to the pip install
command. For example: pip install --user
.