Working on Python for coding is always fun if you don’t get errors all the time you code, though errors can show up, which is normal. Beginners get more errors as they are learning a new language so that one day, they can become a professional. Sometimes, you found yourself in an error code that shows up as a warning like defaulting to user installation because normal site-packages is not writeable.
When you get this error warning, it is not the end of your coding, you can always fix the issues as there is no such issue that can’t be solved. Let’s check out how to fix this error
How to Fix defaulting to user installation because normal site-packages is not writeable
There are a few reasons that can cause the error. Have a look at some issues and the best solutions
1. Check Multiple Python Versions
In the Linux system, you have Python by default and you have also installed a different version. In this case, you will get an error when you type the command pip install <package_name>. The main reason for defaulting to user installation because normal site-packages is not writeable as you have multiple Python version installed. When you use pip/pip3, a package is tried to be added in the default version, which causes the error.
Solution
You need to specify the Python interpreter when installing the package that tries to run using the following command
# For Python 2
python -m pip install [package_name]
# For Python 3
python3 -m pip install [package_name]
if you still encounter the error, you need to append the exact Python version installing the package.
#Using specific Python interpreter version
python3.10 -m pip install [package_name]
2. Installing the virtual environment
Installing the virtual environment can solve the warning issue. This is one of the best solutions to fix the error. Follow the steps
- Install the virtual environment:
$ pip install virtualenv
- Check if the virtual environment is properly installed:
$ virtualenv –version
- Create the environment for the project:
$ virtualenv my_name
- The directory name will be the created my_name after running the command. This is where your Python packages installed.
- You just need to choose the Interpreter of Python you wish to have. It is useful if you have many Python versions are installed:
$ virtualenv -p /usr/bin/python3 virtualenv_name
- The last step is to activate your virtual environment:
$ source virtualenv_name/bin/activate
3. Check Permission for “defaulting to user installation because normal site-packages is not writeable” issue
In the case, you have multiple user accounts in Windows/ Linux or Mac, you need to make sure that Python is installed for all the users or the specific user. If the Python is accessible by a specific user, then you may get an error.
You need to verify if Python is installed for all the users or if you have permission to use it.
4. Reinstall python
If the above solutions don’t work, you can reinstall python
Conclusion
This is how you can get rid of defaulting to user installation because normal site-packages is not writeable error.
Don’t forget to drop a message if it helps you!