Python virtual environment package install issue

旧时模样 提交于 2019-12-12 21:12:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!