关于Python的几个过坑指南(MySQL-python、tornado)
最近碰到的Python项目中,需要安装MySQL-python依赖,并且项目使用tornado,以下是记录在其中碰到的坑。
0x01 tornado在render渲染html页面时报错
访问页面时服务器响应500,查看错误日志,提示:
'utf8' codec can't decode byte 0xbf in position 15:invalid start byte
疑惑了很久文件编码格式等,后来debug跟踪发现错误,是项目路径出现问题,最好不要在包含中文路径中:
snipaste20180809_155405.png
0x02 MySQL-python 1.2.3安装
项目需要使用MySQL-python 1.2.3,然而通过pip安装会一直失败:
snipaste20180809_155857.png
似乎是注册表中找不到某个值
可以通过以下步骤解决:
1、使用要安装的python环境运行此脚本:register.py
#!/usr/bin/env python# -*- coding:utf-8 -*-import sysfrom _winreg import *# tweak as necessaryversion = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath"pythonkey = "PythonPath"pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath )def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!"RegisterPy()
snipaste20180809_160020.png
作者:日生三金
链接:https://www.jianshu.com/p/1d14324eb584
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦