Importerror dll load failed 1 не является приложением win32
I'm setting up an autoclicker in Python 3.8 and I need win32api for GetAsyncKeyState but it always gives me this error:
I'm on Windows 10 Home 64x. I've already tried
And it successfully installs but nothing changes. I tried uninstalling and re-installing python as well. I also tried installing 'django' in the same way and it actually works when I import django , so I think it's a win32api issue only.
I expect the output to be none, but the actual output is always that error ^^
Make sure you don't have a dependency conflict! I installed pywin32 via pip and it conflicted with my Conda installation.
24 Answers 24
pseudopunit commented Sep 1, 2020
Ketki-Savle commented Sep 27, 2018
conda update --all resolved this for me.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Тем не менее, все, что я бегу, это 64 бит. Я нахожусь на win7 64 бит, у меня есть winpython 2.7.3.3, распределение в 64 бита, и я скомпилировал opencv в 64 бита с предоставленной инструкцией здесь и поместил dll cv2.pyd в папку lib / site-packages на python.
К сожалению, предложение использовать 32-битную версию Python больше не работает для меня, так как мне приходится обрабатывать массивы слишком большие для 32-битных.
Единственное, чего не хватало, это добавить новый путь двоичных файлов opencv (C: \ opencv \ build \ bin \ Release) в переменную среды Windows PATH, перезапустить python.
Кажется, теперь все работает нормально!
Эта проблема была решена путем добавления пути двоичных файлов opencv к переменной среды Windows PATH (например, на моем компьютере этот путь: C: \ opencv \ build \ bin \ Release).
Вы можете попробовать установить 32-битную версию opencv
Или вам нужно пересобрать модуль cv2 для win 64bit.
Все, что вам нужно сделать, это скопировать файл cv2.pyd из папки x86 (например, C: \ opencv \ build \ python \ 2.7 \ x86 \ ) в C: \ Python27 \ Lib \ site-packages \ , а не из папки x64.
Надеюсь, это вам поможет.
Эта ошибка может также появиться, когда версии Python смешаны:
Например, если какая-либо загружаемая DLL была скомпилирована с использованием python 2.7.16, и вы пытаетесь импортировать с python 2.7.15, эта ошибка ImportError: DLL load failed: %1 is not a valid Win32 application. выдается.
По крайней мере, это то, что я обнаружил в моем случае.
Я просто нажал на это, и проблема заключалась в том, что пакет был когда-то установлен в каталоге пакетов для каждого пользователя. (В Windows.) Aka% AppData% \ Python. Поэтому Python сначала искал там, находил старую 32-битную версию файла .pyd и терпел неудачу с указанной ошибкой. К сожалению, pip uninstall само по себе было недостаточно для очистки, и в настоящее время pip 10.0.1, похоже, не имеет параметра --user для удаления, только для установки.
Tl; dr Удаление старого .pyd из% AppData% \ python \ python27 \ site-packages решило эту проблему для меня.
Когда у меня была эта ошибка, она исчезла после того, как мой компьютер вышел из строя и перезагрузился. Попробуйте закрыть и снова открыть IDE, если это не сработает, попробуйте перезагрузить компьютер. Я только что установил библиотеки, не перезапуская pycharm, когда получил эту ошибку.
Никогда не закрывайте PyCharm первым, чтобы протестировать, потому что мой взорванный компьютер продолжает зависать случайным образом . работая над этим, но это по крайней мере решило эту проблему . маленькие победы .. :).
CartoonProgrammers commented Sep 22, 2020 •
use this command then your kernel will be running: pip install -- pywin32==227 and also dont forget to use this in anaconda powershell prompt
Abeni18 commented Aug 29, 2018
After a long search i found the solution
The problem is that if the GPU is old the pytorch version before 0.4.0 doesn’t work, so you have to install the newest pytorch,
run this - conda install -c pytorch pytorch
After you install the newest pytorch you will face torch._C import * DLL load failed problem
to fix that run the ff code
set PYTORCH_BUILD_VERSION=0.4.1
conda install -c pytorch pytorch
set PYTORCH_BUILD_VERSION=0.4.1
YnsDev1 commented May 17, 2018
mingwandroid commented Jan 5, 2018
Can you run the script via python to see which DLL is failing? If that doesn't help please use procmon to determine this.
Also conda list --show-channel-urls would be helpful.
gblackshields commented Jan 8, 2018
I cannot do much with any preinstalled software, this is a work PC with very tight restrictions (I had to put in a request just to get terminal access). You're right, I don't use the anaconda prompt, it is through a launched Spyder IDE instance that I first came across this (Spyder launched directly from the executable, not through Anaconda Navigator). I had been using Anaconda for some time prior to the new recommendations with respect to modifying PATH etc, so I elected to 'stick to what you know'. Thanks for setting me straight! You've convinced me that this is more an issue with my configuration than anything else, so I'm happy to close.
njsmith commented Jan 5, 2018
adithcraft commented Jul 20, 2018
I had same error while running scrapy from anaconda prompt. By seeing on process monitor, it caused by both dll files cannot be found inside Anaconda3\Lib\site-packages\cryptography\hazmat\bindings.
Copy both files from Anaconda3\pkgs\openssl-1.0.2o-h8ea7d77_0\Library\bin into Anaconda3\Lib\site-packages\cryptography\hazmat\bindings, and it works
MSeal commented Sep 1, 2020
shaktijaiswal commented Sep 13, 2020
facing same problem
SamuelLawrence876 commented Jul 3, 2020
Also having the problem. has anyone found a fix?
Solved
If you are working in a miniconda on conda environment. You could just install pywin32 using conda instead of pip.
This solved my problem:
I had to install it within a given conda environment (rather than in one I run jupyter notebook from). Nonetheless, it works!
We shall hold a festival in your name! Win 10 64-bit. Hours wasted. but thanks to this, issue solved. conda install pywin32 in my activated env didn't affect system32 and it avoided the need to run the postinstall script which failed because wintypes DLL was not found. It shouldn't be possible to get into this ridiculous state (I don't know how it happened) and it should not take this much work to get out. But thank you thank you thank you.
For my case, install and reinstall pywin32 doesn't help. After copied the two files from [installation directory of Anaconda]\Lib\site-packages\pywin32_system32 to C:\Windows\System32 , it works.
My environment is python 3.8 in miniconda. The two files are pythoncom38.dll and pywintypes38.dll .
Same issue under Python 3.8. Solution works, but I had to take the files under my virtual environment Lib folder
This information helped, but putting 3rd party stuff in C:\Windows\System32 is a recipe for future trouble. Think for instance what will happen if pywin32 updates the DLL and you don't copy them again to C:\Windows\System32 after a pip update. You will get an inconsistent system. In addition, all programs of the computer will "see" these DLLs. You should rather set the PATH as/where required.
For me, it worked by downgrading my pywin32 from version 227 to version 224. Just type the following command on any shell in administrator mode:
I get this error under Python3.8: Could not find a version that satisfies the requirement pywin32==224 (from versions: 225, 226, 227, 228)
You must not activate the base env, only the env that you want to use. Downgrading from 228 to 225 worked for me. pip install --upgrade pywin32==225 worked
As of November 2021, pip install --upgrade pywin32==300 works, pwin32 versions 301, 302 fail! [SO community members should get paid for their QA services :)]
Run Scripts\pywin32_postinstall.py -install in an Admin command prompt
edit: User @JoyfulPanda gave a warning:
Running this script with admin rights will also copy pythoncom37.dll, pywintypes37.dll (corresponding to the pywin32 version), into C:\WINDOWS\system32 , which effectively overwrites the corresponding DLL versions from Anaconda already there. This later causes problem when openning (on Windows) "Start Menu > Anaconda3 (64-bit) > Anaconda Prompt (a_virtual_env_name)". At least Anaconda 2019.07 has pywin32 223 installed by default. Pywin32 224 may work, but 225-228 causes problem for Anaconda (2019.07)
To run pywin32_postinstall.py, you need to python pywin32_postinstall.py -install , else you'll get an importerror about winreg
Running this script with admin rights will also copy pythoncom37.dll , pywintypes37.dll (corresponding to the pywin32 version), into `C:\WINDOWS\system32`, which effectively overwrites the corresponding DLL versions from Anaconda already there. This later causes problem when openning (on Windows) "Start Menu > Anaconda3 (64-bit) > Anaconda Prompt (a_virtual_env_name)". At least Anaconda 2019.07 has pywin32 223 installed by default. Pywin32 224 may work, but 225-228 causes problem for Anaconda (2019.07).
conda install pywin32 worked for me. I am using conda distribution and my virtual env is using Python 3.8
This happens when Lib\site-packages\pywin32_system32 is not in the list of directories to search for DLL (PATH environment variable).
pywin32 (or one of its dependencies) adds this path at runtime to the PATH variable. If this is failing, or another component is overriding the PATH after it's been set by pywin32, you will get the given error (ImportError: DLL load failed while importing win32api).
You can try to extend the PATH variable in the shell before starting Python.
If that doesn't work, then the PATH maybe overridden within the Python program at runtime. Add the following line to your program just before pywin32 is used to verify its value:
As a last resort, you can extend the PATH variable before pywin32 is loaded:
I have added absolute path of 'pywin32_system32' to the os.environ['PATH'] and still can't import win32api. Only copying the two dlls to the system32 could work.
Maybe because of this change in 3.8: DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution.
C:\ProgramData\Anaconda3>py Scripts\pywin32_postinstall.py -install . Pythonwin has been registered in context menu Creating directory C:\ProgramData\Anaconda3\Lib\site-packages\win32com\gen_py Can't install shortcuts - 'C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Python 3.8' is not a folder The pywin32 extensions were successfully installed.
For python 3.8.3, pywin32==225 worked for me, the existing pywin32==228 was uninstalled.
Hope it solves your problem
for me a similar approach worked. I downgraded from 227 to 226. also a newer version like 301 did not workout for me.
According to pywin32 github you must run
and after that, you must run
taken from here. worked for me!
I think this is the most orthodox solution amongst all available solutions. It works because extra pywin32 extensions need to be installed.
As of February 2022, downgrading tot version 303 of pywin32 solves the issue.
Check your pywin32 version:
Downgrade to version 300:
pypiwin32 is an outdated distribution. Uninstall it and install pywin32 :
Try to reinstall it; after all your experiments with different packages the DLLs could be broken: pip install --ignore-installed pywin32
thank you so much! actually it didn't work first when i just installed pywin32 but then i wrote in the scripts folder pywin32_postinstall.py -install , then i tried import win32api and no error appear!
All pywin32_postinstall.py doing is copying pywintypes[pyton version].dll and pythoncom[pyver].dll from \Lib\site-packages\pywin32_system32\ into main dir. Actually better to just manually copy to \Library\bin. Then it all works.
Windows 10, Python 3.8, PyWin32 v.302 using Anaconda
Here is what worked for me
Open an elevated command prompt activate environment
- Windows Key
- Type cmd
- Right click Command Prompt and click Run as Administrator
- conda activate [ENVIRONMENT]
Navigate to the environment you installed PyWin32 on, works if pip install or conda install is used
- cd C:\Users\[USER]\anaconda3\envs\[ENVIRONMENT]\Scripts
Run the post install script that was added when installing PyWin32
Jupyter notebook github has the issue mentioned in the question. There are multiple solution proposed.
однако все, что я запускаю, - это 64 бита. Я на Win7 64 бит, у меня есть winpython 2.7.3.3, распределение 64 бит, и я скомпилировал opencv в 64 битах с предоставленной инструкцией здесь и разместил cv2.PYD dll в папке Lib/site-packages python.
к сожалению, предложение использовать 32-битную версию python больше не работает для меня, поскольку мне приходится обрабатывать массивы numpy слишком большие для 32 бит.
единственное, чего не хватало, это добавить новый путь к двоичным файлам opencv (C:opencvbuildbinRelease) для переменной среды Windows PATH перезапустите python.
теперь все работает нормально!
эта проблема была решена путем добавления пути двоичных файлов opencv к переменной среды PATH Windows (например , на моем компьютере этот путь: C:\opencv\build\bin\Release).
вы можете попробовать установить 32-битную версию opencv
или вам нужно перестроить модуль cv2 для win 64bit.
все, что вам нужно сделать, это скопировать cv2.файл pyd из папки x86 (C:\opencv\build\python\2.7\x86\ к примеру)C:\Python27\Lib\site-packages\ , а не из папки x64.
надеюсь, что поможет вам.
когда у меня была эта ошибка, она ушла после того, как мой компьютер разбился и перезапустился. Попробуйте закрыть и снова открыть IDE, если это не сработает, попробуйте перезагрузить компьютер. Я только что установил библиотеки в этот момент без перезапуска pycharm, когда я получил эту ошибку.
никогда не закрывал PyCharm сначала, чтобы проверить, потому что мой проклятый компьютер продолжает сбой случайным образом. работаю над этим, но это, по крайней мере, решило эту проблему.. маленькая победа.. :).
Я просто нажал на это, и проблема заключалась в том, что пакет в какой-то момент был установлен в каталоге пакетов для каждого пользователя. (в Windows.) aka %AppData%\Python. Поэтому Python сначала искал там, находя старую 32-битную версию.pyd-файл и сбой с указанной ошибкой. К сожалению, pip uninstall сам по себе не был достаточно, чтобы очистить это, и в это время pip 10.0.1, похоже, не имеет параметра --user для удаления, только для установки.
tl; dr удаление старого .pyd из %AppData%\python\python27\site-packages решил эту проблему для меня.
Hello, not sure if this is the right platform to address this issue. However, I am on a windows 10 64-bit system. I was using python 3.8.0 32-bit but recently I downloaded anaconda in order to work with jupyter notebooks. When I open the anaconda prompt and type python it show this:
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Now when I try to create a notebook I have the options: Python 3 and Python 3.8.0. Whichever I choose I get this when I click the Kernel error:
The text was updated successfully, but these errors were encountered:
kunalagg04 commented Aug 31, 2020
Exact same issue here as well.
ctivanovich commented Jul 22, 2018
@ajay-banstola I tried that to no effect. @adithcraft I tried that, also to no effect.
mingwandroid commented Jan 8, 2018
Steve Dower's announcement is unrelated to this.
ichisa commented Aug 14, 2020
Same issue here
dhirschfeld commented Sep 13, 2020
The problem in the original issue is mixing and matching pythons - jupyter is running from anaconda:
. but it's running the notebook in the original Python environment:
So, I'd say just don't do that - there's no reason to install another python alongside anaconda .
The solution is to uninstall the other Python version and remove all traces of it (from e.g. the PATH env variable)
gblackshields commented Jan 8, 2018
The incriminating DLL was libeay32.dll, found in "C:\Program Files (x86)\Intel\iCLS Client". I put in a workaround, essentially by kicking this folder further down my PATH, and so far, it's worked, and nothing else has broken AFAIK. No idea if it's related in some way to this announcement other than mentioning the same DLL.
ctivanovich commented Jun 24, 2018 •
I'm having this same problem for windows 10 64-bit, namely by trying to use sshtunnel, psycopg2, or pymysql. For the connectors, I get the following error just by importing, while I get it for sshtunnel when trying to start an ssh server:
C:\Anaconda3\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py in () . long traceback. ---> 13 from cryptography.hazmat.bindings._openssl import ffi, lib . ImportError: DLL load failed: The operating system cannot run %1.
I've tried putting anaconda to the front of my path variable and I've tried removing it from path and using the anaconda prompt, but it has not solved the problem. Kind of at my wit's end trying to figure this out, any suggestions? (I did not install anaconda with the option to append to path selected, i added later to path myself to have cmd access to python.exe and jupyter.exe).
ajay-banstola commented Jul 21, 2018
make an anaconda environment and run the script to install again
mingwandroid commented Jan 5, 2018
Sandsten commented Sep 28, 2020
I was plagued by the same issue with ImportError: DLL load failed: %1 is not a valid Win32 application
This happened when i tried to open vscode through anaconda-navigator and run a jupyter notebook. It then complained about missing packages for running the kernel through a vscode popup, i pressed install, it installed something and then everything broke down.
Then I managed to get it to work by reinstalling anaconda as admin (through right clicking the installer) and then installing it in it's default path C:\ProgramData\Anaconda3 . I reinstalled it a bunch of times prior to this with no avail, both without admin and with admin directly under C:\ . No idea if installing it in it's default path as admin did the trick or something entirely different.
HenriqueSaccani commented Oct 7, 2020
I'm not using anaconda but i have the same problem, i tried the pip install -- pywin32==227 but did not work.
cryptography installed on windows with Anaconda package manager.
I am using paramiko to connect via SSH to a local compute cluster.. Connection fails with the error below. I've since reproduced this error using the introductory 'Fernet' example on the pypi cryptography homepage.
From reading similar error messages online, my google-guess is that the error is due to the package finding incorrect DLLs (in my case, found in C:\Program Files (x86)\Intel\iCLS Client). However I do not have any idea on how to rectify, short of prepending PATH with the right location - but what is the right location?
The text was updated successfully, but these errors were encountered:
dhirschfeld commented May 24, 2020
I'd try a force reinstall for pywin32 (in the environment where it's being loaded):
mingwandroid commented Jan 8, 2018
I can only assume you do not use the Anaconda Prompt or otherwise activate your shell correctly and instead elected for the Anaconda installer to modify your PATH? This is the worst way to use Anaconda, particularly on Windows with it's very poor shared library handling capabilities (DLL hell).
In particular Windows has two PATH parts, system and user. System comes first. The Anaconda installer usually installs as user so adding to PATH here means it's not at the front. Using correct activation, the Anaconda Prompt or Anaconda Navigator avoids all this trouble.
I don't know what this iCLS Client is but do you need it on PATH? When I install stuff on Windows I try to avoid allowing anything to modify PATH.
kunalagg04 commented Aug 31, 2020
Exact same issue here as well.
Читайте также: