Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PyInstaller和PythonNet CLR_Python_.net_Clr_Pyinstaller_Python.net - Fatal编程技术网

PyInstaller和PythonNet CLR

PyInstaller和PythonNet CLR,python,.net,clr,pyinstaller,python.net,Python,.net,Clr,Pyinstaller,Python.net,好的,我需要一些关于pyinstaller和PythonNet的帮助 这是我第一次在论坛上发帖,我在编码方面相对缺乏经验,但我一直在学习一些用于GUI开发的python。我有一个使用.NETDLL库与USB摄像头接口的脚本。该脚本在Python中正常运行,但我正试图通过Pyinstaller将其编译为.exe,我被卡住了 以下是前几行代码: import os import clr import sys import System from System import IntPtr 以下是运行

好的,我需要一些关于pyinstaller和PythonNet的帮助

这是我第一次在论坛上发帖,我在编码方面相对缺乏经验,但我一直在学习一些用于GUI开发的python。我有一个使用.NETDLL库与USB摄像头接口的脚本。该脚本在Python中正常运行,但我正试图通过Pyinstaller将其编译为.exe,我被卡住了

以下是前几行代码:

import os
import clr
import sys
import System
from System import IntPtr
以下是运行编译的.exe文件后的错误:

未处理的异常:System.IO.FileLoadException:无法加载文件或程序集 y'Python.Runtime,版本=4.0.0.1,区域性=neutral,PublicKeyToken=5000fea6cba7 02dd'或其依赖项之一。定位程序集的清单定义doe s与程序集引用不匹配。(来自HRESULT的异常:0x8013100) 在System.Reflection.RuntimeAssembly.\u nLoad(AssemblyName文件名,字符串cod eBase、证据汇编安全性、运行时汇编位置提示、堆栈爬网标记& stackMark、IntPtr pPrivHostBinder、布尔throwOnFileNotFound、布尔forIntro 检查,布尔抑制(安全检查) 位于System.Reflection.RuntimeAssembly.nLoad(AssemblyName文件名,字符串代码 基本、证据汇编安全性、运行时汇编位置提示、堆栈爬网标记&s tackMark,IntPtr pPrivHostBinder,布尔throwOnFileNotFound,布尔forIntros 透视、布尔抑制(安全检查) 位于System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName为 semblyRef、证据汇编安全性、运行时汇编请求汇编、堆栈爬网 k&stackMark、IntPtr pPrivHostBinder、布尔throwOnFileNotFound、布尔forIn t检查、布尔抑制安全检查) 在System.Reflection.Assembly.Load处(AssemblyName assemblyRef) 在clrModule.initclr()处

我认为python.runtime的问题类似于此处发布的问题(),但我已经尝试了推荐的解决方案,仍然会遇到相同的错误。i、 我卸载了pythonnet,然后搜索并删除了所有剩余的clr.pyd或python.runtime.dll文件。然后通过命令提示符使用pip重新安装:

“pip安装--pythonnet之前”

编译脚本后,python.runtime.dll将与exe文件一起显示在“dist”文件夹中。但是版本号有点奇怪。右键单击dll并在windows中查看“属性”会将版本列为2.0.0.2,但查看同一文件的程序集信息(使用dotPeek)会将其列为4.0.0.1。这是怎么回事

以下是显示版本差异的屏幕截图:

[显示版本2.0.0.2的windows属性屏幕截图]

imagizer.imageshack.us/v2/381x520q90/902/6DEzLM.jpg (抱歉,我无法将此链接设为链接)

请注意,我正在Windows7(64位)上运行Python 2.7(32位)。另外,最初我在编译过程中出错,因为Pyinstaller找不到CLR所需的python.runtime.dll,但我修改了CLR-hook.py以包含完整的dll路径,所以现在它编译时没有错误,但显然还是有问题。这是新的钩子:

    ##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)将拉动请求合并到pyinstaller:

使用此clr钩子的正确方法是从命令行指定
--hidden import=clr
,或在spec文件中指定
hiddenimports=['clr']
。 这将负责查找
Python.Runtime.DLL
隐藏的Windows导入


如果有人愿意解决Linux或OSX上的捆绑问题,那么请继续!请注意,这些平台上没有预装Mono,因此捆绑可能会变得非常复杂。

您有过这样的工作吗?我很想知道怎么做。我确实有这个问题,但对于py2exe而不是pyInstaller-有任何解决方案吗?pyInstaller是否生成dist文件夹中的Python.Runtime.dll?@boileau请看下面我的答案