Dan Tang
Dan Tang

Reputation: 1343

Can't find modules installed via virtualenv on windows

I'm running virtualenv on Windows 7 and I created a virtual environment for python 2.7 and installed some modules but I can't seem to import it.

1) venv\scripts\activate

2) pip2 install requests

(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) when I try to import this on the interactive shell, I get the following error

(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) I've tried searching SO but the other answers seem to be applicable for a mac (e.g. accidentally installing via sudo). When I do pip2 list, the module is present, so I don't understand why I can't access it.

(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: [email protected]
License: Apache 2.0
Location: c:\users\dan\desktop\python\bulkphotos\venv\lib\site-packages
Requires:

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

Does anyone know how to solve this problem?

EDIT The results of running sys.path on the interactive 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']

The results of running where py and 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

Upvotes: 2

Views: 3037

Answers (2)

Maciej Lach
Maciej Lach

Reputation: 1691

The Windows Python launcher PEP 397 is not aware of the active virtual env. See PEP 486 for details.

Try to launch Python interpreter by executing python instead of py.

Upvotes: 4

Nishant Nawarkhede
Nishant Nawarkhede

Reputation: 8400

I dont know why these packages are not imported,

But you can debug it by viewing your pythonpath using,

python -c "import sys; print sys.path"

You can append optional path to sys.path.

Upvotes: 1

Related Questions