Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Setting Up a Local Python Environment Installing Python and Python Libraries Locally Using virtualenv

virtualenv "No module named requests"

Following the video, I made a virtualenv named peace code: (peace) C:\Python34\Scripts> pip install requests

Got: requests in c:\python34\lib\site-packages

Then tried (peace)C:\Python34\Scripts>python

Got: Python 3.4.2 and stuff

Tried

import requests Got: Traceback (most recent call last): File"<stdin>", line 1, in <module> ImportError: No module named 'requests'

Want to know how to effectively import modules using virtualenv under Windows. Thanks

I'm getting this same error (on a Windows machine) and I still have not been able to solve it. Does anyone have any other ideas?

EDIT: Was I supposed to install "requests" outside the virtual environment before starting? Because after I installed it globally, the "import requests" finally worked.

3 Answers

Sigh...can't show the screenshot. When I do a pip freeze in the env, requests==2.5.1 shows up. It just doesn't work when I try to use the environment. (environmentName) C:Python34\Scripts>pip freeze I show Flask, Jinja2, MarkupSafe, WerKzeug, itsdangerous, mistune, requests, and virtualenv

but I still get ImportError: No module named 'requests' after this: (environmentName) C:Python34\Scripts>python

import requests

Gavin Ralston
Gavin Ralston
28,770 Points

When you type pip freeze in your venv, what installed modules do you see listed?

Gavin Ralston
Gavin Ralston
28,770 Points

I ask mainly because it showed requests in c:\python34\lib\site-packages but that's not going to help you in the venv. The whole point a virtual environment is to have the module you want in your venv path rather than pulling from your default system environment.

I'm pretty sure I'm experiencing the same problem. When I make a venv with virtualenv from my ActiveState python...

~ virtualenv myvenv

it displays error

Cannot find sdist setuptools-*.tar.gz
Cannot find sdist pip-*.tar.gz

So it appears, when I try to pip install inside the venv, it links to outside pip which is in Activatestate python folder in outside the directory. However, venv install as a .exe python inside the virtual environment and when I launch the python, it links to that inside python which doesn't have nor pip nor requests due to error installing myenv which I said about before

A trick I discovered is, I'd just put a get-pip.py (yeah, the alternative install method) inside the venv and launch it with python (the python in my venv) which lets me install packages locally

and it's totally not optimal, so if somebody could contribute a better solution! (^: