当从cmd、powershell或cygwin运行而在gitbash中工作时,Python无法加载dll

2024-04-26 14:03:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个64位dll“tdjson.dll“(telegram tdlib),我想从python项目中使用它。 问题是,当我从CMD、PowerShell、Cygwin或gitbash以外的任何其他终端运行代码时,python无法导入DLL。运行我的代码的唯一方法是从gitforwindows附带的gitbash终端执行它。你知道吗

以下是Mingw64和CMD的日志:

usrname@pcname MINGW64 /e/projects/tele (master)
$ where python
C:\Users\usrname\AppData\Local\Programs\Python\Python37\python.exe

usrname@pcname MINGW64 /e/projects/tele (master)
$ python -i
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> CDLL("tdjson.dll")
<CDLL 'tdjson.dll', handle 7ffd19a70000 at 0x2939d19b0b8>
>>>

E:\projects\tele>where python
C:\Users\usrname\AppData\Local\Programs\Python\Python37\python.exe

E:\projects\tele>python -i
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> CDLL("tdjson.dll")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\usrname\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application
>>>

Tags: cmd终端localctypesusersappdataprojectsdll