Home > front end >  Can't Import Python3 Requests Module
Can't Import Python3 Requests Module

Time:02-11

I am using VS Code using Python 3.9.1.

I have setup a venv called env. Folder structure is:

env
  - Include
  - Lib
      - requests
  - Scripts
  - pyvenv.cfg
  - scrape.py

In my script, scrape.py I have:

import requests

URL = "https://etherscan.io/token/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
page = requests.get(URL)

print(page.text)

I get the following error: Import "requests" could not be resolved from source Pylance(reportMIssingModuleSource)

I have installed requests as you can see from the directory structure. A pip list gives the following which also shows requests is installed:

enter image description here

CodePudding user response:

Use the command select python interpreter, setting it to your venv.

Make sure you Activate your venv in the console.

I think it'll add the string (venv) to your prompt. After running activate, pip and python now

There's additional guides here: https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments

  • Related