首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过在Mac OS上导入时出现的问题安装的Python模块

通过在Mac OS上导入时出现的问题安装的Python模块
EN

Stack Overflow用户
提问于 2016-09-12 03:03:30
回答 2查看 38关注 0票数 0

我在python2.7中安装了beautifulsoup4模块,但导入失败。

python模块安装在此目录下。

代码语言:javascript
复制
$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

代码语言:javascript
复制
$ /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()

python sys.path的模块位置为/Library/Python/2.7/site-packages

代码语言:javascript
复制
$ /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()
$

请建议模块导入失败的原因。

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-12 03:07:24

该模块名为bs4,而不是beautifulsoup4,请尝试使用:

代码语言:javascript
复制
import bs4  
票数 0
EN

Stack Overflow用户

发布于 2016-09-12 03:08:09

试试这个:

代码语言:javascript
复制
 from bs4 import BeautifulSoup
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39439622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档