简体   繁体   中英

beautifulsoup4 installation & import using python3 on mac

I am going crazy about the installation of beautifulsoup4 on my macbook on which I have Python 3.x installed.

I managed to install beautifulsoup by typing "python3 setup.py install" in the console. After going through some code the console tells me

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$

But when I run "import bs4" in Python, it keeps telling me

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

but as far as I can see I installed the 4..4.0 version of beautifulsoup4.

There seem to be a lot of people how are seeking for a short but clear noobie-tutorial how to install bs4 in Python 3.x on a Mac with OS 10.x

Hopefully someone can help us out...

Actually the pip3 install BeautifulSoup produces a strange error for me:

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'

But sudo pip3 install BeautifulSoup4 works!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM