问题
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?
回答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/
回答2:
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
来源:https://stackoverflow.com/questions/51833041/python-virtual-environment-package-install-issue