突然想看看Webpy, 在网上看到一个篇:在windows下如何快速搭建web.py开发框架
http://www.cnblogs.com/dolphin0520/archive/2013/10/15/3343617.html
但是从github上下载下来后,安装出错:
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 6, in <module>
from web import __version__
File "c:\Python27\webpy-webpy-0.37\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
File "c:\Python27\webpy-webpy-0.37\web\wsgi.py", line 12, in <module>
import httpserver
File "c:\Python27\webpy-webpy-0.37\web\httpserver.py", line 4, in <module>
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "c:\Python27\lib\SimpleHTTPServer.py", line 27, in <module>
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
File "c:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHan
ler
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 0xb0 in position 1: ordinal
not in range(128)
各种搜索找不到解决方案,没办法,自己打开Webpy的setup.py文件一看,原来就一个version的问题
setup.py
#!/usr/bin/env python
# ...
from distutils.core import setup
from web import __version__
setup(name='web.py',
version=__version__,
description='web.py: makes web apps',
author='Aaron Swartz',
author_email='me@aaronsw.com',
maintainer='Anand Chitipothu',
maintainer_email='anandology@gmail.com',
url=' http://webpy.org/',
packages=['web', 'web.wsgiserver', 'web.contrib'],
long_description="Think about the ideal way to write a web app. Write the code to make it happen.",
license="Public domain",
platforms=["any"],
)
明显from web import __version__ 找不到吗,手动给他设置一下,之后安装成功,下面是我手动该的:
#!/usr/bin/env python
# ...
from distutils.core import setup
setup(name='web.py',
version='0.37',
description='web.py: makes web apps',
author='Aaron Swartz',
author_email='me@aaronsw.com',
maintainer='Anand Chitipothu',
maintainer_email='anandology@gmail.com',
url=' http://webpy.org/',
packages=['web', 'web.wsgiserver', 'web.contrib'],
long_description="Think about the ideal way to write a web app. Write the code to make it happen.",
license="Public domain",
platforms=["any"],
)
好啦,安装成功,我是在Git Bash下装的,cmd没试,因为看到很多人说要用Cygwin
如果上面的看完你安装成功了,说名你是个新手,我也是个新手,那么我们该写hello world啦。代码满天飞,就不写啦,但是你运行又出错啦:
$ python hello.py
Traceback (most recent call last):
File "hello.py", line 1, in <module>
import web
File "c:\Python27\lib\site-packages\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
File "c:\Python27\lib\site-packages\web\wsgi.py", line 12, in <module>
import httpserver
File "c:\Python27\lib\site-packages\web\httpserver.py", line 4, in <module>
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "c:\Python27\lib\SimpleHTTPServer.py", line 27, in <module>
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
File "c:\Python27\lib\SimpleHTTPServer.py", line 208, in SimpleHTTPRequestHand
ler
mimetypes.init() # try to read system mime.types
File "c:\Python27\lib\mimetypes.py", line 362, in init
db.read_windows_registry()
File "c:\Python27\lib\mimetypes.py", line 262, 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 0xb0 in position 1: ordinal
not in range(128)
如果你像我一样马虎,只能说我们都找错了地方,其实web.py的setup.py没有问题,你应该仔细看到最下面的error
File "c:\Python27\lib\mimetypes.py", line 262, 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 0xb0 in position 1: ordinal
not in range(128)
是的,是编码问题,于是我们又搜索到了另一个人的解决方案
解决UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128
http://blog.youkuaiyun.com/mindmb/article/details/7898528
非常好,我们好像找到原因啦,但是他没有写的那么清楚,实际上你应该看下一个搜索结果:
setuptools,pip,install,UnicodeDecodeError: 'ascii' codec can't decode byte.原因和解决方案
http://blog.youkuaiyun.com/hugleecool/article/details/17996993
解决方法:打开C:\Python27\Lib下的 mimetypes.py 文件,找到大概256行(你可以用Notepad++的搜索功能)的
‘default_encoding = sys.getdefaultencoding()’。
在这行前面添加三行:
if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
default_encoding = sys.getdefaultencoding()
现在你可以python hello.py啦,经过不懈的努力的搜索,我们终于找到原因啦,看到下面的截图,恭喜你啦。(不想让你见笑,这是我的一次写python)
瞬间感慨网上贡献的重要!