一:win10白嘁,python2 終端pip install 時(shí)報(bào)錯(cuò):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 7: ordinal not in range(128)
解決方法:在Python27\Lib 下 新建sitecustomize.py 文件朝扼,鍵入內(nèi)容
import sys
sys.setdefaultencoding('gb2312')
二:windows10庆冕,打包python程序成exe
使用pyinstaller (程序中使用了pyqt5眠砾,lxml)
方案一:python2安裝提示沒有此包,需要進(jìn)行pip install python-qt5
最終執(zhí)行程序時(shí)俐东,提示不是可用的win32程序鲸阔,未解決。
方案二:python3(這里用了python3.6+安裝pyinstaller時(shí)報(bào)錯(cuò))建議使用低版本的python3(3.5以下的版本安裝pyqt5依賴時(shí)艺智,需要安裝VC++ 10.0以上
https://support.microsoft.com/zh-cn/help/2977003/the-latest-supported-visual-c-downloads
)倘要;由于使用了lxml,所以需要使用python3.5+力惯。這里使用的python3.5.4碗誉,安裝其他包完美解決~
注:當(dāng)用pyinstaller時(shí),可能會(huì)報(bào)錯(cuò)(Non-UTF-8 code starting with...),這是因?yàn)槟愕挠脩裘麨橹形母妇В杂脩裘詈迷O(shè)置為英文哮缺。可用記事本修改Python35\Scripts\pyinstaller-script.py文件甲喝,最前面加上# -- coding:utf-8 --即可尝苇。
發(fā)現(xiàn)重大bug,現(xiàn)網(wǎng)上很多答案并不能解決此問題。
錯(cuò)誤:Cannot find existing PyQt5 plugin directories
解決:pyinstaller 你的文件 --exclude-module PyQt5
其余參數(shù):-w 不顯示命令行窗口
-i 為main.exe指定圖標(biāo)(必須為.ico結(jié)尾)
-F 生成one-file的程序
三:python程序插入數(shù)據(jù)庫(kù)報(bào)錯(cuò)
當(dāng)出現(xiàn)編碼格式不正確或者類似表情類的字符會(huì)報(bào)錯(cuò)糠溜。需要進(jìn)行以下操作:
1淳玩、修改連接時(shí)使用的編碼格式
connect(... charset='utf8mb4')
2、修改庫(kù)表字段(按情況而定)
alter database 庫(kù)名 default character set 字符集;
alter table 表名 convert to character set 字符集;
alter table 表名 modify 字段名 字段屬性 character set 字符集;