If you are using pip install
command to install a third-party python library on your system, you might encounter the “Consider using the --user
option or check the permissions.” error. If so, don’t worry, it is a very common issue that can be fixed easily.
Table of Contents
In this article, we will discuss about this error and how to solve it using the --user
options.
Could not install packages due to an EnvironmentError: [Errno 13]
Permission denied: '/usr/local/lib/python3.5/dist-packages/xxxxxx'
Consider using the `--user` option or check the permissions.
What causes the “Consider using the --user
option” error in Python ?
When we run pip install command to install a third-party library without the –user option, it tries to install the package system-wide. If the user do not have admisnistrative permission, then this error message “Consider using the --user
option or check the permissions” occurs.
This python error occurs because the system cannot install the package without the necessary permissions.
When should we use –user option ?
We should use the --user
option while installing a python package locally without the need for administrative permission.
The --user
option allows us to install the package locally in the user directory, where only the current user has the full control.
It is very helpful when we are working in a shared environment where we might not have full control of the system.
How to solve the “pip install fix Consider using the –user option” error
Now that we know the reason for the error, we can fix the error by any of the following solutions:
- Use the
--user
option with the pip install command - Using sudo command while installing Python packages.
- Use a virtual environment.
Solution 1: Use --user
option to install Python Packages
As the error itself suggest “consider using --user
option”, so we can use the --user
option while installing the Python package in our system.
The --user
option lets Python to install the package locally in the user’s home directory instead of the whole system.
To fix the error we have to use –user with the pip install command:
pip install --user <package-name>
# In Python 3
pip3 install --user <package-user>
# For windows
pip install --user <package-name>
With this command, the package will be installed in the directory which the current user has full access.
Solution 2: Using the sudo command while installing packages as Administrator
This solution does not require you to use the --user
option. The sudo
command lets the user install Python packages as administrator.
With the sudo
command you can install the Python package system-wide and will be available to every user in the system.
Example of how to use sudo
while installing python packages:
sudo pip install <package-name>
# In Python 3
sudo pip3 install <package-name>
sudo
is only available in Linux-based Operating Systems and Mac OS.
If you are using Windows then you cannot use sudo
command. To install any python package as administrator follow the steps below:
- Open Command Prompt as “Run as administrator“.
- In Command Prompt, run
pip install <package-name>
to install the package as an administrator.
Solution 3: Using a Virtual Environment
The last solution to this “permission denied” error is to use a Virtual Environment. A virtual Environment is an isolated Python environment that allows us to install and manage python packages separately without affecting the system-wide Python installation.
To create a virtual environment you can follow the steps below:
Step 1: Create the environment using:
python -m venv <venv-name>
Step 2: Activate the environment using the command:
source <venv-name>/bin/activate
Once the environment is created successfully, now we can install python packages using pip install
command without the --user
option.
Conclusion
Here, we have learned that the “check for permission” error occurs when we try to install a python package without having administrator permissions.
And the easiest and fast way to solve the error is to use the --user
option while installing the package.
The second solution ie. the sudo command should be used if the user wants to install the package system-wide.
And third solution is best when the first solution did not work and the user wants to install the package locally.