我安装了anaconda,下面是在jupyter笔记本中运行完美的代码。
from bs4 import BeautifulSoup as bs
xml = '<head><body></body></head>'
s = bs(xml,'xml')
print(s)
输出:
<?xml version="1.0" encoding="utf-8"?>
<Head><body/></Head>
但是如果我尝试在Windows命令提示符下运行,则相同的代码将引发以下错误:
F:\ ProgramData \ Anaconda3> python testcode.py Traceback(最新 最后调用):文件“ testcode.py”,第4行,在 s = bs(xml,'xml')文件“ F:\ ProgramData \ Anaconda3 \ lib \ site-packages \ bs4__init __。py”,行 198,我 init %“,”。join(features))bs4.FeatureNotFound:找不到具有您要求的功能的树生成器d:xml。您需要安装吗 解析器库?
我什至尝试将脚本复制到“ F:\ ProgramData \ Anaconda3”文件夹中,然后从此处运行命令提示符。但是同样的错误。
注意:F:
是操作系统驱动器。
我该如何解决?
从其运行python脚本以便可以找到conda软件包的根目录(在anaconda Windows上)应该是什么?
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?
>>>
我从Python exe安装程序在新的Windows操作系统上安装了3.7.3 64位Python,为环境变量添加了python路径,并通过pip安装了bs4,lxml。现在就可以了。
但是我仍然想知道如何充分安装anaconda,以使其足以在系统中的任何位置运行python脚本。
安装Anaconda后缺少什么,只是路径变量还是还有其他东西?