问题描述
脚本在使用 Anaconda 和 Python 3.4 的源文件上运行良好.当我使用以下设置文件对其进行 cxfreeze (v 4.3.4) 时:
Scripts works fine on source file with using Anaconda alongside with Python 3.4. When i cxfreeze (v 4.3.4) it with following setup file:
从 cx_Freeze 导入设置,可执行文件
from cx_Freeze import setup, Executable
setup(executables=[Executable("main.py", base="Win32GUI")],版本='0.2')
setup(executables=[Executable("main.py", base="Win32GUI")], version='0.2')
我在服务器上收到以下错误:
I got following error on the server:
DBOps.py",第 54 行,在 executemany 中
DBOps.py", line 54, in executemany
C:UsersuserAnaconda3libsite-packagesMySQLdbcursors.py",行286,在executemany文件中
"C:UsersuserAnaconda3libsite-packagesMySQLdbcursors.py", line 286, in executemany File
FileC:UsersuserAnaconda3libsite-packagesMySQLdbcursors.py",第 127 行,_warning_check 文件c:Python64-bit3.4libwarnings.py",
"FileC:UsersuserAnaconda3libsite-packagesMySQLdbcursors.py", line 127, in _warning_check File "c:Python64-bit3.4libwarnings.py",
第 15 行,在 showwarning AttributeError: 'NoneType' object has no attribute 'write'
line 15, in showwarning AttributeError: 'NoneType' object has no attribute 'write'
我认为我的系统上安装的不同 python 版本可能会导致这个问题,使用安装程序将它们删除.没有改变.服务器和本地机器上的相同错误.错误部分看起来像c:Python64-bit3.4libwarnings.py",因为我的系统或服务器上都没有这样的目录路径.
I thougth different python versions installed on my system might result this problem, removed them by using installer. Nothing changed. Same error on both server and lochal machines. The errorneous part seems like "c:Python64-bit3.4libwarnings.py", since there is no such directory path neither on my system or on server.
推荐答案
以下是 Thomas Kluyver 的相关解决方案:
Here is the relevant solution by Thomas Kluyver:
更大的问题是任何试图显示警告将导致错误,因为默认情况下它会尝试写入sys.stderr 的警告,如果您使用 Win32GUI 基础,则没有要写入的标准错误.事先调用 warnings.simplefilter('ignore')应该防止这种情况发生.
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
这篇关于Cx-Freeze : Showwarning AttributeError: 'NoneType' 对象没有属性 'write'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!