简体   繁体   English

在Mac OSX上安装BeautifulSoup

[英]Installing BeautifulSoup on Mac OSX

I have tried everything here: How can I install the Beautiful Soup module on the Mac? 我已经在这里尝试了所有方法: 如何在Mac上安装Beautiful Soup模块?

Installation seems to work (getting correct output during install) from both the traditional way to install and also using easy_install but when I use: 从传统的安装方式到使用easy_install,安装似乎都可以正常工作(在安装过程中获得正确的输出),但是当我使用时:

from bs4 import BeautifulSoup

the interpreter says no such module exists. 解释器说不存在这样的模块。

What should I look at first to troubleshoot this? 我首先应该看什么来解决这个问题?

To see all the packages you have installed, you can run the following in a interpreter: 要查看已安装的所有软件包,可以在解释器中运行以下命令:

>>> help('modules')

That will list for you all the modules you have installed. 这将为您列出所有已安装的模块。 Look for bs4 in the list (which seems to be alphabetical). 在列表中查找bs4 (似乎按字母顺序)。 Another option is to issue at your prompt: 另一个选择是在您的提示下发出:

$ python -c "help('modules')" | grep bs4

If nothing comes up, or you cannot find it in the list, the module is not installed. 如果什么都没有出现,或者您在列表中找不到它,则表明该模块未安装。

To install it, I used sudo pip install bs4 . 要安装它,我使用了sudo pip install bs4 You may need to run sudo easy_install pip first to get pip . 您可能需要先运行sudo easy_install pip来获取pip Also note the use of sudo , as this may make a difference. 还要注意使用sudo ,因为这可能有所不同。

And I'm running 10.8 build version 12C60. 我正在运行10.8构建版本12C60。

I have an uggly solutions which works for me: 我有一个适合我的解决方案:

try:
    from bs4 import BeautifulSoup as bs
except ImportError:
    from BeautifulSoup import BeautifulSoup as bs

after what, I call everything with bs prefix. 之后,我用bs前缀称呼所有内容。

I've had the same issue. 我有同样的问题。 bs4 is installed but it wasn't showing up in help(modules). bs4已安装,但未显示在帮助(模块)中。

I don't know if this will work for others, but I had the same issue with openCV and solved it by adding the following before trying to load the package. 我不知道这是否对其他人有用,但是我在openCV中遇到了同样的问题,并在尝试加载程序包之前添加了以下内容来解决该问题。 It worked for openCV and it just worked for bs4: 它适用于openCV,仅适用于bs4:

import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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