简体   繁体   中英

why I got ( ModuleNotFoundError: No module named 'ModuleName' ) error in VSCode, windows 10?

I wrote a simple python program that I learned from Mosh Hamedani course.

  • Operating System: Windows10, 64bit
  • Editor: VSCode
  • Python: 3.9.0

已安装的 Python

1- I created a folder called "PyCrawler".

2- Then in my project directory, using terminal, run these commands one by one:

  pipenv install beautifulsoup4

  pipenv install requests

3- Then it give me an error to install autopep8, so I installed that.

4- created a file named "app.py"

5- selected correspond venv.

6- write these code inside app.py

import requests
from bs4 import BeautifulSoup

response = requests.get("http://stackoverflow.com/questions")
soup = BeautifulSoup(response.text, "html.parser")

questions = soup.select(".question-summary")
print(questions[0].select_one(".question-hyperlink").getText())

7- when I run this program using "python app.py" command it gives me "ModuleNotFoundError: No module named 'bs4' " error.

我得到的错误截图

It's strange. I installed beautifulsoup4, why I got this error?!!

Solutions in other questions that have been asked didn't help me.

I got same issue for selenium.

I think if I install any package I get this issue and I don't know why.

Thanks for your helps in advance.

You are probably installing the packages to a different version of Python than the one you are using to run your program. Before you run your program, enter the command

$ pipenv shell

into your terminal to activate the enviornment. Then

$ python app.py

should work. For more information, see the documentation for pipenv .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM