pip errors regarding permission, can this be fixed? - python

I am trying to use pip, and every time I run a command to install or upgrade, I see this type of error (OSError).
I don't like having to sudo just to install packages, is this required?
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/docutils'

You're trying to modify a location shared amongst all users. You can't do that without sudo-ing, for good reason (otherwise, people could replace, say, python, with a program that deletes all your user data, or copies it to their home folder for perusal, etc.).
If you want to only make the changes for yourself, not others, you can pass pip the --user argument to install to ~/.local such that the new package is installed only for you, not other users.
Virtual environments are another option, but that's overkill to an extent (an active virtual environment isolates you completely from even the system site-packages directory, so you must individually install all packages again if they're needed).

Linux and Mac OS come with their own packaged python interpreter, and it is not advisable to use them for your development purpose. Start using virtualenv, a tool to create isolated Python environments in which you can install any packages, test installation of your own libraries and much more without affecting the systemwide installed python environment. Check out their site for tutorials on how to install, create and run scripts in a virtualenv.

Related

Why can't I install django

whenever I go to the command prompt and typepip install Django==2.0.3 I receive this in red text.
Exception:
Traceback (most recent call last):
File "c:\program files (x86)\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\wheel.py", line 316, in clobber
ensure_dir(destdir)
File "c:\program files (x86)\python36-32\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "c:\program files (x86)\python36-32\lib\os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'c:\\program files (x86)\\python36-32\\Lib\\site-packages\\pytz'
It also tells me that my pip installer is out of date, but whenever I try to update it I just receive the same error message.
You have a PermissionError on your installation. If Linux user, usually use "sudo" to fix this problem.
And as I see, you use Windows to install Django. So if you are Windows user, you must use "runas".
So, the best way to install Django on your Windows is :
runas pip install Django==2.0.3
Just try it. Hope that can solve your problem...
Try pip3 install django==2.0.3.
You are installing package for Python 3.x , so I guess that could be an issue
By default, common users have listing, reading and executing permissions in Program Files folders and other operations will be blocked by User Access Control(UAC). It is better to install python in your user directory or other partitions rather than system partition.
To solve your problem quickly, you can use "run as administrator" to start cmd, then run pip command again.
As it seems you're on Windows, try to open command-line as Administrator (Easiest way: Searching on Cortana, right click and open as administrator).

How to fix ".dist-info directory not found" in my package?

I have a Python 2 package that I'm trying to upgrade to Python 3. It was written by someone who used to work on the same team I'm on now but who is no longer with the company, and unfortunately nobody left on the team is able to help out.
After running 2to3 on the files of the package, I ran python setup.py sdist to create a package, placed the package in a local repository, then attempted to use pip install to install the package. It ended up erroring out with the following:
Exception:
Traceback (most recent call last):
File "/home/user/project/lib/python3.5/site-packages/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/home/user/project/lib/python3.5/site-packages/pip/commands/install.py", line 297, in run
root=options.root_path,
File "/home/user/project/lib/python3.5/site-packages/pip/req/req_set.py", line 622, in install
**kwargs
File "/home/user/project/lib/python3.5/site-packages/pip/req/req_install.py", line 808, in install
self.move_wheel_files(self.source_dir, root=root)
File "/home/user/project/lib/python3.5/site-packages/pip/req/req_install.py", line 1003, in move_wheel_files
isolated=self.isolated,
File "/home/user/project/lib/python3.5/site-packages/pip/wheel.py", line 340, in move_wheel_files
assert info_dir, "%s .dist-info directory not found" % req
AssertionError: my-package-name .dist-info directory not found
The old Python 2 version of the package didn't have anything called .dist-info in the .tgz archive, and it installed just fine. Does anyone know what's going on here and how to fix it?
In my case this was resolved by deleting AppData\Local\pip\Cache folder (windows). Should be fairly similar for other operating systems.

Installing Pandas on MacOs. Permission Error

I am trying to pip install pandas on a mac. I have python 3.6 installed.
When I pip install in the terminal I get the following error:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pandas'
Could you possibly edit the error into a formatted code block by highlighting it and pushing ctrl+k so it is easier to read? Thanks.
Edit: Also, I just looked through and at the bottom it says permission denied. Try rerunning the command as an admin. I.E try this command:
sudo pip install pandas
You might have already noticed, Mac come with a built in Python, python 2.7. If you read your traceback: /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py it's pointing to the 2.7 dir. this dir is in the Library folder so you don't have permission to install to it.
But you state that you have Python 3.6 installed as well, so if you wanted to install to that indtead. Do pip3 install pandas or python3 -m pip install pandas this help specify the python version. And if you want to run python 3.6 in terminal, type python3 instead of just python

pip freeze is giving me the global packages

I'm fairly new to python so please bear with me. I installed the virtual env created a new environment and everything very smooth(great). so when I try to pip freeze it gives me all the global packages that are installed and not only the environment im in. Then I try to install django and it does not let me. This is the error that gives me...
→ pip install django
Collecting django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)
100% |████████████████████████████████| 6.6MB 187kB/s
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_set.py", line 732, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 835, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 1030, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/wheel.py", line 344, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/wheel.py", line 315, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'
OK. I got it working. The problem was something with a cache directory. When I reinstalled virtualenv I used a flag plus sudo.
sudo pip install --no-cache-dir virtualenv
but new questions comes up.
How important is a cache directory for the environments?
Do I need one yes o no?
Thanks all for your awesome help.

Cannot pip install anything with OS X El Capitan

I am trying to pip install virtualenv (and anything else) on OS X El Capitan and got the following error:
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 311, in run
root=options.root_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 646, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 339, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 282, in clobber
ensure_dir(dest) # common for the 'include' path
File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 71, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 1] Operation not permitted: '/usr/lib/python2.7/site-packages'
Looks pip is trying to write in '/usr/lib/python2.7/site-packages' and due to SIP in El Capitan it got denied.
But I was wondering why does pip needs to write there? How can I fix this?
I ran brew doctor
which gives
Your system is ready to brew.
So I think it is OK.
I tried brew reinstall python and it gives an odd error:
==> Reinstalling python
Error: /usr/local/opt/python is not a valid keg
which python gives
/usr/local/bin/python
So where in system has this weird thing that let pip fail
Update:
It looks my pip is pointing to system python rather than brewed python.
I changed the first line of pip to
#!/usr/local/bin/python
and problem is solved
You may need to brew link python, or unlink then link to get things pointing to the correct places.

Categories

Resources