I installed anaconda and below is the code which runs perfect in jupyter notebook.
from bs4 import BeautifulSoup as bs
xml = '<head><body></body></head>'
s = bs(xml,'xml')
print(s)
Output:
<?xml version="1.0" encoding="utf-8"?>
<Head><body/></Head>
But the same code if I try to run with windows command prompt throws the error below:
F:\ProgramData\Anaconda3>python testcode.py Traceback (most recent call last): File "testcode.py", line 4, in s = bs(xml,'xml') File "F:\ProgramData\Anaconda3\lib\site-packages\bs4__init__.py", line 198, i n init % ",".join(features)) bs4.FeatureNotFound: Couldn't find a tree builder with the features you requeste d: xml. Do you need to install a parser library?
I even tried to copy the script in "F:\ProgramData\Anaconda3" folder and run command prompt from here. But same error.
Note: F:
is the OS drive.
How can I resolve this?
What should be the root directory (on anaconda windows) to run the python script from so that it can locate the conda packages?
Few observations on running python console from that location:
F:\ProgramData\Anaconda3>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Ana
conda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml
>>> from bs4 import BeautifulSoup as bs
>>> s = bs("<head></head>","xml")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\ProgramData\Anaconda3\lib\site-packages\bs4\__init__.py", line 198, i
n __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requeste
d: xml. Do you need to install a parser library?
>>> import lxml
>>> s = bs("<head></head>","lxml")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\ProgramData\Anaconda3\lib\site-packages\bs4\__init__.py", line 198, i
n __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requeste
d: lxml. Do you need to install a parser library?
>>>
Update:
I installed 3.7.3 64-bit Python on fresh Windows OS from Python exe Installer, added python path to environment variables, installed bs4,lxml with pip. And now it works.
But I'd still like to know how to make the anaconda installation sufficient and enough for the python scripts running anywhere in the system.
What is missing after Anaconda installation, just the path variables or there are other things as well??
lxml
instead ofxml
– bharatkxml
andlxml
. And I don't want to uselxml
as I want the tags to be case sensitive and case preserved. – Zid