2

I'm building a Python project requiring Django. I have created a project directory and virtual environment using virtualenv. But I can't install django using PIP and I have to use easy_install in order to install it into the virtual environment.

Note - I only have this problem with Django. I am able to successfully install other packages into the virtual environment using PIP without issues.

I'm running the following sequence...

cd projectfolder
virtualenv venv
venv\Scripts\activate
pip install django

And I get the following error message:

Could not install packages due to an EnvironmentError: [WinError 5] Access 
is denied: 'C:\\Users\\xxxx\\AppData\\Local\\Temp\\pip-unpack- 
kc0_p8wh\\Django-2.1-py3-none-any.whl'
Consider using the `--user` option or check the permissions.

Again - if I run the same block of code, but end it with:

easy_install django

Then the package installs fine.

Any thoughts?

George Rodman
  • 289
  • 7
  • 19
  • For whatever reason running the `pip.cmd` (i.e. `pip`) on Windows results in a lower privilege as per [this question](https://stackoverflow.com/questions/31172719/pip-install-access-denied-on-windows), so the workaround is to use `python -m pip` instead (i.e. try `python -m pip install django`). – metatoaster Aug 14 '18 at 02:54
  • Thanks. But this still doesn't work. I get the same error message listed below. And it's only for this 1 package (Django). I'm able to install other packages without issue. But for some reason, it only brings this error up when install Django. Any thoughts? – George Rodman Aug 14 '18 at 03:21
  • Just a followup: looks pretty similar to [this question that has no answer](https://stackoverflow.com/questions/36517742/django-wont-install-on-windows-using-pip). Might be a bug with the wheel provided by django when interacted through Windows. – metatoaster Aug 14 '18 at 03:32
  • It looks as if PIP unpacks to the temp directory - and for whatever reason - can't find the package in the temporary once it unpacks it. I'm totally clueless as to what this could mean. – George Rodman Aug 14 '18 at 03:35

2 Answers2

1

In most situations the best solution is to rely on the so-called "user site" location by running:

pip install --user package_name

If that doesn't work, you need the admin rights. So just run the cmd as an administrator.

Or better yet create a virtualenv and then install. Instructions can be found on: https://virtualenv.pypa.io/en/stable/installation/

Rahul Purohit
  • 540
  • 4
  • 16
  • 1
    I have admin rights and am still getting this error, whether I'm in the virtual environment or not. And it's ONLY with this package (Django). I don't have any issues installing any other packages in or out of the virtualenv. Only Django causes problems. Any thoughts? – George Rodman Aug 14 '18 at 03:22
0

You didn't actually active your virtual-env, and your error information show as:

C:\Users\xxxx\AppData\Local\Temp\pip-unpack- kc0_p8wh\Django-2.1-py3-none-any.whl

Nothing about venv/xxx/path, so you should active by.

FOR Linux

source venv\Scripts\activate first. and then try install again.

FOR WIN Thanks for @metatoaster remind at the comments below. But it depends on where are you virtualenv path.

C:\Venv\Scripts>activate

To make sure whether you are in virtual-env , just check whether you have a special subfix at the begin of command line. something like:

(my_venv)landpacks
Frank AK
  • 1,705
  • 15
  • 28
  • `source` is part of `bash`, not `cmd` on Windows. – metatoaster Aug 14 '18 at 02:54
  • 1
    Thanks, but this still didn't work. For some reason, the only package that gives me a problem is Django (both inside and outside of the virtualenv). I can install any other package fine, but this is the only one that causes problems. – George Rodman Aug 14 '18 at 03:23
  • And I can still install Django using easy_install. Just not PIP. Any thoughts? – George Rodman Aug 14 '18 at 03:24
  • Seems your `pip` has no privilege to do this operations. and can you switch to super user (something like linux root user). – Frank AK Aug 14 '18 at 03:25