pip upgrade OSError: [Errno:13] Permission Denied - python

I need to upgrade pip on my Ubuntu system but I am getting error:
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 742, in install
**kwargs
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
ensure_dir(destdir)
File "/home/shivams334/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip-9.0.1.dist-info'
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Maybe I should go with 'chown' but don't know how to use it. Please help.

Since you want to upgrade your system-wide Python, you need to run this command with administrator privilege:
sudo pip install -U pip
But, I recommend you not changing/polluting your system-wide Python. Instead use a virtualenv:
virtualenv myapp
source myapp/bin/activate
pip install -U pip # <- only if virtualenv is not up to date

Related

When using pip of python 3, what does "can't combine user with prefix, exec_prefix/home, or install_(plat)base" mean? And How do I fix it?

When I run the following pip command:
pip3 install -r requirements.txt --upgrade --force-reinstall --ignore-installed --target target/classes/python
I got the following error:
Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 360, in run
prefix=options.prefix_path,
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/usr/lib/python3/dist-packages/pip/wheel.py", line 247, in move_wheel_files
prefix=prefix,
File "/usr/lib/python3/dist-packages/pip/locations.py", line 153, in distutils_scheme
i.finalize_options()
File "/usr/lib/python3.6/distutils/command/install.py", line 274, in finalize_options
raise DistutilsOptionError("can't combine user with prefix, "
distutils.errors.DistutilsOptionError: can't combine user with prefix, exec_prefix/home, or install_(plat)base
What does it mean?
I'm not even using any of the options among '--user', '--prefix', '--home' or '--install*', so where does the can't combine part come from?
Well, first: target By default will not replace existing files/folders in as per pip documentation https://pip.pypa.io/en/stable/reference/pip_install/, so you only need to use upgrade.
second: Combining many commands that are not necessarily be together is not quite preferable, the 3 commands that are necessary to be combined in this command are --upgrade --no-deps --force-reinstall as per this answer on how to force reinstall in pip Can I force pip to reinstall the current version?.
third: sometimes set up tools needs reinstallation
so I suggest the following commands
pip uninstall pip setuptools
pip install pip setuptools
pip3 install --upgrade --no-deps --force-reinstall <packagename>
pip3 install -r requirements.txt

Permission denied when installing Tensorflow with pip

When I try to install Tensorflow with pip install tensorflow, I get this 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 323, in clobber
shutil.copyfile(srcfile, destfile)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/protobuf-3.5.2-py2.7-nspkg.pth'
What does it mean? How can I install the tensorflow package?
When I use: sudo pip install tensorflow I now get this 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 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/n6/bfff99yn3nnc46h_gh5tc7fm0000gn/T/pip-TI9hQ_-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
Instead of saying denied it says Operation not permitted
Looks like your user doesn't have the permission to install packages in your system (for all users). Here's how to fix this problem for Linux, macOS and Windows:
Linux / macOS
From your terminal, you can install the package for your user only, like this:
pip install tensorflow --user
OR
You can use su or sudo from your terminal, to install the package as root:
sudo pip install tensorflow
Windows
From the Command Prompt, you can install the package for your user only, like this:
pip install tensorflow --user
OR
You can install the package as Administrator, by following these steps:
Run the Command Prompt as Administrator, using the Run This Program As An Administrator option.
Run the command pip install tensorflow
It clearly seems to be a problem of permissions.
If you are using Ubuntu or Liux OS, the try using:
sudo pip install tensorflow
If you are using Windows then:
Run the Command prompt as Administrator and the run pip install tensorflow
For better getting rid of such issues in future, Using Anaconda.
You should run this with
sudo pip
You need to install with administrator permissions. This can be done with sudo command.
I would suggest also specifying the Python interpreter as well as using pip, to stop the confusion of where pip should install to. By default there are two versions plus those you may have installed yourself.
To install on 2.7 you could use this:
sudo python -m pip install tensorflow
To install on 3.6 you could use this:
sudo python36 -m pip install tensorflow
For 3.5 you could use this:
sudo python3 -m pip install tensorflow
To tell what the version each Python is you can use which python

Cannot pip install watson-developer-cloud

OS: Windows 10 x64
I am trying to install watson-developer-cloud using the command
pip install --upgrade watson-developer-cloud
However, I get the following error
Exception:
Traceback (most recent call last):
File "C:\Users\AurangzebRathore\Anaconda2\lib\site-
packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\AurangzebRathore\Anaconda2\lib\site-
packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "C:\Users\AurangzebRathore\Anaconda2\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "C:\Users\AurangzebRathore\Anaconda2\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:\Users\AurangzebRathore\Anaconda2\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "C:\Users\AurangzebRathore\Anaconda2\lib\site-packages\pip\wheel.py",
line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "C:\Users\AurangzebRathore\Anaconda2\lib\site-packages\pip\wheel.py", line 323, in clobber
shutil.copyfile(srcfile, destfile)
File "C:\Users\AurangzebRathore\Anaconda2\lib\shutil.py", line 97, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied:
'C:\\Users\\AurangzebRathore\\Anaconda2\\Lib\\site-packages\\_cffi_backend.pyd'
I tried to use
$ easy_install --upgrade watson-developer-cloud
but when I run the code, it still says
ImportError: No module named watson_developer_cloud
Make sure you are running command as administrator.
Find the Command Prompt (cmd.exe)
Right click on "Command Prompt"
Run as Administrator
After it, use pip --version and see if are working. If not, you need to install again. If you installed Python from source, with an installer from python.org, or via Homebrew you should already have pip.
If pip isn’t already installed, then first try to bootstrap it from the standard library:
python -m ensurepip --default-pip
And try update your pip:
python -m pip install --upgrade
Install your Watson package:
pip install -I watson-developer-cloud==0.26.1
Obs.: This is the Official command in the API Reference, as you can see in this link.
See more about in this useful Installing Packages - Python.

Pip version virtualenv doesn't match and won't upgrade

Okay, so, I run my project packages in a virtual environment. I usually manage these packages through PyCharm. PyCharm tells me I have Pip 9.0.1 installed. Only when I run my virtual environment from the command line and I print pip version, it says 7.1.0. If I try upgrading using pip install --upgrade pip I get an error
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 7.1.0
Uninstalling pip-7.1.0:
Successfully uninstalled pip-7.1.0
Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\basecommand.py", line 223, in main
status = self.run(options, args)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\commands\install.py", line 299, in run
root=options.root_path,
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_set.py", line 646, in install
**kwargs
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_install.py", line 813, in install
self.move_wheel_files(self.source_dir, root=root)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\req\req_install.py", line 1008, in move_wheel_files
isolated=self.isolated,
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\wheel.py", line 449, in move_wheel_files
generated.extend(maker.make(spec))
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 323, in make
self._make_script(entry, filenames, options=options)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 227, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 163, in _write_script
launcher = self._get_launcher('t')
File "c:\python-virtualenv\arcus\lib\site-packages\pip-7.1.0-py3.5.egg\pip\_vendor\distlib\scripts.py", line 302, in _get_launcher
result = finder(distlib_package).find(name).bytes
AttributeError: 'NoneType' object has no attribute 'bytes'
My system-wide pip version is 9.0.1 though. I just don't get what is happening. Hopefully someone can shed some light. I've tried de-installing and re-installing it again, I've tried using a wheel to install, doesn't work
Windows, by the way.
I had the same issue, but found the answer here:
https://github.com/pypa/pip/issues/2669
Basicly I just had to use this command instead:
easy_install -U pip
Open the Command Prompt (cmd) as administrator and run:
pip install --user --upgrade pip
Or try:
python -m pip install --user --upgrade pip
Relevant GitHub issue.

Cannot upgrade Pip. Permission denied. Why?

I'm trying to upgrade pip on my iMac, but I keep getting a permission denied error. I'm the admin, so I don't know what I've done wrong.
iMac:~ me$ pip install --upgrade pip
You are using pip version 6.0.8, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.1.2-py2.py3-none-any.whl#md5=5ff9fec0be479e4e36df467556deed4d
Downloading pip-7.1.2-py2.py3-none-any.whl (1.1MB)
100% |################################| 1.1MB 181kB/s
Installing collected packages: pip
Found existing installation: pip 6.0.8
Uninstalling pip-6.0.8:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 347, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_set.py", line 543, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 667, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_uninstall.py", line 126, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/pip/utils/__init__.py", line 316, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 300, in move
rmtree(src)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 247, in rmtree
rmtree(fullname, ignore_errors, onerror)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 252, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 250, in rmtree
os.remove(fullname)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg/EGG-INFO/dependency_links.txt'
I don't know what I've done wrong here as an upgrade seem fairly straightforward.
Thanks,
pip installations require elevation
sudo pip install --upgrade pip
Just because you are currently using an admin account doesn't mean the command will run with elevation, unless you specify sudo
You have to use sudo since you are upgrading pip "globally". I prefer to install Homebrew and let Homebrew manage everything.
Install Xcode from the App Store
Install Homebrew - ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install Python - brew install python, which also installs pip.
With this setup, everything is installed locally, which doesn't require you to run sudo.
I hope this helps.
You can do one of two ways:
chown -R user /path/to/file a more detailed information can be found in this SO post, while it doesn't relate to the exact problem it deals with the same issue
Quick and dirty way just do pip install --upgrade pip as already mentioned. However, many users will suggest against that.

Categories

Resources