0
我有一个Kivy应用程序,它必须连接到物理设备。 连接和控制设备的代码已经写入.dll文件。 所以我想从.dll文件导入一些函数。导入.dll -s
我设法导入它在Python中。下面是它的代码:
mydll.py:运行将返回[ 'COM3', 'COM4']
import clr
# import dll-s
try:
clr.AddReference("CETAx10_x15")
clr.AddReference("Converter")
clr.AddReference("NLog")
clr.AddReference("ValueDefine")
clr.AddReference("Python.Runtime")
except:
clr.AddReference("cls\\CETAx10_x15")
clr.AddReference("cls\\Converter")
clr.AddReference("cls\\NLog")
clr.AddReference("cls\\ValueDefine")
clr.AddReference("cls\\Python.Runtime")
import CETAx10_x15
import Converter
import NLog
import ValueDefine
import Python.Runtime
import System
def get_openports():
temp = []
output = []
ports_reply = CETAx10_x15.CETA.get_ports(temp)
for elem in ports_reply[1]:
output.append(elem)
return output
print(get_openports())
,所以它做什么它应该。
我的Kivy应用程序运行完美无需导入此mydll.py文件。正如你所看到的[“COM3”,“COM4”]被打印出来
[INFO ] [Logger ] Record log in C:\Mirk\CETACal\logs\kivy_17-03-01_150.txt
[INFO ] [Factory ] 193 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Kivy ] v1.9.2.dev0, git-c6018cc, 20170222
[INFO ] [Python ] v3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
[INFO ] [Logger ] Record log in C:\Mirk\CETACal\logs\kivy_17-03-01_151.txt
[INFO ] [OSC ] using <thread> for socket
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] GLEW initialization succeeded
[INFO ] [GL ] Backend used <glew>
[INFO ] [GL ] OpenGL version <b'4.3.0 - Build 10.18.14.4432'>
[INFO ] [GL ] OpenGL vendor <b'Intel'>
[INFO ] [GL ] OpenGL renderer <b'Intel(R) HD Graphics 4600'>
[INFO ] [GL ] OpenGL parsed version: 4, 3
[INFO ] [GL ] Shading version <b'4.30 - Build 10.18.14.4432'>
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <32>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [EZS-2G ] The system parameters are: ['C:\\Mirk\\CETACal\\main.py']
['COM3', 'COM4']
Traceback (most recent call last):
File "C:\Mirk\CETACal\main.py", line 2708, in <module>
EZS.run()
File "C:\Python34\lib\site-packages\kivy\app.py", line 802, in run
root = self.build()
File "C:\Mirk\CETACal\main.py", line 1745, in build
self.root = Builder.load_file(os.path.join(cls.config.kvPATH, 'root.kv'))
File "C:\Python34\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
return self.load_string(data, **kwargs)
File "C:\Python34\lib\site-packages\kivy\lang\builder.py", line 380, in load_string
self._apply_rule(widget, parser.root, parser.root)
File "C:\Python34\lib\site-packages\kivy\lang\builder.py", line 500, in _apply_rule
rule.canvas_before, rootrule)
File "C:\Python34\lib\site-packages\kivy\lang\builder.py", line 804, in _build_canvas
Instruction = Factory.get('Instruction')
File "C:\Python34\lib\site-packages\kivy\factory.py", line 139, in __getattr__
module = __import__(name=item['module'], fromlist='.')
TypeError: __import__() takes at least 1 argument (0 given)
: 我Kivy应用程序导入此mydll.py将返回以下错误消息。
我的应用程序和“mydll.py”都像一个魅力。 但导入后将失败。
我只是不明白为什么两个独立工作的程序在导入后失败。
我使用: Win7的 蟒蛇3.4 Kivy 1.9.2.devs0(公布:22.02)