Preface: I've tried every suggestion in this post. None of them work.
I'm attempting to import the module requests
into a Python file (using Python 2.7.14).
Visual Studio Code outputted this in the console:
ImportError: No module named requests
Upon digging, I discovered I don't have requests
installed, so I fixed that with the following commannd from Terminal:
sudo pip install requests
, based on this answer with a bazillion upvotes.
I closed VS Code and restarted it, opened my Python file, ran it and I got the same error. I proceeded to try each of the solutions in hopes one would work. None did.
I recently installed anaconda
and I suspect that is the source of my problem, so I uninstalled every instance of Python I could find via brew
and also stray installations that were parts of other installations that have accumulated over time on my hard disk based on this answer.
I then reinstalled python from scratch after running brew doctor
, brew prune
, etc.
I also dug into the code settings within Visual Studio Code to see if perhaps that's where my problem was. One of the suggestions was to override the settings for python
in the code-runner.executorMap
setting, so I typed which python
in Terminal to obtain the path to python
and updated VS Code's User Settings to the path which python
returned. Now, I'm using this as my code-runner.executorMap
for python
:
"code-runner.executorMap": {
"python" : "/usr/bin/python"
}
I've verified Python is working by throwing in a couple of simple statements in:
print("Printing works fine")
print(1+1)
The moment I put import requests
at the top of the file, I get this error and nothing below it executes:
[Running] /usr/bin/python "/Users/me/Documents/developerNew/python/tempCodeRunnerFile.py" Traceback (most recent call last): File "/Users/me/Documents/developerNew/python/tempCodeRunnerFile.py", line 1, in import requests ImportError: No module named requests
I have my file named something else, so I think my problem lives in the "tempCodeRunnnerFile.py". I tried removing the override for the codeRunner.executorMap
, but that doesn't seem to work either.
I'm out of ideas. If you have one, I welcome your suggestion. Thank you for reading.