Beautiful Soup 不导入
Beautiful Soup not importing
我在 OSX 并且我之前已经在终端中安装了 bs4。
所以尝试再次安装它我得到:
$ pip install beautifulsoup4
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.4.1-py2.7.egg
当我尝试导入 bs4 时出现此错误:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import bs4
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bs4/__init__.py", line 468
print soup.prettify()
^
SyntaxError: invalid syntax
我该如何解决这个问题? bs4 文件最初下载到我的 python2.7 文件中,因此我将其复制并粘贴到我的 python 路径上的文件夹中。我很确定这是错误的做法,但我现在应该怎么做才能让它正常工作?我在这里查看了其他类似的问题(诚然有很多),但我还没有找到有效的解决方案。
谢谢!
print (soup.prettify())
python 3 使用 print() 作为函数。
即
print ("hello world")
也可以这样
print("hello world",end="")
这样就没有换行
从第 2 版软件包迁移到第 3 版可能还有很多错误,因为一些事情发生了变化,我可以 运行 bs4 但我在 python 上得到了它3.
在 Python 3 中,打印语句应该有括号 print(soup.prettify())
,我不确定为什么它不是你的情况,看来你有 bs4
来自 python 2个版本。再试试强制安装美汤$ pip install --ignore-installed beautifulsoup4
。
我在 OSX 并且我之前已经在终端中安装了 bs4。 所以尝试再次安装它我得到:
$ pip install beautifulsoup4
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Python/2.7/site-packages/beautifulsoup4-4.4.1-py2.7.egg
当我尝试导入 bs4 时出现此错误:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import bs4
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/bs4/__init__.py", line 468
print soup.prettify()
^
SyntaxError: invalid syntax
我该如何解决这个问题? bs4 文件最初下载到我的 python2.7 文件中,因此我将其复制并粘贴到我的 python 路径上的文件夹中。我很确定这是错误的做法,但我现在应该怎么做才能让它正常工作?我在这里查看了其他类似的问题(诚然有很多),但我还没有找到有效的解决方案。
谢谢!
print (soup.prettify())
python 3 使用 print() 作为函数。
即
print ("hello world")
也可以这样
print("hello world",end="")
这样就没有换行
从第 2 版软件包迁移到第 3 版可能还有很多错误,因为一些事情发生了变化,我可以 运行 bs4 但我在 python 上得到了它3.
在 Python 3 中,打印语句应该有括号 print(soup.prettify())
,我不确定为什么它不是你的情况,看来你有 bs4
来自 python 2个版本。再试试强制安装美汤$ pip install --ignore-installed beautifulsoup4
。