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
sudo 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!
2 个解决方案
#1
12
For BeautifulSoup4 you have to use
对于BeautifulSoup4,你必须使用
from bs4 import BeautifulSoup
Check the document: BS4 document
检查文件:BS4文件
#2
4
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)...
#1
12
For BeautifulSoup4 you have to use
对于BeautifulSoup4,你必须使用
from bs4 import BeautifulSoup
Check the document: BS4 document
检查文件:BS4文件
#2
4
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)...