Could not install packages due to an EnvironmentError: [Errno 13]
If you want to use python3+ to install the packages you need to use pip3 install package_name
And to solve the errno 13 you have to add --user
at the end
pip3 install package_name --user
EDIT:
For any project in python it's highly recommended to work on a Virtual enviroment, is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.
In order to create one with python3+ you have to use the following command:
virtualenv enviroment_name -p python3
And then you work on it just by activating it:source enviroment_name/bin/activate
Once the virtual environment is activated, the name of your virtual environment will appear on left side of terminal. This will let you know that the virtual environment is currently active.Now you can install dependencies related to the project in this virtual environment by just using
pip
.pip install package_name
Permission denied with pip install --user -e /home/me/package/
It's a bug. The issue is being tracked at https://github.com/pypa/pip/issues/7953 .
The workaround for now is to modify your setup.py()
to contain this:
import site
import sys
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]
Or to use something like this on the command line, if you use setup.cfg or pyproject.toml:$ python3 -c 'import setuptools, site, sys; site.ENABLE_USER_SITE = 1; sys.argv[1:] = ["develop", "--user"]; setuptools.setup()'
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/var/project_env/bin/pip'
Don't create your virtual environment (venv) in /var
.
My advice:
- Create your virtual environment alongside your source code, if you're using
pip
- If you're using
pipenv
, let pipenv choose where to create the venv
requirements.txt
(or a Pipfile) to specify which packages and versions are needed. Why is permission denied on pip install except for when --user is included at end of command?
With a virtual environment activated,
pip install spam
tries to install into the virtual environment's site-packages. This will almost always be somewhere you have write permissions for.pip install --user spam
tries to install into the user-packages directory. This will always be somewhere under your home directory, so you should always have write permissions for it.pip install spam
tries to install files into the site-packages directory for your Python installation. This will usually not be in your home directory (typically it's somewhere in/Library
), so you may or may not have write permissions.- Apple's pre-installed Python does not give you write permissions to its site-packages.
sudo pip install spam
will let you ignore the permissions by installing as root, although with some Python installations it may cause other problems.
- Homebrew, Python.org, and Anaconda/Miniconda do give you write permissions to their site-packages if you leave the defaults alone.
- Obviously, leave the defaults alone if you know what you're doing.
- Less common ways of installing (Enthought, building from source, MacPorts, etc.), you should read the appropriate docs.
- Apple's pre-installed Python does not give you write permissions to its site-packages.
pip install spam
works, but you're using Apple's pre-installed Python on the ones where it doesn't.While you could fix that by using sudo
, you probably don't want to, for a few reasons:
- On recent versions of macOS, Apple's pre-installed Python, and the packages they pre-install with it, are badly out of date.
- The pre-installed packages are set up to be maintained with the deprecated
easy_install
rather thanpip
, so getting them up to date can be a huge pain. - If you mess things up too badly, you can break some system scripts that the OS depends on.
- Your changes can be undone by a macOS system update.
--user
whenever possible when you can't. Any one of these three will solve your problem, but you really should do all of them.And then, if you accidentally try to install something to Apple's site-packages, you'll get a permissions error—but that's a good thing; it means you didn't actually change anything, so you have nothing to undo.
pip install failing with: OSError: [Errno 13] Permission denied on directory
Option a) Create a virtualenv, activate it and install:
virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt
Option b) Install in your homedir:
pip install --user -r requirements.txt
My recommendation use safe (a) option, so that requirements of this project do not interfere with other projects requirements. Module not found error in Python after pip install package --user
You're probably attempting to download package to a system folder where you don't have permission to write or modified, maybe it's due to modification on your pip.ini
file which specify by default the packages location ?
Check pip documentation and his topic about configuration here.
Furhtermore, I advise you, if you start learning python and using pip package, to learn fundamental about the principle of virtualenv using venv lib here. VirtualEnv is a recommended practice in python who allow you to compartmentalize project in a specified place with a personal pip package directory and other things, these methods aim to avoid dependancy concurrence between projects and also avoid pip package permissions issue by downloading pip package only for your virutalenv.
- Step by step to setup venv ( you should be in the root folder of your
projet) :
user@hostname > python3 -m venv venv
user@hostname > source ./env/bin/activate
(venv) user@hostname > python -m pip install foo-packages
- Or the second option but not recommended is to use sudo to
install packages to the system folder :
sudo@hostname > sudo python -m pip install foo-packages
Related Topics
Difference Between Two Lists with Duplicates in Python
Running Multiple Bash Commands with Subprocess
Should All Python Classes Extend Object
Safely Create a File If and Only If It Does Not Exist with Python
Python Using Variables from Another File
What Could Cause a Python Module to Be Imported Twice
Recursive List Comprehension in Python
Using Python Requests: Sessions, Cookies, and Post
How to Implement SQL Coalesce in Pandas
Python Decompression Relative Performance
Import Text to Pandas with Multiple Delimiters
How to Fix Selenium Webdriverexception: the Browser Appears to Have Exited Before We Could Connect
Create Spark Dataframe. Can Not Infer Schema for Type
SQL Alchemy Orm Returning a Single Column, How to Avoid Common Post Processing
Source Interface with Python and Urllib2
How to Get Windows' Special Folders for Currently Logged-In User