一: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)槟愕挠脩裘麨橹形?,所以用戶名最好設(shè)置為英文??捎糜浭卤拘薷腜ython35\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ù)庫報(bào)錯(cuò)
當(dāng)出現(xiàn)編碼格式不正確或者類似表情類的字符會(huì)報(bào)錯(cuò)。需要進(jìn)行以下操作:
1、修改連接時(shí)使用的編碼格式
connect(... charset='utf8mb4')
2、修改庫表字段(按情況而定)
alter database 庫名 default character set 字符集;
alter table 表名 convert to character set 字符集;
alter table 表名 modify 字段名 字段屬性 character set 字符集;