不能使用ctypes加载库

时间:2018-05-01 00:19:40

标签: python dll ctypes

我是python的新手,我正在尝试使用PyCharm运行代码 第一段代码是加载一个dll文件

# python version >= 2.5
import sys,os
import time
import ctypes

from ctypes import *

try :
    if sys.platform.startswith('win32'):
        print 'we are in windows'
        libEDK = cdll.LoadLibrary("edk.dll")
    if sys.platform.startswith('linux'):
        srcDir = os.getcwd()    
        libPath = srcDir + "/libedk.so.1.0.0"        
        libEDK = CDLL(libPath)
except :
    print 'Error : cannot load dll lib' 

与dll文件位于同一文件夹中的代码文件,但我仍然得到异常

Error : cannot load dll lib

输出如下:

C:\Python27\python.exe "C:/Users/shehab/Downloads/Emotiv premium libraries v3.0.0.41/Examples/EpocExamples/examples_Python/emoStateLoger.py"
we are in windows
Traceback (most recent call last):
Error : cannot load dll lib
  File "C:/Users/shehab/Downloads/Emotiv premium libraries v3.0.0.41/Examples/EpocExamples/examples_Python/emoStateLoger.py", line 22, in <module>
    EE_EmoEngineEventCreate = libEDK.EE_EmoEngineEventCreate
NameError: name 'libEDK' is not defined

Process finished with exit code 1

任何线索?

0 个答案:

没有答案