Решение проблемы с ошибкой ImportError: No module named requests
Если при запуске программы на Python у вас появляется сообщение об ошибке:
значит у вас отсутствует модуль Requests. Requests не является встроенным модулем, поэтому его нужно загрузить. Официальная документация по модулю: https://pypi.python.org/pypi/requests
OSX/Linux
Если у вас установлен pip, для установки в OSX/Linux используйте команду:
Обратите внимание на версию, чтобы явно указать, для какой версии Python вы делаете установку, используйте pip2 или pip3.
На OSX если у вас установлен easy_install, вы также можете использовать
Windows
В этой операционной системе используйте команду:
Если у вас машина на Windows, где если он был установлен, easy_install может быть найден в вашем каталоге Python*\Scripts. (Помните, Path\easy_install.exe — это пример, моя, к примеру, такая C:\Python32\Scripts\easy_install.exe)
Если у вас Windows машина без установленного easy install, то вы можете получить его здесь: http://www.lfd.uci.edu/
Если вы хотите добавить библиотеку на Windows машине вручную, вы можете загрузить сжатую библиотеку, разархивировать и затем поместить в каталог Lib вашего Python.
Из исходников (универсальный способ)
Любая отсутствующая библиотека, обычно, доступна в исходниках на: https://pypi.python.org/pypi/. Затем:
На mac osx и Windows, после загрузки zip с исходником, распакуйте его и из терминала/cmd запустите
ModuleNotFoundError: No module named ‘requests’. But ‘requests’ already installed
Trying to import ‘requests’ .
Has it installed via pip3 install requests? But still, have this error.
Error Traceback:
5 Answers 5
Only if you trying to work with urllib
Else try to uninstall requests and then again install it using pip
and again install it
or if you did’nt get what I am saying so please visit
If you’re using PyCharm as IDE, try closing and restarting PyCharm. Move the mouse cursor over the «requests» (with red curly line beneath it), until the red light bulb next to it show up. Select the first option in it, «Install package requests». PyCharm will take care of the installation from there.
I ran into the same issue and have tried all the solutions here on Stack Overflow.
If it is installed this will WORK:
If you see this error when running your script/IDE:
Traceback (most recent call last): File «E:\test.py», line 1, in
import requests
ImportError: No module named requests
Then the trick for me was not to start up a VirtualEnv, I actually found I was running the x64 version of python when I’d installed the requests package into the python 32 bit folder c:\program files (x86)\python37-32\lib\site-packages. This is a screenshot from the internet but it shows you how to change the interpreter you’re using — in my case — I need to set it to Python 3.7.4(x86) 32 bit:
ModuleNotFoundError: No module named ‘requests’ using venv in vscode
I have 1 file, i get as far as line 1 import requests , nothing more yet and I receive the following error ModuleNotFoundError: No module named ‘requests’ .
- Using Visual Studio Code, installed today with standalone Python x64 3.7.4
- Python Extension installed in VSCODE
- venv created within VSCODE as a subfolder of workspace withint VSCODE terminal and was recognized by VSCODE when created and I am using venv interpreter in VSCODE as indicated on bottom bar
- ran pip install requests within terminal inside VSCODE — completed successfully
- ran pip freeze to confirm requests==2.22.0 is registered
- Verified pylint was installed in venv
I cannot figure out why VSCODE python interpreter will not recognize that requests is installed
4 Answers 4
Have you checked your user and workspace settings?
Make sure your workspace settings (not your user settings) points to your project’s venv path.
I have encountered a similar problem such as yours but was able to solve it by changing the workspace settings python path to point to my venv path as below.
try get python version in vscode terminal
and check python version vscode IDE used by clicking left buttom corner.
make sure these 2 versions are consistent. if not, select the version of IDE with the same version of your terminal.
Is there more than one python environment locally? maybe try:
Thanks for the responses. I found out my own issue after a few hours.
First off I figured out somewhere that when I was running the terminal in VSCODE it was running against global interpreter. I then tried ./pip freeze and it worked as expected. This told me that the terminal was connected to the wrong interpreter.
For some reason when I would ‘run’ the file it was executing in the terminal but it wasn’t ‘activating’ the venv. I’ve closed and reopened VSCODE many times but for some reason when I closed the terminal window and reopened using CTRL+SHIFT+’ and I received an error about signed scripts when it tried to activate my venv using the PS1 script. I ran Set-ExecutionPolicy -ExecutionPolicy RemoteSigned inside a normal PowerShell window and then reopened the Terminal window in VSCODE and it successfully activated my venv and I know see my venv name at the beginning of the line of the terminal. I then ran ‘pip freeze’ to confirm which modules installed inside of venv and then ran again in normal powershell window and it was different.
There is documentation somewhere that says to run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned which I found later, but it would have been nice to know this was a requirement.