macos 我如何在我的 mac 上为 python 安装漂亮的汤?看到错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9876226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do i install beautiful soup for python on my mac? see error
提问by Jay Kim
I'm running Mac OS X 10.7.3 on a Macbook Pro. It came with Python 2.7.1 installed. I need the beautiful soup library. So I did the following:
我在 Macbook Pro 上运行 Mac OS X 10.7.3。它安装了 Python 2.7.1。我需要漂亮的汤库。所以我做了以下事情:
1) went to crummy.com and downloaded beautifulsoup4-4.0.2.tar.gz
1)去crummy.com下载beautifulsoup4-4.0.2.tar.gz
2) uncompressed it
2)解压
3) navigated to uncompressed directory and typed the following
3)导航到未压缩的目录并输入以下内容
python setup.py install
but i got a error that i couldn't write to some directory.
但是我遇到了无法写入某个目录的错误。
4) so i ran:
4)所以我跑了:
sudo python setup.py install
须藤 python setup.py 安装
No Errors! Good, right? Not exactly. When I try to run a program with the following:
没有错误!很好,对吗?不完全是。当我尝试使用以下内容运行程序时:
from BeautifulSoup import *
I receive the following error:
我收到以下错误:
ImportError: No module named BeautifulSoup
What did I do wrong?
我做错了什么?
Thanks!
谢谢!
回答by Kien Truong
For BeautifulSoup4 you have to use
对于 BeautifulSoup4,您必须使用
from bs4 import BeautifulSoup
Check the document: BS4 document
检查文件:BS4文件
回答by modocache
Is there a reason you can't use pip
or easy_install
? Unless you're set on installing from source, you can run either of the following:
是否有不能使用的原因pip
或easy_install
?除非您设置为从源代码安装,否则您可以运行以下任一命令:
$ easy_install BeautifulSoup
Or, if you have pip
(which I recommend, you can install it with easy_install pip
):
或者,如果你有pip
(我推荐,你可以用 安装它easy_install pip
):
$ pip install BeautifulSoup
I'm not certain why your source install isn't working though. Is it possible the python interpreter you're using to install the source and the interpreter you're using in your program are different? Try running python --version
on the command line--is the same version displayed as when you run the following in your program?
我不确定为什么您的源安装不起作用。您用于安装源代码的python解释器和您在程序中使用的解释器是否可能不同?尝试python --version
在命令行上运行-- 显示的版本与在程序中运行以下内容时显示的版本相同吗?
import sys
print sys.version # => '2.7.2 (default, Feb 4 2012, 02:01:30)...