Reputation: 135
Hello I am having issues with adding the module "requests" to my virtual environment. I already did pip install requests but it states the requirement is already satisfied but when I got to run my program that depends on "requests" it says ModuleNotFoundError: No module named 'requests'. I have already tried deleting and adding my virtual environment but that didn't work. Any help would be great, please see below screenshot of my terminal.
Upvotes: 0
Views: 5288
Reputation: 11
If you haven't already done so, make sure that the line at the beginning of the Python script invokes the interpreter set in the virtual environment by using, for example, #!/usr/bin/env python
or #!/usr/bin/env python3
. Invoking the Python interpreter directly with #!/usr/bin/python
ignores the virtual environment and would result in a ModuleNotFoundError
. HTH.
Upvotes: 1
Reputation: 1066
I think your $PATH or environment variables are getting messed up somewhere. As a work around, you can run the specific pip command from the inside of your virtualenv. Let's say for example that my virtualenv is called venv_test and it's in my current directory. Make sure you already 'sourced' your virtual environment before running the following.
cd venv_test
cd bin
./pip install requests
It might help to recreate your virtualenv too in case something got switched around. Let's say we have python3 installed along with the default python2.7 that comes with OSX, we can create a python3 specific virtual_env with the following.
mkvirtualenv --python=python3.6 python3_venv
source python3_venv/bin/activate
pip install requests
Upvotes: 1