Python 3.8.0 has been recently released (on 20191014, and can be downloaded from [Python]: Python 3.8.0). PyWin32 has builds for it on [PyPI]: pywin32 225 (released on 20190915). Unfortunately, after pip installing, it doesn't work.
Sample:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe"
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> ^Z
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe"
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing win32api: The specified module could not be found.
>>> ^Z
Notes:
For Python 3.7, I also upgraded my PyWin32 module to the latest, and it works
Older PyWin32 versions work on older Python versions (2.7, 3.5, 3.6)
Reproducible on 64bit and 32bit
Spoiler alert!!!
Applied #2.2. (from below) to the original .whls, and published them on [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 (win_amd64, win32 for Python 3.8).
After installing (one of) them, existing code should work OOTB (with respect to this issue).
Install steps:
Download the .whl that matches your Python architecture (64bit, 32bit - for more details on getting Python architecture, check [SO]: How do I determine if my python shell is executing in 32bit or 64bit? (#CristiFati's answer) (the question is about OSX, but other platforms are covered as well)), it will most likely be 64bit (win_amd64), from the above URL.
For example, I downloaded it in L:\Downloads
Invoke the PIP installer on it ([SO]: How to install a package for a specific Python version on Windows 10? (#CristiFati's answer)). Something like:
(${path_to_your})python.exe -m pip ${path_to_the_downloaded_pywin32_whl}
Example:
"e:\Work\Dev\VEnvs\py_pc064_03.08.00_test0\Scripts\python.exe" -m pip "L:\Downloads\pywin32-225-cp38-cp38-win_amd64.whl"
The problem has been reported on [GitHub]: mhammond/pywin32 - python 3.8.
The above URL references 2 more:
[Python 3.8.Docs]: What’s New In Python 3.8 - Changes in the Python API which states (emphasis is mine):
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.
[Python 3.Docs]: os.add_dll_directory(path) which states (emphasis still mine):
This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes.
In the same time, I did some digging of my own and discovered that (for win32api.pyd) it's pywintypes38.dll (which is a dependency for the .pyds) that is not found (I also specified this in a comment on the issue).
Solutions (actually workarounds (more or less) until an official and backwards compatible fix is released):
Force pywintypes38.dll load by importing it (as it's also a Python module and in this scenario it doesn't fall under the above rule) before any PyWin32 module:
import pywintypes
import win32api
If working with COM, you'd need import pythoncom
Adding pywin32_system32 to the .dll search paths (following the new model from above). There are multiple ways:
v-python's comment from the issue URL which provides a small snippet (I didn't test it)
I also submitted [GitHub]: mhammond/pywin32 - Support for Python 3.8, where I do everything in the pywin32.pth file ("executed" when the interpreter starts, so no changes needed for existing code). Unfortunately, there is a problem with the AppVeyor automated tests which fail (but for some other reasons), so it has been stuck there for a while. Note that in the meantime, the PR was closed and another (similar) approach was pushed. Note that v226 (released on 20191110) which contains the fix, does not work on VirtualEnv ([SO]: PyWin32 (226) and virtual environments (#CristiFati's answer)). Anyway, applying the changes locally (1) (on both my Python VirtualEnvs), solved the problem (on one, and didn't break the other):
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" -c "import win32api"
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe" -c "import win32api"
[prompt]>
Other ways like copying the .dlls (e.g. in %SystemRoot%\System32), or symlinking them, but (personally) I wouldn't recommend those
For more details on .dll loading (via CTypes), check [SO]: Can't import dll module in Python (#CristiFati's answer).
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!
Footnotes
#1: Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching utrunner section) for how to apply patches (on Win).
Managed to install pywin32 v225 with pycharm on python 3.8.
importing pywintypes before win32api
import pywintypes
import win32api
Related
I am importing two python modules on my school computer (I cannot use cmd, I do not have enough experience with powershell), pygame and pyglet. I imported these modules last year and had no problems, this year I have started having problems. I tried reinstalling them.
I have imported them via pip.
import pip
pip.main(["install", "--user", "pygame"])
and
import pip
pip.main(["install", "--user", "pyglet"])
It says that this requirement has already been meet.
When I import it into my code it says
I have tried other methods and they all return the same result.
What can I do?
If restarting vscode doesn't work to cause pylance to find new packages, it sounds like there's a mismatch between the interpreter you're using to run your programs (and where you installed the packages via pip) and the interpreter vscode/pylance is using for language support.
With those restrictions, try this:
First, create a script with
import sys
print(sys.version)
print(sys.executable)
and run it (however you're running scripts).
You should get output like:
3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
C:\Python\Python310\python.exe
Then, in the bottom right of vscode there's a statusbar and at the right side you should see something like:
Here it shows that vscode is using the 3.10.2 64-bit version of the interpreter.
If you click the version label (3.10.2 64-bit in my case), you should get a pop-up at the top of your screen, like:
Make sure you select the interpreter that you're using (as identified by the output of that simple 3-line script -- both the interpreter version and the path).
For me this was a version mismatch: VSCode was using a different interpreter version (3.10) than the packages were installed for (3.9).
You can correct this by clicking the Python version in the status bar (to the right of the word Python). Multiple options should show up, switching to 3.8.9 worked for me.
Python 3.8.0 has been recently released (on 20191014, and can be downloaded from [Python]: Python 3.8.0). PyWin32 has builds for it on [PyPI]: pywin32 225 (released on 20190915). Unfortunately, after pip installing, it doesn't work.
Sample:
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe"
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> ^Z
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe"
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing win32api: The specified module could not be found.
>>> ^Z
Notes:
For Python 3.7, I also upgraded my PyWin32 module to the latest, and it works
Older PyWin32 versions work on older Python versions (2.7, 3.5, 3.6)
Reproducible on 64bit and 32bit
Spoiler alert!!!
Applied #2.2. (from below) to the original .whls, and published them on [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32/v225 (win_amd64, win32 for Python 3.8).
After installing (one of) them, existing code should work OOTB (with respect to this issue).
Install steps:
Download the .whl that matches your Python architecture (64bit, 32bit - for more details on getting Python architecture, check [SO]: How do I determine if my python shell is executing in 32bit or 64bit? (#CristiFati's answer) (the question is about OSX, but other platforms are covered as well)), it will most likely be 64bit (win_amd64), from the above URL.
For example, I downloaded it in L:\Downloads
Invoke the PIP installer on it ([SO]: How to install a package for a specific Python version on Windows 10? (#CristiFati's answer)). Something like:
(${path_to_your})python.exe -m pip ${path_to_the_downloaded_pywin32_whl}
Example:
"e:\Work\Dev\VEnvs\py_pc064_03.08.00_test0\Scripts\python.exe" -m pip "L:\Downloads\pywin32-225-cp38-cp38-win_amd64.whl"
The problem has been reported on [GitHub]: mhammond/pywin32 - python 3.8.
The above URL references 2 more:
[Python 3.8.Docs]: What’s New In Python 3.8 - Changes in the Python API which states (emphasis is mine):
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.
[Python 3.Docs]: os.add_dll_directory(path) which states (emphasis still mine):
This search path is used when resolving dependencies for imported extension modules (the module itself is resolved through sys.path), and also by ctypes.
In the same time, I did some digging of my own and discovered that (for win32api.pyd) it's pywintypes38.dll (which is a dependency for the .pyds) that is not found (I also specified this in a comment on the issue).
Solutions (actually workarounds (more or less) until an official and backwards compatible fix is released):
Force pywintypes38.dll load by importing it (as it's also a Python module and in this scenario it doesn't fall under the above rule) before any PyWin32 module:
import pywintypes
import win32api
If working with COM, you'd need import pythoncom
Adding pywin32_system32 to the .dll search paths (following the new model from above). There are multiple ways:
v-python's comment from the issue URL which provides a small snippet (I didn't test it)
I also submitted [GitHub]: mhammond/pywin32 - Support for Python 3.8, where I do everything in the pywin32.pth file ("executed" when the interpreter starts, so no changes needed for existing code). Unfortunately, there is a problem with the AppVeyor automated tests which fail (but for some other reasons), so it has been stuck there for a while. Note that in the meantime, the PR was closed and another (similar) approach was pushed. Note that v226 (released on 20191110) which contains the fix, does not work on VirtualEnv ([SO]: PyWin32 (226) and virtual environments (#CristiFati's answer)). Anyway, applying the changes locally (1) (on both my Python VirtualEnvs), solved the problem (on one, and didn't break the other):
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q058631512]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.07.03_test0\Scripts\python.exe" -c "import win32api"
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.08.00_test0\Scripts\python.exe" -c "import win32api"
[prompt]>
Other ways like copying the .dlls (e.g. in %SystemRoot%\System32), or symlinking them, but (personally) I wouldn't recommend those
For more details on .dll loading (via CTypes), check [SO]: Can't import dll module in Python (#CristiFati's answer).
Update #0
[PyPI]: pywin32 227 (which addresses this issue), was published on 20191114!
Footnotes
#1: Check [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (#CristiFati's answer) (Patching utrunner section) for how to apply patches (on Win).
Managed to install pywin32 v225 with pycharm on python 3.8.
importing pywintypes before win32api
import pywintypes
import win32api
I'm using python's pyglet module (python 3 on Windows). When I refer to any classes within pyglet.image, python's CPU usage jumps up and doesn't drop until I exit python. For example:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Anaconda3>python.exe
Python 3.4.3 |Anaconda 2.3.0 (64-bit)| (default, Mar 6 2015, 12:06:10) [MSC v.1
600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyglet #No problem!
>>> pyglet.image.ImageData #Heavy CPU load until I exit python
<class 'pyglet.image.ImageData'>
Is this expected behavior? Why does mentioning this class (not even instantiating it) lead to such high CPU load?
Systems I've tested:
Windows 7 desktop with Anaconda python 3.4.3 and pyglet installed
through 'pip install pyglet': High CPU usage (my problem)
The same Win7 desktop with Anaconda python 3.4.3, but pyglet
installed through 'pip install
hg+https://bitbucket.org/pyglet/pyglet': High CPU usage.
The same Win7 desktop with python 3.5 from python.org and pyglet
installed through 'pip install pyglet': High CPU usage.
Fedora 22 Lenovo laptop with python 3.4.2 and pyglet 1.2.1 installed
through dnf: no problem.
Windows 10 HP laptop with Anaconda python 3.4 and pyglet installed
through 'pip install pyglet': no problem.
Is it possible this is hardware-dependent?
It is probably related to the following lines on the module:
# Initialise default codecs
from pyglet.image import codecs as _codecs
_codecs.add_default_image_codecs()
The order for loading the default codecs is:
# Add the codecs we know about. These should be listed in order of
# preference. This is called automatically by pyglet.image.
# Compressed texture in DDS format
try:
from pyglet.image.codecs import dds
add_encoders(dds)
add_decoders(dds)
except ImportError:
pass
# Mac OS X default: QuickTime
(...)
# Windows XP default: GDI+
(...)
# Linux default: GdkPixbuf 2.0
(...)
# Fallback: PIL
(...)
# Fallback: PNG loader (slow)
(...)
# Fallback: BMP loader (slow)
(...)
Because of lazy loading pyglet.image is only loaded when you refer to something, and you are probably using one of the slow fallbacks. If that is the case maybe you can try installing/uninstalling the codecs so that you use one at a time and find out if the problem is indeed with the codecs. Posting your versions of these codecs may help reproduce the issue.
In order to start building a gui I've decided to install wxPython, however I can't get it working. I run python 2.7.6 (in IDLE it shows: Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32) and it works fine.
When I however try to install a 32 bit or 64 bit version of wxPython from http://www.wxpython.org/download.php it doesn't work, meaning that when I run:
import wx
I get the following message:
Traceback (most recent call last):
File "C:\Users\****\Desktop\Python GUI test\test1.py", line 2, in <module>
import wx
ImportError: No module named wx
I think it might go wrong with the place where it installs wxPython. Normally however it uses the right directory automatically. It tries to install in the following dir:
C:\Users\****\AppData\Local\Enthought\Canopy32\User\Lib\site-packages
Which is in a program called Canopy which I once installed but don't know how to get rid off. I've installed it in this dir and I've also installed it within the dir where Python is installed:
C:\Python27\Lib\site-packages
Both of these locations don't work.
Anyone has an idea where things go wrong?
I would suggest to clean up your installations. Canopy is part of Enthought, so if you don't need this anymore de-install it, I would think you can do that from: Control Panel\All Control Panel Items\Programs and Features
Then re/install the Python version you want to use, would suggest 2.7.8 32 bit and then install wxPython 3.0.1 32 bit for Python 2.7.
To test it do not use "Idle" as it is written in Tkinter, which will cause conflicts with wxPython. Just test it with
c:\Python27\python.exe
import wx
I downloaded and installed this version of wxPython for use with my Python 2.6 installation:
http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.9.1-py26.exe
When I run Python and try to import wx, I get the following error:
C:\Program Files\Console2>python
Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\__init__.py", line 45, in <module>
from wx._core import *
File "c:\Python26\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 4, in <module>
import _core_
ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
>>>
I have already tried removing wxPython and installing again and I got the same error. How can I fix this problem?
I was getting the same error.
After some googling found this link to MSVC++ 2008 Redestributable and installed it.
That solved the problem.
Hate to say this, but I had the same problem, and and import worked fine after a reboot.
Copy the Microsoft C runtime library v.9 files and manifest. That is, msvcr90.dll and microsoft.vc90.crt.manifest from folder python to the folder wx, tha is, folder which contains failed to start DLLs.
Or install the Visual C++ 2008 Redistributable Package.
From looking for "application configuration is incorrect" in the wxPython trac system, the only reference that might make sense is a 64-bit vs 32-bit compatibility issue.
Otherwise, I'd say Brian's answer of trying ANSI is pretty good.
BTW, if you try uninstalling again, make go into the site-packages folder and make sure all the wx and wxPython stuff is deleted.
Try the ANSI version instead of the Unicode one. IIRC it needs to match the Python 2.6 install to work properly.
I too have the same issue.Better install "Portable Python" IDE which comes with some nice modules including wxPython .You can start coding GUI immediately without the need to download a separate wxPython.The link ,
http://www.portablepython.com/
Maybe too late, but I had the same problem and solved that by downloading that from their own website : wxPython2.8-win64-unicode-py27
In my case it initially wanted to setup in somewhere else than my python folder. So I changed it to be in ../python27/Lib/SitePackages/
Then it worked properly.
I hope it helps.
Another late answer, but I recently had issues (8/14) and my solution was to use the 32-bit instead of 64-bit wxPython version.
you try to use the module wxpython 2.8.12.1 version, select the version of your python. you can download it here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#wxpython