Как установить requests в visual studio code
Перейти к содержимому

Как установить requests в visual studio code

  • автор:

Импорт запросов в Python с использованием кода Visual Studio

Я пытаюсь импортировать модуль requests в файл Python (используя Python 2.7.14).

Код Visual Studio вывел это в консоль:

ImportError: нет модуля с именем requests

Покопавшись, я обнаружил, что у меня не установлен requests , поэтому я исправил это с помощью следующей команды из Терминала:

sudo pip install requests на основе этого ответа, набравшего миллиард голосов.

Я закрыл VS Code и перезапустил его, открыл файл Python, запустил его и получил ту же ошибку. Я начал пробовать каждое из решений в надежде, что одно из них сработает. Никто не сделал.

Я недавно установил anaconda и подозреваю, что это является источником моей проблемы, поэтому я удалил все экземпляры Python, которые смог найти через brew , а также случайные установки, которые были частью других установок, которые накопились с течением времени на моем жестком диске на основе этот ответ.

Затем я переустановил python с нуля после запуска brew doctor , brew prune и т. Д.

Я также покопался в настройках кода в Visual Studio Code, чтобы увидеть, возможно ли, в этом моя проблема. Одно из предложений заключалось в том, чтобы переопределить настройки для python в настройке code-runner.executorMap , поэтому я набрал which python в Терминале, чтобы получить путь к python , и обновил пользовательские настройки VS Code. на путь, возвращенный which python . Теперь я использую это как свой code-runner.executorMap для python :

Я подтвердил, что Python работает, добавив пару простых утверждений:

В тот момент, когда я помещаю import requests в начало файла, я получаю эту ошибку, и ничего ниже не выполняется:

[Выполняется] / usr / bin / python «/Users/me/Documents/developerNew/python/tempCodeRunnerFile.py» Traceback (последний вызов последним): файл «/Users/me/Documents/developerNew/python/tempCodeRunnerFile.py» , строка 1, в запросах на импорт ImportError: Нет модуля с именем requests

У меня есть файл с другим именем, поэтому я думаю, что моя проблема находится в «tempCodeRunnnerFile.py». Я попытался удалить переопределение для codeRunner.executorMap , но это тоже не сработало.

У меня нет идей. Если он у вас есть, я приветствую ваше предложение. Спасибо за чтение.

Importing requests into Python using Visual Studio Code

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 :

I’ve verified Python is working by throwing in a couple of simple statements in:

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.

mirsovetov.net

Андрощук Александр, ИТ решения, советы, заметки…

ImportError: No module named requests

Задача: При попытке подключить модуль requests (import requests) получил сообщение об ошибке: No module named requests. Нужно установить модуль requests

Инструменты: python2, python3, pip

Решение: Дело в том, что модуля requests нет в базовой инсталяции python’a. Его нужно устанавливать дополнительно. Рассмотрим команды, для установки модуля requests под разные операционные системы:

  • Windows

Если у Вас есть установлен pip, тогда выполните команду, которая установит пакет requests

pip install requests

или

pip3 install requests

Если у Вас есть желание установить пакет вручную, Вы можете скачать эту библиотеку, и розархивировать в папку <python location>\Lib\site-packages . (Например: C:\Python\Lib\site-packages)

Чтобы установить пакет requests в Visual Studio Code — я использовал следующую команду:

  • OSX/Linux

Если у Вас установлен pip — выполните команду (Python2):

sudo pip install requests

или

sudo pip3 install requests

Если у Вас есть установлен easy_install, тогда для него будет команда:

  • Cent OS
  • Debian/Ubuntu

Для установки — выполним команду:

sudo apt-get install python-requests

или

sudo apt-get install python3-requests

Installing a Python Library in Visual Studio Code — Windows

In this quick blogpost, I will share the steps that you can follow in order to install a Python library using pip through either the Terminal or a Jupyter Notebook in Visual Studio Code (VSCode) on a Windows computer.

Pre-requisites

In order to complete the steps of this blogpost, you need to install the following in your windows computer:

  • Visual Studio Code : you can find the steps to install it here.
  • Python Extension for Visual Studio Code : you can find the steps to install it here.
  • Python Interpreter : you can find the steps to install it here.

Installing a Python Library Using the Terminal in VSCode

1) Accessing Visual Studio Code Terminal

  • Open VSCode application

  • Go to the Terminal menu and select New Terminal .

  • A new terminal (PowerShell based) window is opened.

2) Importing a Python Library

  • Run the following command to validate that pip is installed in your computer.

  • Let us say that you want to install Pandas Python library.
  • Run the following command

  • Pandas library is now ready to be imported by any python application. You can repeat this process for any Python library.

Installing a Python Library Using a Jupyter Notebook in VSCode

1) Creating a Jupyter Notebook in VSCode

  • Create a Jupyter Notebook following the steps of My First Jupyter Notebook on Visual Studio Code (Python kernel)

2) Importing a Python Library

  • Run the following command to validate that pip is installed in your computer.

  • Let us say that you want to install Pandas Python library.
  • Run the following command.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *