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

时间:2015-08-17 11:10:31

标签: python virtualenv

我在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)我试过搜索过但其他答案似乎适用于mac(例如偶然通过sudo安装)。当我做pip2列表时,该模块存在,所以我不明白为什么我无法访问它。

(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>

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

EDIT 在交互式shell上运行sys.path的结果

['', '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']

运行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

2 个答案:

答案 0 :(得分:2)

Windows Python启动程序PEP 397不知道活动的虚拟环境。有关详细信息,请参阅PEP 486

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

答案 1 :(得分:1)

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

但您可以通过使用

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

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