Build job-ready skills in AI, ML, Data Science, and more.Get 50% off for life!
In Python, the error message “Defaulting to user installation because normal site-packages is not writeable” usually appears when we try to install packages without having the necessary permissions to write to the system-wide site-packages directory.
This commonly occurs in virtual environments or when we lack administrative access.
To resolve this error, we can use the following approaches:
Using a virtual environment
First, create a virtual environment using tools like venv
or virtualenv
, using this command in the terminal:
Now, activate the virtual environment using these commands:
Finally, install packages within the virtual environment using this command in the terminal:
This way, we’ll have write access to the virtual environment’s site-packages directory without requiring system-wide permissions.
In the following terminal command, we're using Python 3.8 to create a new virtual environment named myenv
. You just need to run the command pip install flask
or any package you want to install.
Specifying a user installation
We can install the package in the user’s local site-packages directory using this command:
Use the --user
flag when installing packages to specify a user installation instead of a system-wide installation.
Using a package manager
If you’re using Linux, you can use system-wide package management like apt
or yum
to install Python packages. Typically, administrative rights are needed for this.
These approaches provide us with the necessary write permissions to install packages in a controlled and isolated manner.
Free Resources