Running Environment: Windows 8.1
Python: 2.7.6
During installation, I use pip for installation. The command is as follows:
Pip install beautifulsoup4
When running, the following error is reported:
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\commandsstall.py", line 278, in run requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bue=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' % (seletup_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", line8, in SimpleHTTPRequestHandler mimetypes.init() # try to read system mime.types File "J:\Program Files (x86)\Python\Python27\lib\mimetypes.py", line 358, init db.read_windows_registry() File "J:\Program Files (x86)\Python\Python27\lib\mimetypes.py", line 258, iead_windows_registry for subkeyname in enum_types(hkcr): File "J:\Program Files (x86)\Python\Python27\lib\mimetypes.py", line 249, inum_types ctype = ctype.encode(default_encoding) # omit in 3.x!UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 1: ordinnot in range(128)Storing debug log for failure in C:\Users\Administrator\pip\pip.log
Solution: Open the mimetypes. py file under C: \ Python27 \ Lib and find
default_encoding = sys.getdefaultencoding()
Changed:
if sys.getdefaultencoding() != 'gbk': reload(sys) sys.setdefaultencoding('gbk')default_encoding = sys.getdefaultencoding()
After the installation is successful, verify whether the installation is successful:
C:\Users\Administrator>pythonPython 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on 32Type "help", "copyright", "credits" or "license" for more information.>>> from bs4 import BeautifulSoup>>> exit()
If no error is reported for "from bs4 import BeautifulSoup", the installation is successful. Otherwise, a similar error is reported as follows:
Traceback (most recent call last): File "<stdin>", line 1, in <module>ImportError: No module named bs4
Original article address: Former Civil Engineer
Reprinted please indicate the source: http://www.cnblogs.com/hongfei/p/3763184.html