[Solved] Defaulting to user installation because normal site-packages is not writeable
If you have multiple versions of Python and try to install the packages using the pip3 install <package> command Python will throw an error defaulting to user installation because normal site-packages is not writeable.
In this article, we will take a look at what is defaulting to user installation because normal site-packages is not writeable and how to fix this error.
Defaulting to user installation because normal site-packages is not writeable
There are several reasons behind this error and some of the most common issues and solutions are mentioned below.
Issue 1: Multiple Versions of Python
In the case of Linux environments, Python comes by default and the version of Python depends on a different distribution of Linux and you may have installed a different version of Python.
Now when you are using pip install <pacakage_name> command to install the packages it will throw the error site-packages are not writable.
The reason behind this is that you have multiple versions of Python and since you are using pip / pip3 it would try to add the packages in the default version of Python which is managed by Python and hence it will throw an error.
Solution 1 – Specify Python Interpreter while installing packages
To install the packages try running the below command by appending the Python command to it. This will ensure the correct Python interpreter is specified and the packages will be installed over there.
Python 3
Python 2
If this also throws an error the better way is to resolve this issue is to append the exact version of Python will installing the packages.
Install Package using Specific Python Interpreter version
Solution 2 – Install Virtual Environment
A virtual environment creates an isolated Python virtual environment and keeps all the dependencies for the project inside it. This would be the ideal solution to resolve the conflict.
Follow the steps to create the virtual environment for your project.
Step 1: Install Virtual Environment Module in Python
Step 2: Verify if the Virtual environment is installed properly by checking its version
Step 3: Create a new virtual environment for your project
After running this command, a directory named my_name will be created. This is the directory that contains all the necessary executables to use the packages that a Python project would need. This is where Python packages will be installed.
Step 4: Specify the Python interpreter of your choice. This will be useful if you have multiple versions of Python installed.
Step 5: Activate the Virtual Environment
Issue 2 – Permission Issue
If you have multiple user accounts in Linux/Mac/Windows do check if the Python is installed for specific users or all the users. Many times if it’s accessible only by specific users and hence you get an error that site-packages are not writeable.
Solution – Install Python for specific user and grant permissions
Verify if Python is installed for all the users and has the correct permissions to write and install the packages.
Conclusion
Mostly when you have multiple version of Python installed on your machine and if your OS also comes with default version of Python there would be a conflict and when you install the packages Python will throw defaulting to user installation because normal site-packages is not writeable.
The best way to resolve this issue is by Creating the virtual environment or specifying the exact version of Python interpreter while installing the packages.
Defaulting to user installation because normal site-packages is not writeable
When installing Python packages using pip , you might encounter the following message in the console:
This message appears when pip fails to install the package in the system-wide directory.
This is not an error message as pip can still install the package, but you might have problems like unable to access the package from your terminal as follows:
This tutorial explains why this message occurs and how you can make it disappear in practice.
Why this message occurs
By default, pip tries to install your package in the system-wide directory named site-packages .
When you lack permission to write to system-wide site-packages , then pip will install it in the user-wide site-packages instead.
You can verify this by running python -m site command from the terminal. There should be multiple site-packages directory as shown below. The screenshot is from a Macbook:
The one under /Applications/Xcode.app is the system-wide directory that requires root permission to write.
The USER_SITE one is where pip installs packages when the “Defaulting to user installation” message appears.
How to solve for Windows users
If you’re using Windows, then this message likely occurs because you installed Python under C:\Program Files which requires administrator permission to modify.
To remove the message, you need to add the —user flag when installing packages:
If you want to permanently fix this, you need to uninstall Python from your computer and install it again using the default settings.
If you need to customize Python installation, then take note of the default installation path and use it when you customize the install location:
By using the location provided in Python default installation, you will have Python installed in a folder that’s writeable without admin permission.
Also, don’t forget to check the options ‘Use admin privileges’ and ‘Add python.exe to PATH’.
Try running pip install command again and you won’t receive the message this time.
How to solve for Linux users
If you’re using Linux, then you will get this message because you installed python using sudo as in:
In Linux-based OS, the system-wide packages directory is also known as dist-packages , and you need root permission to access this directory.
Again, you can verify this using the python -m site command:
When pip fails to install to the dist-packages directory, the message appears to notify you that it’s installing to the site-packages directory instead.
To remove the message, you need to add the —user flag when installing packages:
This command tells pip to skip the dist-packages directory and go to site-packages directly.
If you want to install to dist-packages , then you need to add sudo to the install command:
But you might get a warning message in the console as follows:
If you want to permanently fix this message, then you need to install Python without using sudo . This means you can’t use apt-get either.
You can get Python in Linux using Homebrew, or you can download the source and compile it yourself.
Follow the steps below to compile Python manually. Note that you can get the full path to Python .tgz file from here:
The make command might take a while to complete. Once done, you should now have python3 and pip3 available from your user directory.
Use the which command to verify the installation:
Alright. Now you can install packages without using sudo command:
Because you installed Python and pip without using sudo , the default installation will use the site-packages directory.
Keep in mind that installing Python from source like this enables Python only for the current user. You need to repeat the process for other users.
How to solve for Mac users
If you’re using a Mac, this message appears when you use Python and pip that are provided by the system.
It’s recommended to install your own Python version to avoid permission problems and future changes from the macOS itself.
You can install Python using Homebrew as follows:
Once installed, you should open a new Terminal window for the changes to take affect.
You can see the active python3 and pip3 versions using the which command as follows:
Once both python3 and pip3 are using the Homebrew-sourced version, you’re good to go.
Install any packages using pip install and you won’t receive the error message.
Conclusion
Now you’ve learned how to solve the “Defaulting to user installation” message that occurs when installing Python packages.
I hope this tutorial is helpful. Until next time!
Get 100 Python Snippets Book for FREE
100 Python snippets that you can use in various scenarios
Save 1000+ hours of research and 10x your productivity
About
Sebhastian is a site that makes learning programming easy with its step-by-step, beginner-friendly tutorials.
Learn JavaScript and other programming languages with clear examples.
How To Fix The “Defaulting To User Installation Because Normal Site-packages Is Not Writeable” Problem?
Python is a scripting language, and there are times when you have to create a Python package and distribute it manually. The problem is that you have to do a lot of extra work to make sure that you can install the Python package. The following blog post will help users solve “Defaulting to user installation when regular site-packages is not writeable” in Python.
How Can You Fix The “Defaulting To User Installation Because Normal Site-packages Is Not Writeable” Problem?
Have you ever attempted to install a package and received the following error:
The method to fix the “Defaulting to user installation because normal site-packages is not writeable” problem is uninstalling and then reinstalling Python. After that, everything looks to be in working condition. We’re not sure why, but the message “Defaulting to user installation because normal site-packages is not writeable” doesn’t appear anymore.
Approach 1: Reinstall Python
After uninstalling and reinstalling Python, It’s all OK. It seems logical that it wouldn’t print out the message “Defaulting to user installation because normal site-packages is not writeable”.
Approach 2: Update The Python Download Location
Change the Python download path and run cmd as admin/without admin, or both.
Approach 3: Upgrade To The Latest Python Version
Just make sure your Python version is up-to-date.
Approach 4: When Installing The Package, Utilize The Python Version
When installing the package, you need to use the Python version.
Python 3:
Python 3.7:
Python 2:
Conclusion
We hope you enjoyed our article about fixing the “Defaulting to user installation when regular site-packages are not writeable” issue. We are confident that with this information, you will be able to make the most of your Python development experience by installing packages in a user-specific location rather than system-wide.
If you are still having any problems with your Python packages, please feel free to leave us a comment. Thank you for reading; please make sure to share this helpful article with others!
Forums
Defaulting to user installation because normal site-packages is not writeable
Hello! Why if in consol python3 -m pip3 install xlwt or pip install xlwt — answer Defaulting to user installation because normal site-packages is not writeable BUT Requirement already satisfied: xlwt in /usr/local/lib/python3.9/site-packages (1.3.0) BUT ModuleNotFoundError at /CertifiedValueJ/kinematicviscosityvalues/ No module named ‘xlwt’ Request Method: GET Request URL: https://labjournal.pythonanywhere.com/CertifiedValueJ/kinematicviscosityvalues/ Django Version: 4.0.4 Exception Type: ModuleNotFoundError Exception Value:
No module named ‘xlwt’ Exception Location: /home/LabJournal/LabJournal/viscosimeters/views.py, line 79, in <module> Python Executable: /usr/local/bin/uwsgi Python Version: 3.9.5
I fix «Defaulting to user installation because normal site-packages is not writeable» BUT still «ModuleNotFoundError» (
We have a help page about installing modules here
glenn | 9160 posts | PythonAnywhere staff | July 19, 2022, 5:20 p.m. | permalink