beautifulsoup4安装&在mac上使用python3导入

时间:2015-07-09 17:59:26

标签: python macos installation beautifulsoup

我对我安装了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。

似乎有很多人如何寻求一个简短而明确的noobie教程如何在Mac 10.x中使用OS 10.x在Python 3.x中安装bs4

希望有人可以帮助我们......

1 个答案:

答案 0 :(得分:1)

实际上pip3安装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安装BeautifulSoup4有效!