2016-09-11 102 views
0

我在python2.7中安裝了beautifulsoup4模塊,但導入失敗。Python模塊在Mac OS上導入時被問題安裝

python模塊安裝在這個目錄下。

$ls -l /Library/Python/2.7/site-packages 
total 1080 
-rw-r--r-- 1 root wheel  119 Aug 22 2015 README 
drwxr-xr-x 9 root wheel  306 Sep 8 22:17 beautifulsoup4-4.5.1.dist-info 
drwxr-xr-x 14 root wheel  476 Sep 8 22:17 bs4 
-rw-r--r-- 1 root wheel  30 Sep 8 22:03 easy-install.pth 
drwxr-xr-x 34 root wheel 1156 Sep 8 22:16 pip 
drwxr-xr-x 10 root wheel  340 Sep 8 22:16 pip-8.1.2.dist-info 
-rw-r--r-- 1 root wheel 538338 Sep 8 22:03 setuptools-26.1.1-py2.7.egg 
-rw-r--r-- 1 root wheel  30 Sep 8 22:03 setuptools.pth 
drwxr-xr-x 6 root wheel  204 Jul 26 21:13 vboxapi 
-rw-r--r-- 1 root wheel  241 Jul 26 21:13 vboxapi-1.0-py2.7.egg-info 
drwxr-xr-x 32 root wheel 1088 Sep 8 22:16 wheel 
drwxr-xr-x 11 root wheel  374 Sep 8 22:16 wheel-0.29.0.dist-info 
$ 

python shell的輸出,導入失敗。我使用python2.7

$ /usr/bin/python 
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import beautifulsoup4 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named beautifulsoup4 
>>> exit() 

蟒蛇sys.path具有模塊位置爲/Library/Python/2.7/site-packages

$ /usr/bin/python 
Python 2.7.10 (default, Oct 23 2015, 19:19:21) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import sys 
>>> print "\n".join(sys.path) 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages 
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old 
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload 
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC 
/Library/Python/2.7/site-packages 
/Library/Python/2.7/site-packages/setuptools-26.1.1-py2.7.egg 
>>> exit() 
$ 

請說明爲什麼模塊的導入失敗。

感謝

+0

你試圖在終端使用的easy_install BeautifulSoup?更新並嘗試再次運行。另外:從BS4進口BeautifulSoup –

回答

0

該模塊被稱爲bs4,不beautifulsoup4,嘗試用:

import bs4 
+0

它的工作。謝謝, – bobby

0

試試這個:

from bs4 import BeautifulSoup 
+0

它的工作。謝謝, – bobby