I'm trying to install django using pip in Terminal.
I always get an exception, however. The last error is always "permission denied", and I do not understand why. Any help is appreciated.
Log:
pip install django
You are using pip version 7.1.0, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django
Using cached Django-1.9.4-py2.py3-none-any.whl
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 299, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 646, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 813, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 1008, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 339, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 310, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 70, 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'
sudo pip install django
The error tells you that you can't access a directory (you don't have enough permissions), so you can gain root access via sudo to get the permissions.
pip should be run by a user which has permissions to write to site-packages directory (in your case, /Library/Python/2.7/site-packages/). You should either run it from the root user or under sudo.
My Solution for [Errno 13] Permission denied:
Target: To install package into system/virtualenv
Why you get this problem?
Because apart from root, other users you created don't have permission to write to site-packages, that is why you get OS error permission denied for that user
How to solve?
Make sure you activated the virtualenv all the time
Source bin/activate
Suppose, I created a user
(sampleEnv) sunny#ubuntu-512mb-lon1-01: pip install django
This will give the Permission error, Instead of that shift to root
$ su -
(sampleEnv) root#ubuntu-512mb-lon1-01: pip install django
Now root have permission to write to site-packages.
Once django is installed. Shift back to user
$ su - sunny
then do pip freeze you can see packages installed in system and go on!
Related
I have seen other threads that suggest using virtual environments, running as sudo, or installing for the specific user. None of these have solved my issue. I still get the same error.
Fedora36
Python 3.10
(base) pip install PySimpleGUI
Collecting PySimpleGUI
Using cached PySimpleGUI-4.60.4-py3-none-any.whl (509 kB)
Installing collected packages: PySimpleGUI
Successfully installed PySimpleGUI-4.60.4
ERROR: Exception:
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
status = run_func(*args)
File "/usr/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
return func(self, options, args)
File "/usr/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 463, in run
self._handle_target_dir(
File "/usr/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 473, in _handle_target_dir
ensure_dir(target_dir)
File "/usr/lib/python3.10/site-packages/pip/_internal/utils/misc.py", line 104, in ensure_dir
os.makedirs(path)
File "/usr/lib64/python3.10/os.py", line 215, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/usr/lib64/python3.10/os.py", line 215, in makedirs
makedirs(head, exist_ok=exist_ok)
File "/usr/lib64/python3.10/os.py", line 215, in makedirs
makedirs(head, exist_ok=exist_ok)
[Previous line repeated 3 more times]
File "/usr/lib64/python3.10/os.py", line 225, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/Users'
(base)
I have tried:
sudo pip install PySimpleGUI
Requirement already satisfied: PySimpleGUI in /usr/local/lib/python3.10/site-packages (4.60.4)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
This works kind of but creates the obvious issue of installing as sudo. Also it seems very possible that I will create system issues.
(base) pip install --user PySimpleGUI
ERROR: Can not combine '--user' and '--target'
(base) pip install PySimpleGUI --user
ERROR: Can not combine '--user' and '--target'
(base)
I believe that the issue is a path issue. Everything was kind of working but pip installed into my anaconda python bin instead of general bin. VSCode was not able to import the packages, even when selecting the anaconda python as my interpreter.
Currently, this is my which pip output.
(base) which pip
/usr/bin/pip
I have tried figuring out whats going on in my .bashrc but I admittedly am not familiar with everything in there and do not want to screw anything up. I don't know if I am to meddle about within .bashrc or .bash_profile
I'd like to be able to use pip to install packages without sudo, user, or virtual env. It is like that on my windows partition and on my mac. I am not opposed to removing python and all associated packages.
Thanks.
I tried to install the python library openpyxl using pip by typing into the terminal:
pip install openpyxl
But it was not executed properly. It threw an exception:
Successfully built openpyxl jdcal et-xmlfile
Installing collected packages: jdcal, et-xmlfile, openpyxl
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 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/jdcal.py'
Best way is probably to use pip install <libname> --user
Meaning in your case use pip install openpyxel --user
This installs the package for your user and that is safe. Also you have probably the right of installing the package for the user.
The permission error you have encountered is a frequent problem. As can be seen here:
pip is not able to install packages correctly: Permission denied error
and here error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied
Using the sudo pip command is not considered as safe as explained here: What are the risks of running 'sudo pip'?
Your user doesn't have write permissions in the Python installation folder.
To fix it, run pip as root:
sudo pip install openpyxl
Your account does not have write access to this directory?.
If the installation directory is a system-owned directory, you may
need to sign in as the administrator or "root" account.
sudo pip install openpyxl
If you do not have administrative access to this machine, you may
wish to choose a different installation directory, preferably one
that is listed in your PYTHON_PATH environment variable.
easier way: change that dir permission:
chmod +a 'user:YOUR_USER_NAME allow add_subdirectory,add_file,delete_child,directory_inherit' /Library/Python/2.7/site-packages
Change security setting of site-packages folder to "Full Control" for your user and re run pip install openpyxl
I am trying to upgrading pip from 8.1.1 to 8.1.2 .
But it showing following 'PermissionError: [WinError 5] Access is denied:
How to upgrade pip?
C:\>python -m pip install --upgrade pip
Collecting pip
Using cached pip-8.1.2-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Exception:
Traceback (most recent call last):
File "C:\Program Files\Python35\lib\shutil.py", line 538, in move
os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'c:\\program files\\python35\\lib\\site-packages\\pip-8.1.1.dist-info\\description.rst' -> 'C:\\Users\\user\\AppD
ata\\Local\\Temp\\pip-nen4ldwg-uninstall\\program files\\python35\\lib\\site-packages\\pip-8.1.1.dist-info\\description.rst'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python35\lib\site-packages\pip\basecommand.py", line 209, in main
status = self.run(options, args)
File "C:\Program Files\Python35\lib\site-packages\pip\commands\install.py", line 317, in run
prefix=options.prefix_path,
File "C:\Program Files\Python35\lib\site-packages\pip\req\req_set.py", line 726, in install
requirement.uninstall(auto_confirm=True)
File "C:\Program Files\Python35\lib\site-packages\pip\req\req_install.py", line 746, in uninstall
paths_to_remove.remove(auto_confirm)
File "C:\Program Files\Python35\lib\site-packages\pip\req\req_uninstall.py", line 115, in remove
renames(path, new_path)
File "C:\Program Files\Python35\lib\site-packages\pip\utils\__init__.py", line 267, in renames
shutil.move(old, new)
File "C:\Program Files\Python35\lib\shutil.py", line 553, in move
os.unlink(src)
PermissionError: [WinError 5] Access is denied: 'c:\\program files\\python35\\lib\\site-packages\\pip-8.1.1.dist-info\\description.rst'
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
This problem occurs even with administrator privileges.
open your cmd with admin priviliges. for that right click in icon and select open with administrator.
Upgrade PIP on your default python environment required sudo, i.e. in Windows term, you must your start command prompt as administrator mode. In fact, this is not recommended.
You don't need to use sudo/'Windows adminsitrators" if you setup virtualenv. It is python best practice to setup Python virtualenv , So you can separate the pip package required for individual project. For windows, it is similar setup.
Nevertheless, if you have decent PC with enough RAM, just install Virtualbox and deploy ubuntu. This way, your don't need to deal with windows python package installation/upgrade that overlook by developer (although all python package suppose to work out of the box) .
I am a student and I am doing project on department computer, system Linux 7.2. Now I am trying to install pip so that I can install python packages using it.
I have downloaded get-pip.py and tried to install via python get-pip.py. It gives me:
Collecting pip
Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
100% |████████████████████████████████| 1.2MB 471kB/s
Collecting wheel
Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
100% |████████████████████████████████| 71kB 764kB/s
Installing collected packages: pip, wheel
Exception:
Traceback (most recent call last):
File "/tmp/tmpqybTwL/pip.zip/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/tmp/tmpqybTwL/pip.zip/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/tmp/tmpqybTwL/pip.zip/pip/req/req_set.py", line 732, in install
**kwargs
File "/tmp/tmpqybTwL/pip.zip/pip/req/req_install.py", line 835, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/tmp/tmpqybTwL/pip.zip/pip/req/req_install.py", line 1030, in move_wheel_files
isolated=self.isolated,
File "/tmp/tmpqybTwL/pip.zip/pip/wheel.py", line 344, in move_wheel_files
clobber(source, lib_dir, True)
File "/tmp/tmpqybTwL/pip.zip/pip/wheel.py", line 315, in clobber
ensure_dir(destdir)
File "/tmp/tmpqybTwL/pip.zip/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib64/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/site-packages/pip'
Then, I tried to install using sudo python get-pip.py, however, I got "xxx is not in the sudoers file. This incident will be reported."
So, I was wondering whether I don't have the permission to root and don't have the right to do sudo...but I am not sure about this...
Any suggestion to fix this problem? And in the end, I want to install scipy and gensim.
Does the system hand you a virtualenv command?
Then you should read about virtualenvs. Comes in handy anyhow.
If not you may use the approach by Jasper van den Bosch
You either need to use a virtual environement, and install the pip package in the virtual env. Or install it with pip globally ie system wide as root user
Try install pip using easy_install
Try Below commands in terminal:
sudo su
easy_install pip
I have been trying to set up virtualenv for use with django, but I keep having issues installing virtualenv with pip.
jeff#jeff-HP-MacBook-Android:~/repos$ pip install virtualenv
Collecting virtualenv
Using cached virtualenv-13.1.2-py2.py3-none-any.whl
Installing collected packages: virtualenv
Exception:
Traceback (most recent call last):
File "/home/jeff/.local/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/home/jeff/.local/lib/python2.7/site-packages/pip/commands/install.py", line 311, in run
root=options.root_path,
File "/home/jeff/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 646, in install
**kwargs
File "/home/jeff/.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 "/home/jeff/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "/home/jeff/.local/lib/python2.7/site-packages/pip/wheel.py", line 339, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/jeff/.local/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
shutil.copyfile(srcfile, destfile)
File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/virtualenv.py'
jeff#jeff-HP-MacBook-Android:~/repos$
The closest answer I can find regards permissions inside the virtualenv: How to avoid "Permission denied" when using pip with virtualenv
But from what I can tell my issue is that there's something wrong with my install of pip, since I apparently don't even have virtualenv yet.
I don't think there's anything wrong with your pip installation. virtualenv is itself a Python module, and by default it goes in /usr/local/lib/python2.7/dist-packages, a folder for which your user does not have write permissions. If you have sudo access, it would be easiest to simply try:
sudo pip install virtualenv
Once you've done that, you should be able to create virtualenvs without needing to use sudo. Alternately, there are instructions here for making your own virtual environment, but it looks like you will likely need to do some manual editing of the script it directs you to download.