我安装了 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 & gt;python testcode.py Traceback (最近一次调用最后一次):文件“testcode.py”,第 4 行,在 s = bs (xml,'xml') 文件“F:\ ProgramData\ Anaconda3\ lib\ site-packages\ bs4__init__.py”,第 198 行
我甚至试图将脚本复制到“F:\ ProgramData\ Anaconda3”文件夹中,并从此处运行命令提示符。但同样的错误
注意:F:
是 OS 驱动器。
我如何解决这个问题?
什么应该是根目录(在 anaconda 窗口)运行 python 脚本,以便它可以找到 conda 包?
从该位置运行 python 控制台的一些观察结果:
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 yoequeste
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 yoequeste
d: lxml. Do you need to install a parser library?
>>>
更新:
我从 Python exe Installer 在新鲜的 Windows 操作系统上安装了 3.7.3 64 位 Python,将 python 路径添加到环境变量,安装了 bs4,lxml 与 pip。现在它工作
但我仍然想知道如何使 anaconda 安装足够和足够的 python 脚本在系统中的任何地方运行。
Anaconda 安装后缺少什么,只是路径变量或还有其他东西??
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(48条)