Home > front end >  Why does the python terminal close when executing the import statement?
Why does the python terminal close when executing the import statement?

Time:09-26

I have a simple python program, that is supposed to scrape some information from the internet and do stuff with it. When I run the code in PyCharm (IDE) it works fine, but when I run it directly it doesn't work (Right-click -> Open with -> Python). In order to find the error I put several input statements in the code, as such:

from random import choice
input(1)
import webbrowser as web
input(2)
from time import sleep
input(3)
import pyautogui as pg
input(4)
from platform import system
input(5)  # It closes after this.
from bs4 import BeautifulSoup
input(6)
import requests
input(7)

It all seems to work fine until 5. I press enter then the terminal instantly closes without any error messages. So there must be something wrong when I import BeautifulSoup from bs4.

from bs4 import BeautifulSoup

Why does the python terminal close when executing the import statement? Any help would be appreciated :)

CodePudding user response:

This is probably due to an exception that is terminating the process. I had the same problem a while ago and it was solved by installing the package.

Are you sure you have bs4 installed? Try running pip install bs4 to make sure it is installed.

  • Related