Cx-Freeze : Showwarning AttributeError: 'NoneType' object has no attribute 'write'

Cx-Freeze : Showwarning AttributeError: 'NoneType' object has no attribute 'write'

脚本在使用 Anaconda 和 Python 3.4 的源文件上运行良好。当我使用以下设置文件 cxfreeze (v 4.3.4) 时:

from cx_Freeze import setup, Executable

setup(executables=[Executable("main.py", base="Win32GUI")], version='0.2')

我在服务器上遇到以下错误:

DBOps.py", line 54, in executemany

"C:\Users\user\Anaconda3\lib\site-packages\MySQLdb\cursors.py", line 286, in executemany File

"FileC:\Users\user\Anaconda3\lib\site-packages\MySQLdb\cursors.py", line 127, in _warning_check File "c:\Python-bit.4\lib\warnings.py",

line 15, in showwarning AttributeError: 'NoneType' object has no attribute 'write'

我认为我的系统上安装的不同 python 版本可能会导致此问题,使用安装程序将其删除。没有改变。服务器和本地计算机上的相同错误。错误的部分看起来像“c:\Python-bit.4\lib\warnings.py”,因为在我的系统或服务器上都没有这样的目录路径。

这是 Thomas Kluyver 的相关解决方案:

The bigger issue there is that anything that attempts to show a warning will cause an error, because by default it tries to write warnings to sys.stderr, and if you use the Win32GUI base, there's no stderr to write to. Calling warnings.simplefilter('ignore') beforehand should prevent that.

来源:https://bitbucket.org/anthony_tuininga/cx_freeze/issues/81/python-34-venv-importlib-attributeerror