在 windows 上找不到通过 virtualenv 安装的模块

Can't find modules installed via virtualenv on windows

我在 Windows 7 上使用 运行 virtualenv,我为 python 2.7 创建了一个虚拟环境并安装了一些模块,但我似乎无法导入它。

1) venv\scripts\activate

2) pip2 安装请求

(I the following message: get Requirement already satisfied (use --upgrade to upgrade): requests in c:\users\dan\desktop\python\bulkphotos\venv\lib\site-packages)

3) 当我尝试在交互式 shell 上导入它时,出现以下错误

(venv) C:\Users\Dan\Desktop\Python\bulkphotos>py
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named requests

4) 我试过搜索 SO 但其他答案似乎适用于 mac(例如通过 sudo 意外安装)。当我做pip2 list的时候,模块是存在的,所以我不明白为什么我不能访问它。

(venv) C:\Users\Dan\Desktop\Python\bulkphotos>pip2 list
google-api-python-client (1.4.1)
httplib2 (0.9.1)
oauth2client (1.4.12)
pip (7.1.0)
pyasn1 (0.1.8)
pyasn1-modules (0.0.7)
requests (2.7.0)
rsa (3.2)
setuptools (18.0.1)
simplejson (3.8.0)
six (1.9.0)
uritemplate (0.6)
wheel (0.24.0)

(venv) C:\Users\Dan\Desktop\Python\bulkphotos>pip2 show requests
---
Metadata-Version: 2.0
Name: requests
Version: 2.7.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.com
License: Apache 2.0
Location: c:\users\dan\desktop\python\bulkphotos\venv\lib\site-packages
Requires:

(venv) C:\Users\Dan\Desktop\Python\bulkphotos>

有谁知道如何解决这个问题?

编辑 结果 运行 sys.path 互动 shell

['', 'C:\windows\system32\python27.zip', 'C:\Python27\DLLs', 'C:\Python27\lib', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\lib-tk', 'C:\Python27', 'C:\Python27\lib\site-packages']

运行 where py 和 where python

的结果
(venv) C:\Users\Dan\Desktop\Python\bulkphotos>where py
C:\Windows\py.exe

(venv) C:\Users\Dan\Desktop\Python\bulkphotos>where python
C:\Users\Dan\Desktop\Python\bulkphotos\venv\Scripts\python.exe
C:\Python27\python.exe
C:\Python34\python.exe

我不知道为什么没有导入这些包,

但是你可以通过使用

查看你的 pythonpath 来调试它
python -c "import sys; print sys.path"

您可以将可选路径附加到 sys.path

Windows Python 启动器 PEP 397 is not aware of the active virtual env. See PEP 486 了解详情。

尝试通过执行 python 而不是 py 来启动 Python 解释器。