Windows8下安装Python的BeautifulSoup
程序员文章站
2023-11-23 18:49:52
运行环境:windows 8.1
python:2.7.6
在安装的时候,我使用的pip来进行安装,命令如下:
复制代码 代码如下:
pip install bea...
运行环境:windows 8.1
python:2.7.6
在安装的时候,我使用的pip来进行安装,命令如下:
复制代码 代码如下:
pip install beautifulsoup4
运行的时候,报错如下:
复制代码 代码如下:
exception:
traceback (most recent call last):
file "j:\program files (x86)\python\python27\lib\site-packages\pip\basecomm
.py", line 122, in main
status = self.run(options, args)
file "j:\program files (x86)\python\python27\lib\site-packages\pip\commands
stall.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bu
e=self.bundle)
file "j:\program files (x86)\python\python27\lib\site-packages\pip\req.py",
ne 1229, in prepare_files
req_to_install.run_egg_info()
file "j:\program files (x86)\python\python27\lib\site-packages\pip\req.py",
ne 292, in run_egg_info
logger.notify('running setup.py (path:%s) egg_info for package %s' % (sel
etup_py, self.name))
file "j:\program files (x86)\python\python27\lib\site-packages\pip\req.py",
ne 265, in setup_py
import setuptools
file "build\bdist.win-amd64\egg\setuptools\__init__.py", line 11, in <modul
from setuptools.extension import extension
file "build\bdist.win-amd64\egg\setuptools\extension.py", line 5, in <modul
file "build\bdist.win-amd64\egg\setuptools\dist.py", line 15, in <module>
file "build\bdist.win-amd64\egg\setuptools\compat.py", line 19, in <module>
file "j:\program files (x86)\python\python27\lib\simplehttpserver.py", line
, in <module>
class simplehttprequesthandler(basehttpserver.basehttprequesthandler):
file "j:\program files (x86)\python\python27\lib\simplehttpserver.py", line
8, in simplehttprequesthandler
mimetypes.init() # try to read system mime.types
file "j:\program files (x86)\python\python27\lib\mimetypes.py", line 358, i
nit
db.read_windows_registry()
file "j:\program files (x86)\python\python27\lib\mimetypes.py", line 258, i
ead_windows_registry
for subkeyname in enum_types(hkcr):
file "j:\program files (x86)\python\python27\lib\mimetypes.py", line 249, i
num_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
unicodedecodeerror: 'ascii' codec can't decode byte 0xb0 in position 1: ordin
not in range(128)
storing debug log for failure in c:\users\administrator\pip\pip.log
解决方法:打开c:\python27\lib下的 mimetypes.py 文件,找到大概256行的
复制代码 代码如下:
default_encoding = sys.getdefaultencoding()
改成:
复制代码 代码如下:
if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
default_encoding = sys.getdefaultencoding()
安装成功后,验证是否安装成功:
复制代码 代码如下:
c:\users\administrator>python
python 2.7.6 (default, nov 10 2013, 19:24:24) [msc v.1500 64 bit (amd64)] on 32
type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import beautifulsoup
>>> exit()
如果“from bs4 import beautifulsoup”没有报错的话,则说明安装成功,否则,将报类似错误如下:
复制代码 代码如下:
traceback (most recent call last):
file "<stdin>", line 1, in <module>
importerror: no module named bs4
推荐阅读
-
Python依赖文件requirements.txt的生成和安装
-
在Mac OS的PHP环境下安装配置MemCache的全过程解析
-
python3下实现搜狗AI API的代码示例
-
python通过安装itchat包实现微信自动回复收到的春节祝福
-
Python下rrdtool模块的基本使用方法
-
Windows8下mysql 5.6.15 安装配置方法图文教程
-
Windows下python2.7.8安装图文教程
-
Windows下Python使用Pandas模块操作Excel文件的教程
-
在Mac OS系统上安装Python的Pillow库的教程
-
Windows环境下安装PHP Pear的方法图文教程