我对在我安装了 Python 3.x 的 MacBook 上安装 beautifulsoup4 感到非常着迷。
我通过在控制台中输入“python3 setup.py install”成功安装了 beautifulsoup。经过一些代码后,控制台告诉我
Installed /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beautifulsoup4-4.4.0-py3.5.egg
Processing dependencies for beautifulsoup4==4.4.0
Finished processing dependencies for beautifulsoup4==4.4.0
Patriks-MacBook-Pro:beautifulsoup4-4.4.0 Patrik$
但是当我在 Python 中运行“import bs4”时,它一直告诉我
import bs4
File "<frozen importlib._bootstrap>", line 2205, in _find_and_load
File "<frozen importlib._bootstrap>", line 2190, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 2132, in _find_spec
File "<frozen importlib._bootstrap>", line 1908, in find_spec
File "<frozen importlib._bootstrap>", line 1884, in _get_spec
File "<frozen importlib._bootstrap>", line 1865, in _legacy_get_spec
File "<frozen importlib._bootstrap>", line 864, in spec_from_loader
File "<frozen importlib._bootstrap>", line 905, in spec_from_file_location
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beautifulsoup4-4.4.0-py3.5.egg/bs4/__init__.py", line 48
'You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>'You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).'
^
SyntaxError: invalid syntax
但据我所知,我安装了4..4.0版本的beautifulsoup4。
似乎有很多人正在寻找一个简短但清晰的菜鸟教程,如何在 OS 10.x 的 Mac 上使用 Python 3.x 安装 bs4
希望有人能帮助我们......
最佳答案
实际上 pip3 install BeautifulSoup 给我带来了一个奇怪的错误:
Collecting BeautifulSoup
Downloading BeautifulSoup-3.2.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/tmp/pip-build-prl0vx3e/BeautifulSoup/setup.py", line 22
print "Unit tests have failed!"
^
SyntaxError: Missing parentheses in call to 'print'
但是 sudo pip3 install BeautifulSoup4 有效!
关于python - beautifulsoup4在mac上使用python3安装和导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31324949/