[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

python3 -m pip install [package_name]

Python 2

python -m pip install [package_name]

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

python3.7 -m pip install [package_name]

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

$ pip install virtualenv

Step 2: Verify if the Virtual environment is installed properly by checking its version

$ virtualenv --version

Step 3: Create a new virtual environment for your project

$ virtualenv my_name

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.

$ virtualenv -p /usr/bin/python3 virtualenv_name

Step 5: Activate the Virtual Environment

$ source virtualenv_name/bin/activate

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.

Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
Python Ord() A Step-By-Step Guide

Python ord(): A Step-By-Step Guide

Table of Contents Hide ord() Function in Python Example ord() vs chr() ord() Function ExamplesTypeError: ord() expected a character, but string of length 2 found. In Python ord() function accepts a single…
View Post
Python List Pop()

Python List pop()

Table of Contents Hide Syntax of List pop() pop() ParametersReturn Value from List pop()Example 1: Pop item at the given index from the listExample 2: pop() without an index, and for…
View Post
Typeerror Unhashable Type 'List'

TypeError: unhashable type: ‘list’

Table of Contents Hide TypeError: unhashable type: ‘list’Example – unhashable type: ‘list’Solution to TypeError: unhashable type: ‘list’.Solution 1 – By Converting list into a tupleSolution 2 – By Adding list…
View Post