[note] 安裝 windows 的 pip error

客戶端用 windows 2003 server

下載了 active python ,也安裝了 pip ,與一些 windows 下需要用安裝檔案的套件。

pip install -r requirements/我的相依套件檔案

立馬出現錯誤。

Exception:
Traceback (most recent call last):
File "c:\python27\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "c:\python27\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "c:\python27\lib\site-packages\pip\req.py", line 1229, in prepare_files
req_to_install.run_egg_info()
File "c:\python27\lib\site-packages\pip\req.py", line 292, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "c:\python27\lib\site-packages\pip\req.py", line 265, in setup_py
import setuptools
File "c:\python27\lib\site-packages\setuptools\__init__.py", line 12, in
from setuptools.extension import Extension
File "c:\python27\lib\site-packages\setuptools\extension.py", line 7, in
from setuptools.dist import _get_unpatched
File "c:\python27\lib\site-packages\setuptools\dist.py", line 16, in
from setuptools.compat import numeric_types, basestring
File "c:\python27\lib\site-packages\setuptools\compat.py", line 19, in
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
File "C:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHandler
mimetypes.init() # try to read system mime.types
File "C:\Python27\lib\mimetypes.py", line 358, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 258, in read_windows_registry
for subkeyname in enum_types(hkcr):
File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa4 in position 9: ordinalnot in range(128)

Storing debug log for failure in C:\Documents and Settings\Administrator\pip\pip.log

於是只好先把 codign 的環境也裝一下,然後來看看是甚麼問題,拜了幾次大神終於下對了關鍵字,果然是與 Windows 的預設語系有關係,遙想 server 2003 的年代,算了,別想,改來就對了,找到 C:/Python27/lib/mimetypes.py 當中的
default_encoding = sys.getdefaultencoding()

把環境語系直接給定
if sys.getdefaultencoding() != 'big5':
    reload(sys)
    sys.setdefaultencoding('big5')
default_encoding = sys.getdefaultencoding()

接者繼續安裝套件囉!

張貼留言

2 留言

匿名表示…
試了好幾種方法只有這個有效,謝謝
Draq寫道…
這個問題我也找了頗久~
最後癥結就是那個 window server 2003 已經很久遠,所以很多套件更新都不會管它了Orz