Python Forum
Error when running .py file but not when entering exact same code in CLI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when running .py file but not when entering exact same code in CLI
#1
Code:
#!/usr/bin/python3

import requests
from bs4 import BeautifulSoup
url = "https://pythonprogramming.net/parsememcparseface/"
resp = requests.get(url)
txt = resp.text
soup = BeautifulSoup(txt, 'lxml')
The following error is now being produced on unchanged code that was previously working (2 days ago):
Traceback (most recent call last):
  File "./xtest.py", line 10, in <module>
    soup = BeautifulSoup(txt, 'lxml')
  File "/usr/lib/python3/dist-packages/bs4/__init__.py", line 165, in __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
Additionally, at the same point the error message is returned, a new sub-folder is created:
__pycache__
Containing 1 compiled/binary file:
lxml.cpython-36.pyc

If I run exactly the same code via the python3 CLI, no such error is returned, no such sub-folder is created and I can view and process the response text as expected.

I have removed and reinstalled python3-bs4, but the problem continues.

Any assistance would be much appreciated.
Reply
#2
Is python3-lxml installed?
Reply
#3
Yes indeed.

$ apt list | grep python3-lxml

python3-lxml/bionic-updates,bionic-security,now 4.2.1-1ubuntu0.1 amd64 [installed,automatic]
Reply
#4
Just in case there was a problem with the python3-lxml package, I removed then reinstalled it, but the problem remains.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code example for entering input in a textbox with requests/selenium object peterjv26 1 1,674 Sep-26-2020, 04:34 PM
Last Post: Larz60+
  Error after a few minutes of running julio2000 10 5,292 Feb-05-2020, 11:05 PM
Last Post: julio2000
  error when running headless selenium julio2000 2 4,508 Feb-01-2020, 12:41 PM
Last Post: julio2000
  What the difference between python2 and python3 when they running my code. lpangfeic 1 1,832 Nov-19-2019, 04:44 PM
Last Post: Larz60+
  Running flask run produces error. Charles1 1 4,028 Oct-04-2019, 10:38 PM
Last Post: snippsat
  whats the error in this code in python 3.0 as this is running 2.0 pyhon ekansh 7 5,098 Feb-05-2018, 06:47 AM
Last Post: seco
  Issues running Selenium to download zip file davehughes87 4 6,251 Jan-12-2017, 02:19 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020