【发布时间】:2020-08-21 09:31:23
【问题描述】:
我正在尝试使用 pythonnet clr 和 cx_freeze 构建一个应用程序,我已经使用 pyinstaller 成功构建了它,所以我知道它可以工作,但是当我使用 cx_freeze 并尝试启动 .exe 时收到以下错误:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the
target of an invocation. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: key
at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at Python.Runtime.Runtime.InitializePlatformData()
at Python.Runtime.Runtime.Initialize(Boolean initSigs)
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs)
at Python.Runtime.PythonEngine.InitExt()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at clrModule.PyInit_clr()
我的 setup.py 如下:
from cx_Freeze import setup, Executable
import sys
import matplotlib
import site
from mypackage import version
mpl_toolkits = site.getsitepackages()[1] + '/mpl_toolkits'
def getTargetName():
"""OS specific name for application"""
app_name = "myapp"
if sys.platform.startswith('linux'):
return app_name
elif sys.platform.startswith('win'):
return app_name + ".exe"
else:
return app_name + ".dmg"
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os", 'sys', 'pyqt5', 'serial.win32', 'numpy', 'pubsub', 'mypackage', 'clr'],
"includes": [],
"include_files": [(matplotlib.get_data_path(), "mpl-data"),
(matplotlib.get_data_path(),
"matplotlib.backends.backend_qt5agg"),
(matplotlib.get_data_path(), "matplotlib.figure"),
(matplotlib.get_data_path(), "matplotlib.dates"),
(mpl_toolkits, "mpl_toolkits")],
"excludes": ["tkinter", "matplotlib.tests", "numpy.random._examples"]}
# GUI applications require a different base on Windows (the default is for a console application).
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(name="myapp",
version=version.VERSION,
description="application",
options={"build_exe": build_exe_options},
executables=[Executable("mypackage/main.py",
icon="mypackage/logo.ico",
shortcutName="my app",
shortcutDir="DesktopFolder",
targetName=getTargetName(),
base=base)])
在添加 pythonnet clr 组件之前,我已经成功构建了应用程序,任何见解将不胜感激
【问题讨论】:
标签: python clr cx-freeze python.net