- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
好的,我需要一些有关 pyinstaller 和 PythonNet 的帮助。
这是我第一次在论坛上发帖,我对编码相对缺乏经验,但我已经学习了一些用于 GUI 开发的 python。我有一个使用 .NET dll 库与 USB 摄像头连接的脚本。该脚本在 Python 中运行正常,但我试图通过 Pyinstaller 将其编译为 .exe,但我遇到了困难。
以下是前几行代码:
import os
import clr
import sys
import System
from System import IntPtr
这是运行编译的 .exe 文件后的错误:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembl y 'Python.Runtime, Version=4.0.0.1, Culture=neutral, PublicKeyToken=5000fea6cba7 02dd' or one of its dependencies. The located assembly's manifest definition doe s not match the assembly reference. (Exception from HRESULT: 0x80131040) at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String cod eBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntro spection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String code Base, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& s tackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntros pection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName as semblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMar k& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIn trospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at clrModule.initclr()
我认为 python.runtime 的问题与此处发布的问题类似( https://github.com/pythonnet/pythonnet/issues/34 ),但我已经尝试了推荐的解决方案,但仍然遇到相同的错误。即我卸载了 pythonnet,然后搜索并删除了任何剩余的 clr.pyd 或 python.runtime.dll 文件。然后通过命令提示符使用 pip 重新安装:
"pip install --pre pythonnet"
编译我的脚本后,python.runtime.dll 与 exe 文件一起出现在“dist”文件夹中。但版本号有些奇怪。右键单击 dll 并在 Windows 中查看“属性”,会列出版本为 2.0.0.2,但查看同一文件的程序集信息(使用 dotPeek)会列出为 4.0.0.1。这是怎么回事?
以下是显示版本差异的屏幕截图:
dll assembly screenshot shows version 4.0.0.1
[显示版本 2.0.0.2 的 Windows 属性屏幕截图]
imagizer.imageshack.us/v2/381x520q90/902/6DEzLM.jpg(抱歉,我无法将此链接设为链接)
请注意,我在 Windows 7(64 位)上运行 Python 2.7(32 位)。另外,最初我在编译过程中遇到错误,因为Pyinstaller找不到CLR所需的python.runtime.dll,但我修改了clr-hook.py以包含完整的dll路径,所以现在它编译没有错误,但有些东西显然还是不对。这是新的钩子(Hook):
##hook-clr.py
import ctypes.util
datas = [(ctypes.util.find_library('C:\\Python27\\lib\\site-packages\\Python.Runtime'), '')]
这是编译期间 pyinstaller 的输出:
C:\Users\M80\Desktop\RealTimeBeamAnalysis> pyinstaller Realtime_3_exec.py
219 INFO: wrote C:\Users\M80\Desktop\RealTimeBeamAnalysis\Realtime_3_exe
c.spec
263 INFO: Testing for ability to set icons, version resources...
455 INFO: ... resource update available
462 INFO: UPX is not available.
516 INFO: Processing hook hook-os
697 INFO: Processing hook hook-time
703 INFO: Processing hook hook-cPickle
804 INFO: Processing hook hook-_sre
986 INFO: Processing hook hook-cStringIO
1118 INFO: Processing hook hook-encodings
1137 INFO: Processing hook hook-codecs
2354 INFO: Processing hook hook-httplib
2360 INFO: Processing hook hook-email
2519 INFO: Processing hook hook-email.message
2970 INFO: Processing hook hook-clr
3061 WARNING: library python%s%s required via ctypes not found
3298 INFO: Extending PYTHONPATH with C:\Users\M80\Desktop\RealTimeBeamAn
alysis
3299 INFO: checking Analysis
3299 INFO: building Analysis because out00-Analysis.toc non existent
3299 INFO: running Analysis out00-Analysis.toc
3299 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
3393 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21
022.8_none ...
3394 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.crt_1fc
8b3b9a1e18e3b_9.0.21022.8_none_bcb86ed6ac711f91.manifest
3413 INFO: Searching for file msvcr90.dll
3414 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_
9.0.21022.8_none_bcb86ed6ac711f91\msvcr90.dll
3414 INFO: Searching for file msvcp90.dll
3414 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_
9.0.21022.8_none_bcb86ed6ac711f91\msvcp90.dll
3416 INFO: Searching for file msvcm90.dll
3416 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_
9.0.21022.8_none_bcb86ed6ac711f91\msvcm90.dll
3541 INFO: Analyzing C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.e
gg\PyInstaller\loader\_pyi_bootstrap.py
3562 INFO: Processing hook hook-os
3582 INFO: Processing hook hook-site
3608 INFO: Processing hook hook-encodings
3748 INFO: Processing hook hook-time
3752 INFO: Processing hook hook-cPickle
3840 INFO: Processing hook hook-_sre
3996 INFO: Processing hook hook-cStringIO
4131 INFO: Processing hook hook-codecs
4654 INFO: Processing hook hook-httplib
4657 INFO: Processing hook hook-email
4799 INFO: Processing hook hook-email.message
5021 INFO: Processing hook hook-clr
5094 WARNING: library python%s%s required via ctypes not found
5378 INFO: Processing hook hook-pydoc
5513 INFO: Analyzing C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.e
gg\PyInstaller\loader\pyi_importers.py
5680 INFO: Analyzing C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.e
gg\PyInstaller\loader\pyi_archive.py
5831 INFO: Analyzing C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.e
gg\PyInstaller\loader\pyi_carchive.py
5963 INFO: Analyzing C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_-py2.7.e
gg\PyInstaller\loader\pyi_os_path.py
5982 INFO: Analyzing Realtime_3_exec.py
6026 INFO: Processing hook hook-PyQt4
6038 INFO: Processing hook hook-PyQt4.QtCore
6322 INFO: Processing hook hook-PyQt4.QtGui
8180 INFO: Processing hook hook-matplotlib
8298 INFO: Processing hook hook-PIL
8386 INFO: Processing hook hook-PIL.Image
9391 INFO: Processing hook hook-distutils
9837 INFO: Processing hook hook-parser
10396 INFO: Processing hook hook-sysconfig
10493 INFO: Processing hook hook-xml
10580 INFO: Processing hook hook-xml.sax
10618 INFO: Processing hook hook-pyexpat
11866 INFO: Processing hook hook-setuptools
12416 INFO: Processing hook hook-win32com
12434 INFO: Processing hook hook-win32com.client
12562 INFO: Processing hook hook-pythoncom
12647 INFO: Processing hook hook-pywintypes
12771 INFO: Processing hook hook-win32ui
13937 INFO: Processing hook hook-scipy.special._ufuncs
13979 INFO: Processing hook hook-Image
14680 INFO: Processing hook hook-pycparser
15338 INFO: Processing hook hook-PIL.SpiderImagePlugin
15522 INFO: Processing hook hook-_tkinter
15863 INFO: checking Tree
15865 INFO: building because out00-Tree.toc missing or bad
15866 INFO: building Tree out00-Tree.toc
16239 INFO: checking Tree
16240 INFO: building because out01-Tree.toc missing or bad
16241 INFO: building Tree out01-Tree.toc
16338 INFO: Processing hook hook-scipy.sparse.csgraph
18598 INFO: Processing hook hook-pytz
C:\Python27\lib\site-packages\matplotlib\backends\backend_qt.py:11: MatplotlibDe
precationWarning: QT3-based backends are deprecated and will be removed after th
e v1.2.x release. Use the equivalent QT4 backend instead.
mplDeprecation)
33262 INFO: Processing hook hook-matplotlib.backends
34985 INFO: Processing hook hook-PyQt4.QtOpenGL
34990 INFO: Processing hook hook-PyQt4.QtSvg
35388 INFO: Processing hook hook-anydbm
36676 INFO: Processing hook hook-h5py
40292 INFO: Processing hook hook-IPython
46546 INFO: Processing hook hook-OpenGL
47113 INFO: Processing hook hook-OpenGL_accelerate
49549 INFO: Processing hook hook-zmq
50545 INFO: Processing hook hook-xml.dom
50582 INFO: Processing hook hook-xml.dom.domreg
55157 INFO: Processing hook hook-docutils
56850 INFO: Processing hook hook-pygments
57268 INFO: Processing hook hook-pygments.lexers
57973 INFO: Processing hook hook-pygments.formatters
58388 INFO: Processing hook hook-pygments.styles
60513 INFO: Processing hook hook-sqlite3
62490 INFO: Processing hook hook-lxml.etree
62500 INFO: Processing hook hook-xml.etree.cElementTree
62529 INFO: Processing hook hook-_elementtree
63798 INFO: Hidden import 'codecs' has been found otherwise
63799 INFO: Hidden import 'encodings' has been found otherwise
63799 INFO: Looking for run-time hooks
63805 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_pkgres.py
64029 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_Image.py
64170 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_qt4plugins.py
64285 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_mplconfig.py
64420 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_mpldata.py
64534 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_win32comgenpy.py
64672 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_PIL_Image.py
64797 INFO: Analyzing rthook C:\Python27\lib\site-packages\pyinstaller-2.1.1dev_
-py2.7.egg\PyInstaller\loader\rthooks\pyi_rth_Tkinter.py
70305 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of
final executable
73703 INFO: Adding Microsoft.VC90.MFC to dependent assemblies of final executabl
e
73792 INFO: Searching for assembly x86_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.2
1022.8_none ...
73792 INFO: Found manifest C:\Windows\WinSxS\Manifests\x86_microsoft.vc90.mfc_1f
c8b3b9a1e18e3b_9.0.21022.8_none_b81d038aaf540e86.manifest
73804 INFO: Searching for file mfc90.dll
73804 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b
_9.0.21022.8_none_b81d038aaf540e86\mfc90.dll
73805 INFO: Searching for file mfc90u.dll
73805 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b
_9.0.21022.8_none_b81d038aaf540e86\mfc90u.dll
73805 INFO: Searching for file mfcm90.dll
73805 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b
_9.0.21022.8_none_b81d038aaf540e86\mfcm90.dll
73805 INFO: Searching for file mfcm90u.dll
73807 INFO: Found file C:\Windows\WinSxS\x86_microsoft.vc90.mfc_1fc8b3b9a1e18e3b
_9.0.21022.8_none_b81d038aaf540e86\mfcm90u.dll
84271 INFO: Using Python library C:\Windows\system32\python27.dll
99841 INFO: Warnings written to C:\Users\M80\Desktop\RealTimeBeamAnalysi
s\build\Realtime_3_exec\warnRealtime_3_exec.txt
99993 INFO: checking PYZ
99995 INFO: rebuilding out00-PYZ.toc because out00-PYZ.pyz is missing
99996 INFO: building PYZ (ZlibArchive) out00-PYZ.toc
137450 INFO: checking PKG
137450 INFO: rebuilding out00-PKG.toc because out00-PKG.pkg is missing
137450 INFO: building PKG (CArchive) out00-PKG.pkg
137516 INFO: checking EXE
137518 INFO: rebuilding out00-EXE.toc because Realtime_3_exec.exe missing
137519 INFO: building EXE from out00-EXE.toc
137590 INFO: Appending archive to EXE C:\Users\M80\Desktop\RealTimeBeamA
nalysis\build\Realtime_3_exec\Realtime_3_exec.exe
137690 INFO: checking COLLECT
137690 INFO: building COLLECT out00-COLLECT.toc
最佳答案
拉取请求已通过 clr (pythonnet) 的 Hook 合并到 pyinstaller:
https://github.com/pyinstaller/pyinstaller/pull/2048/files
使用此 clr Hook 的正确方法是从命令行指定 --hidden-import=clr
或在规范文件中指定 hiddenimports=['clr']
。这应该可以找到 Windows 的 Python.Runtime.DLL
隐藏导入。
如果有人愿意解决 Linux 或 OSX 上的捆绑问题,那么请继续!请注意,Mono 并未预安装在这些平台上,因此捆绑可能会变得非常复杂。
关于python - PyInstaller 和 PythonNet CLR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26110026/
使用 pythonnet 从 python 访问一些 dll,无论所有者或权限设置为什么,dll 都无法访问 linux 目录。就像这样收到一条访问被拒绝的消息。 访问路径“/tmp/work”被拒绝
Python代码如下 import pandas as pd # 读取数据 data = pd.read_csv('data_row.csv') # 检查异常值 def detect_ou
我在 windows7 上安装了 64 位 CPython 3.4。我使用 pythonnet 包 (2.0.0.dev1)。我想实例化 Action 委托(delegate),但它给我一个错误。 d
我有一个依赖 NuGet 的应用程序 功能以确保 log4net.dll 的单一版本。绑定(bind)重定向会自动添加到应用程序的 app.config 文件中。 我想将该应用程序的程序集加载到 Py
好的,我需要一些有关 pyinstaller 和 PythonNet 的帮助。 这是我第一次在论坛上发帖,我对编码相对缺乏经验,但我已经学习了一些用于 GUI 开发的 python。我有一个使用 .N
我正在使用 pythonnet 在 python 上尝试简单的 winform 应用程序。但我无法把这件事做好。 import clr clr.AddReference("System.Windows
我正在尝试执行一个 Python 脚本,该脚本使用 Python For .Net ( https://github.com/pythonnet/pythonnet ) 来加载名为“Kratos_3.
我正在使用 Python 脚本和 Pythonnet 来驱动 C# 库。该库在某些事件上触发委托(delegate)方法。我正在注册委托(delegate)方法,但它没有被调用。 相关方法定义为eve
我尝试在 Microsoft Visual Studio 2017 社区中以窗口形式使用 Pythonnet 运行 Visbrain,但我遇到了以下问题。 环境 1) Pythonnet 版本:v2.
我已经安装了 pythonnet 来为特定的 API 使用 clr 包,它只适用于 python 中的 clr。尽管在我的 python 脚本(使用命令或常规 .py 文件)中它可以正常工作,但在 j
我正在使用 pythonnet (http://pythonnet.sf.net) 将 python 框架和 .NET 库绑定(bind)在一起(我知道是不是 IronPython,但这不是问题所在)
我在 win32 上有 Windows 7 x64 和 Python 2.7.6 版。安装的框架是: 微软 .NET 框架 4.5.2Microsoft .NET Framework 4 多目标包。所
我正在尝试使用 pythonnet 将非常简单自定义 C# 类导入到 Python 中。我从未使用过 C# 或 VS,所以这可能是我犯的一些愚蠢的错误。 我有一个可靠的 C# 代码库(不是我编写的),
我正在尝试运行来自 https://github.com/pythonnet/pythonnet 的 Embedding Python in .NET 示例.我已按照故障排除文章将正确的 %PYTHO
我有一个 NET 库,我正在使用 Python 和 PythonNET,但不知道如何将枚举放入列表中。 Python 似乎将枚举转换为不适合 List 数据类型的整数。这是一个例子: import c
我们正在建立从 python 到 .net VB 代码的连接。我们在VB中成功创建了DLL,我们可以使用CLR将它导入到python中。 DLL 中的类已导入,所有方法都可见。然而,当我们调用一个方法
我找不到关于 PythonNET 使用列表的任何答案,列表是一个用于 Python 的包,可让您导入 .NET DLL。出于某种原因,创建 DateTime 列表对我不起作用。 已解决以下是使其工作的
当我使用 PythonNet 从 Python 加载 .Net 类时,它不会填充该类的 python __ dict__ ,但是当我使用相同的命令序列从 ipython 加载它时,它会填充该类。谁能说
我需要在新的 alpine 3.8/python 3.7 容器中安装 pythonnet。我已经为 Ubuntu 完成了它(这里的巨大帮助是 pythonnet 的 dockerfile)。我不能在
我正在尝试开发一个在 .net 中嵌入 python 的简单计算器程序,我想从 NuGet 中引用 pythonnet 以将其包含在我的项目中 我使用 NuGet 安装了 pythonnet v2.3
我是一名优秀的程序员,十分优秀!