Fixed: pip/python: normal site-packages is not writeable

Here, I will show you how to fix the error “Defaulting to user installation because normal site-packages is not writeable” while installing a package in Python using pip command.

I faced this issue recently while installing openpyxl with pip command. Then I realized this error had nothing to do with a package.

The reason of Defaulting to user installation because normal site-packages is not writeable error

If you are facing this issue that means that the Python version you are using to install the package is invalid for that package.

So make sure the pip and python versions are valid and good to go.

I was using multiple versions of Python at the same time on my machine and that was the issue.

(Nowadays Python is pre-installed with the OS and besides that, we generally install a newer version of Python as well. This is a major reason we are getting this error)

How to fix it

Well, there are multiple ways to fix this and depending upon your current version of pip and python, one of my given methods will fix this error.

If your current Python version is Python3 then run the following command:

python3 -m pip install [pacakge that you are going to install]

For example, if you are going to install opencv and then basic command is pip install opencv-python

But you should run the following command instead of that

python3 -m pip install opencv-python

It should fix your issue.

If you are using python version 2 then do the following:

python -m pip install opencv-python

To install numpy just use:

python3 -m pip install numpy

or

python -m pip install numpy

depending upon the Python version that you are using currently.

What to do if it does not work either

Just specify the exact Python version like this:

python3.7 -m pip install numpy

(If your Python version is 3.7 or change it accordingly)

Having multiple users may also cause permission issues

You can also try these:

pip install numpy --user

python -m pip install numpy --user
python3 -m pip install numpy --user

or

python3.7 -m pip install numpy --user

If you are using Linux then I will recommend using sudo before your command.

If you are using Windows then try to run the CMD as administrator.

Just right-click on your CMD and click run as administrator.

The last and most complicated (As well as best) method is creating a virtual env.

You can check this: Create virtual environment using venv

Leave a Reply

Your email address will not be published. Required fields are marked *