Python for Mac 安装 beautifulsoup select报错

#Python3# Beautifulsoup Mac安装解决办法?[自问自答已解决]
学marketing的时候,一个助教上了一个tutorial,讲了如何爬网站从好更好的进行business insight的工作,绚丽的数据让我一下子被吸引进了python语言。而此问题在于解决如何在mac Python3.x的框架下安装package例如beautifulsoup。参考Jackman的博客,并进行了实际操作,由于是电脑小白,如果有比我更简易的操作,请各位大神指点迷津。首先从package的网站上下载最新版的package http://然后你会得到一个压缩包名叫beautifulsoup4-4.4.1.tar.gz。解压至桌面(楼主为了方便输入路径)接着打开终端,开始切换至解压的文件夹cd Desktopcd beautifulsoup4-4.4.1接着告诉python给老子安上这个packagesudo python ./setup.py install大功告成~非常欢迎一起学习的小白进行交流祖国母亲生日快乐,雄起
按投票排序
pip安装不会更方便吗...
为嘛不用pip先装 pip 打开terminal 输入 sudo easy_install pip然后装bs4 同样 在terminal 输入 pip install beautifulsoup4
依题主的方式搞定,只是有一些小变动。Python改为Python3接着打开终端,开始切换至解压的文件夹
cd Desktop
cd beautifulsoup4-4.4.1
接着告诉python给老子安上这个package
sudo python3 ./setup.py install
而且这Python且是不能通过brew方式安装的,通过官网下载的pkg文件安装在原始目录下。这里提供 另外一种思路来安装进入Python3的目录。如果是从官网上下载的PKG文件安装,一般路径是这样的。cd /Library/Frameworks/Python.framework/Versions/3.5/bin
版本号根据你下载的版本来确定,如果不确定也可以通过cd /Library/Frameworks/Python.framework/Versions/
来确定,在bin目录下查找合适你版本的pip文件名。如我的版本号下是pip3 还有 pip3.5。然后执行pip3.5 install beautifulsoup4
xxxx:bin xxxx$ pip3.5 install beautifulsoup4Collecting beautifulsoup4
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. (read timeout=15)",)': /simple/beautifulsoup4/
Downloading beautifulsoup4-4.4.1-py3-none-any.whl (81kB)
100% |████████████████████████████████| 81kB 392kB/s Installing collected packages: beautifulsoup4Successfully installed beautifulsoup4-4.4.1可以愉快的玩耍了
按照你的方法安装完
导入的时候 ImportError: No module named 'bs4'
已有帐号?
无法登录?
社交帐号登录How to re-install lxml? [如何安装lxml ?] - 问题-字节技术
How to re-install lxml?
如何安装lxml ?
问题 (Question)
I am using python 2,7.5 on mac 10.7.5, beautifulsoup 4.2.1. I am going to parse a xml page using the lxml library, as taught in the beautifulsoup tutorial. However, when I run my code, it shows
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
lxml,xml. Do you need to install a parser library?
I am sure that I already installed lxml by all methods: easy_install, pip, port, etc. I tried to add a line to my code to see if lxml is installed or not:
import lxml
Then python can just successfully go through this code and display the previous error message again, occurring at the same line.
So I am quite sure that lxml was installed, but not installed correctly. So I decided to uninstall lxml, and then re-install using a 'correct' method. But when I type in
easy_install -m
Searching for lxml
Best match: lxml 3.2.1
Processing lxml-3.2.1-py2.7-macosx-10.6-intel.egg
Using /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-
3.2.1-py2.7-macosx-10.6-intel.egg
Because this distribution was installed --multi-version, before you can
import modules from this package in an application, you will need to
'import pkg_resources' and then use a 'require()' call similar to one of
these examples, in order to select the desired version:
pkg_resources.require("lxml")
# latest installed version
pkg_resources.require("lxml==3.2.1")
# this exact version
pkg_resources.require("lxml&=3.2.1")
# this version or higher
Processing dependencies for lxml
Finished processing dependencies for lxml
So I don't know how to continue my uninstall...
I looked up many posts about this issue on google but still I can't find any useful info.
Here is my code:
import mechanize
from bs4 import BeautifulSoup
import lxml
class count:
def __init__(self,protein):
self.proteinCode = protein
self.br = mechanize.Browser()
def first_search(self):
soup = BeautifulSoup(self.br.open("http://www.ncbi.nlm.nih.gov/protein/?report=genbank&log$=prottop&blast_rank=1&RID=YGJHMSET015"), ['lxml','xml'])
if __name__=='__main__':
proteinCode = sys.argv[1]
gogogo = count(proteinCode)
I want to know:
How can I uninstall lxml?
How can I install lxml 'correctly'? How do I know that it is correctly installed?
我使用python 2,7.5 mac 10.7.5 beautifulsoup 4.2.1。准备我要去解析一个xml页面使用lxml库,beautifulsoup教的教程。然而,当我运行我的代码,会表现出来的bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
lxml,xml. Do you need to install a parser library?
我相信我已经安装lxml的方法:easy_install,皮普,端口,等等。我试图添加一行代码,看看lxml是否安装:import lxml
然后python可以成功地通过这段代码并再次显示以前的错误消息,发生在同一路线。所以我很确定,lxml安装,但没有正确安装。所以我决定卸载lxml,然后重新安装使用“正确”的方法。但是当我输入easy_install -m
它显示:Searching for lxml
Best match: lxml 3.2.1
Processing lxml-3.2.1-py2.7-macosx-10.6-intel.egg
Using /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-
3.2.1-py2.7-macosx-10.6-intel.egg
Because this distribution was installed --multi-version, before you can
import modules from this package in an application, you will need to
'import pkg_resources' and then use a 'require()' call similar to one of
these examples, in order to select the desired version:
pkg_resources.require("lxml")
# latest installed version
pkg_resources.require("lxml==3.2.1")
# this exact version
pkg_resources.require("lxml&=3.2.1")
# this version or higher
Processing dependencies for lxml
Finished processing dependencies for lxml
所以我不知道如何继续卸载…我在谷歌上查找很多关于这个问题的帖子但我仍然找不到任何有用的信息。这是我的代码:import mechanize
from bs4 import BeautifulSoup
import lxml
class count:
def __init__(self,protein):
self.proteinCode = protein
self.br = mechanize.Browser()
def first_search(self):
soup = BeautifulSoup(self.br.open("http://www.ncbi.nlm.nih.gov/protein/?report=genbank&log$=prottop&blast_rank=1&RID=YGJHMSET015"), ['lxml','xml'])
if __name__=='__main__':
proteinCode = sys.argv[1]
gogogo = count(proteinCode)
我想知道:我怎样才能卸载lxml呢?我怎么能安装lxml‘正确的’吗?我如何知道它是正确安装?
最佳答案 (Best Answer)
I am using BeautifulSoup 4.3.2 and OS X 10.6.8. I also have a problem with improperly installed lxml. Here are some things that I found out:
First of all, check this related question:
Now, in order to check which builders for BeautifulSoup 4 are installed, try
&&& import bs4
&&& bs4.builder.builder_registry.builders
If you don't see your favorite builder, then it is not installed, and you will see an error as above ("Couldn't find a tree builder...").
Also, just because you can import lxml, doesn't mean that everything is perfect.
&&& import lxml
&&& import lxml.etree
To understand what's going on, go to the bs4 installation and open the egg (tar -xvzf). Notice the modules bs4.builder. Inside it you should see files such as _lxml.py and _html5lib.py. So you can also try
&&& import bs4.builder.htmlparser
&&& import bs4.builder._lxml
&&& import bs4.builder._html5lib
If there is a problem, you will see, why a parricular module cannot be loaded. You can notice how at the end of builder/__init__.py it loads all those modules and ignores whatever was not loaded:
# Builders are registered in reverse order of priority, so that custom
# builder registrations will take precedence. In general, we want lxml
# to take precedence over html5lib, because it's faster. And we only
# want to use HTMLParser as a last result.
from . import _htmlparser
register_treebuilders_from(_htmlparser)
from . import _html5lib
register_treebuilders_from(_html5lib)
except ImportError:
# They don't have html5lib installed.
from . import _lxml
register_treebuilders_from(_lxml)
except ImportError:
# They don't have lxml installed.
我用BeautifulSoup 4.3.2和OS x10.6.8。我也安装了不正确的问题lxml。这里有一些事情,我发现:首先,检查相关的问题:现在,为了检查哪些建筑商BeautifulSoup 4安装,试一试&&& import bs4
&&& bs4.builder.builder_registry.builders
本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:

我要回帖

更多关于 beautifulsoup4 的文章

 

随机推荐