带有站点包的 Python 3 virtualenv 不会引导 pip [英] Python 3 virtualenv with site packages does not bootstrap pip

查看:30
本文介绍了带有站点包的 Python 3 virtualenv 不会引导 pip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 的 3.5 内置 virrtualenv 包创建一个新的 Python 虚拟环境:

I'm creating a new Python virtual environment with Python's 3.5 built-in virrtualenv package:

D:\Projects>python -m venv --system-site-packages proj_3

D:\Projects>cd proj_3

D:\Projects\proj_3>Scripts\activate.bat

(proj_3) D:\Projects\proj_3>pip install comtypes
Collecting comtypes
  Downloading comtypes-1.1.2.zip (179kB)
    100% |################################| 184kB 569kB/s
Installing collected packages: comtypes
  Running setup.py install for comtypes ... done
Successfully installed comtypes-1.1.2

(proj_3) D:\Projects\proj_3>dir Lib\site-packages
 Volume in drive D has no label.
 Volume Serial Number is 0E52-CE22

 Directory of D:\Projects\proj_3\Lib\site-packages

20.05.2016  14:15    <DIR>          .
20.05.2016  14:15    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  268,620,853,248 bytes free

所以我想重用现有的系统包并在我创建的 virtualenv 中安装新包.但是相反,尽管我在 virtualenv 中,pip 将软件包安装在我的系统库中,而不是在本地项目中.

So I want to reuse existing system packages and install new package in my created virtualenv. But instead, although I'm in virtualenv, pip installed the package in my system libraries instead in local project.

(proj_3) D:\Projects\proj_3>where pip
C:\Python35\Scripts\pip.exe

(proj_3) D:\Projects\proj_3>python -m ensurepip
Ignoring indexes: https://pypi.python.org/simple
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\python35\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in c:\python35\lib\site-packages

看起来 pip 没有在我的本地包中引导,因为它已经存在于我的系统包中.除非我做错了什么,否则这是出乎意料的,因为在 Python 2 中使用 virtualenv 不会像这样.

It looks like pip is not bootstraped in my local package because it already exists in my system packages. Unless I did something wrong, this is unexpected as using virtualenv with Python 2 does not behave like this.

有什么想法可能出问题了吗?

Any ideas what might be wrong?

推荐答案

这里已经报告了一个错误:https://bugs.python.org/issue24875

It is a bug already reported here: https://bugs.python.org/issue24875

在修复之前,请尝试此解决方法.

Before it is fixed, try this workaround.

首先,创建没有 --system-site-packages 的虚拟环境.然后修改创建的环境.

First, create the virtual environment without --system-site-packages. Then modify the created environment.

pyvenv /path/to/env && pyvenv --system-site-packages /path/to/env

这篇关于带有站点包的 Python 3 virtualenv 不会引导 pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆