在64位機器上,且使用64位python,pip install PyAutoIt的過程
中,可能會報如下錯誤:
File "c:\program files\python37\lib\ctypes\__init__.py", line 356, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 193] %1 不是有效的 Win32 應用程序。 ----------------------------------------
解決方法:
手動下載pyautoit:https://pypi.org/project/PyAutoIt/
解壓將其保存到本地...\Python37\Lib\site-packages\ 中,此目錄為Python安裝包存放目錄。
將autoit文件夾中的autoit.py文件打開,將
dll = "AutoItX3.dll"
改為
dll = "AutoItX3_x64.dll"
保存完成,運行
python setup.py install
即可
原因:
可以注意到,在剛才改過代碼下面,有一個if判斷:
bit, _ = platform.architecture() if "(x86)" in os.environ['PROGRAMFILES'] and bit == "64bit": # if 64bit version of python within 64bit version of Windows, # load AutoItX3_x64.dll dll = "AutoItX3_x64.dll"
在交互式命令行中運行:
os.environ['PROGRAMFILES']
會發現結果是:
C:\Program Files
32位系統是:
C:\Program Files (x86)
所以問題應該出if的第一個條件中,大概率是作者的源碼寫錯了,導致在64位平台下無法正確引用對應位數的dll
參考文檔:
鏈接:https://www.jianshu.com/p/0d7415bab999