60

I am using ubuntu 12.04 and I am trying to pip install virtualenv but suddenly I got this error.

samuel@sampc:~$ pip install virtualenv
Downloading/unpacking virtualenv
  Running setup.py egg_info for package virtualenv

    warning: no previously-included files matching '*' found under directory 'docs/_templates'
    warning: no previously-included files matching '*' found under directory 'docs/_build'
Installing collected packages: virtualenv
  Running setup.py install for virtualenv
    error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/samuel/build/virtualenv/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-Z2v_fR-record/install-record.txt:
    running install

running build

running build_py

running install_lib

creating /usr/local/lib/python2.7/dist-packages/virtualenv_support

error: could not create '/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/samuel/build/virtualenv/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-Z2v_fR-record/install-record.txt failed with error code 1
Storing complete log in /home/samuel/.pip/pip.log

Does anyone have an idea about my case?

gadss
  • 21,687
  • 41
  • 104
  • 154
  • I just had a similar problem because of wrong permissions for my home folder (some things were not owned by me). While sudo pip install would work, it is be better to fix the permissions instead. – Velizar Hristov Sep 28 '15 at 11:11
  • 2
    @VelizarHristov *'/usr/local/lib/python2.7/dist-packages/virtualenv_support': Permission denied* clearly states the path and this path has nothing to do with any home folder so no, your problem is not similar to this one in spite of the same type of error in both cases. – Piotr Dobrogost Jul 20 '16 at 10:52
  • I had similar problem when I try to intall numpy in Python3. Then 'sudo pip3 install numpy' worked. – phenomenon Sep 25 '17 at 04:17

9 Answers9

114

I've heard that using sudo with pip is unsafe.

Try adding --user to the end of your command, as mentioned here.

pip install packageName --user

I suspect that installing with this method means the packages are not available to other users.

Community
  • 1
  • 1
falsePockets
  • 3,826
  • 4
  • 18
  • 37
55

You don't have permission to the Python folder.

sudo chown -R $USER /usr/local/lib/python2.7
user732456
  • 2,638
  • 2
  • 35
  • 49
16

Use

sudo pip install virtualenv

Apparently you will have powers of administrator when adding "sudo" before the line... just don't forget your password.

José Tomás Tocino
  • 9,873
  • 5
  • 44
  • 78
Alali Ruslan
  • 224
  • 2
  • 5
3

use

sudo pip install virtualenv

You have a permission denied error. This states your current user does not have the root permissions.So run the command as a super user.

arpiagar
  • 4,314
  • 1
  • 19
  • 12
2

In the case of permission denied error, you just need to go with this command.

sudo pip install virtualenv

sudo before the command will throw away the current user permissions error.

Note: For security risks, You should read piotr comment.

Awais
  • 1,803
  • 22
  • 26
2

It's because the virtual environment viarable has not been installed.

Try this:

sudo pip install virtualenv
virtualenv --python python3 env
source env/bin/activate
pip install <Package>

or

sudo pip3 install virtualenv
virtualenv --python python3 env
source env/bin/activate
pip3 install <Package>
User42
  • 970
  • 1
  • 16
  • 27
2

pip is not give permission so can't do pip install.Try below command.

apt-get install python-virtualenv
Beyhan Gul
  • 1,191
  • 1
  • 15
  • 25
2

First, sudo pip install 'package-name' means nothing it will return

sudo: pip: command not found

You get the Permission denied, you shouldn't use pip install as root anyway. You can just install the packages into your own user like mentionned above with

pip install 'package-name' --user

and it will work as you intend. If you need it in any other user just run the same command and you'll be good to go.

Seraf
  • 850
  • 1
  • 17
  • 34
0

you have to change permission on the mentioned path.

gabi
  • 1,324
  • 4
  • 22
  • 47
  • Not a good idea to change permission giving access to a user you should consider to install it globally – c24b Feb 07 '16 at 14:16