Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3.8 #1327

Closed
terrdavis opened this issue Apr 2, 2019 · 32 comments
Closed

python 3.8 #1327

terrdavis opened this issue Apr 2, 2019 · 32 comments

Comments

@terrdavis
Copy link

I would like to use this in Python 3.8.
I tried to install by renaming the latest python 3.7 .whl but when I try to import win32api I get this error:
ImportError: DLL load failed: The specified module could not be found.

@Aareon
Copy link

Aareon commented Apr 11, 2019

You will need to clone and compile this repository from source first, as there are currently no builds for Python 3.8.

Install MS Build Tools

https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017

Clone this repository

git clone https://github.com/mhammond/pywin32
cd pywin32

Build from source

py setup.py install

@SmartManoj
Copy link

@terrdavis did u build?

@terrdavis
Copy link
Author

terrdavis commented Jul 5, 2019 via email

@SmartManoj
Copy link

No I didn't.

On Thu, Jul 4, 2019 at 23:12 SmartManoj @.***> wrote: @terrdavis https://github.com/terrdavis did u build? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1327?email_source=notifications&email_token=AEAM2UBJP367AX742D623B3P53Q4TA5CNFSM4HDDYMC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZIUIGA#issuecomment-508642328>, or mute the thread https://github.com/notifications/unsubscribe-auth/AEAM2UE52FDI2VCFCSLP5ITP53Q4TANCNFSM4HDDYMCQ .

Is there anyway to build online?

@Aareon
Copy link

Aareon commented Jul 6, 2019

No.

@SmartManoj
Copy link

@SmartManoj
Copy link

creating build\temp.win-amd64-3.8\Release\win32\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDISTUTILS_BUILD -D_CRT_SECURE_NO_WARNINGS -Icom/win32com/src/include -Iwin32/src -IC:\Users\NIIT\AppData\Local\Programs\Python\Python38\include -IC:\Users\NIIT\AppData\Local\Programs\Python\Python38\include "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" /Tpwin32/src/PyACL.cpp /Fobuild\temp.win-amd64-3.8\Release\win32/src/PyACL.obj -DBUILD_PYWINTYPES /Zi /Fdbuild\temp.win-amd64-3.8\Release\pywintypes_vc.pdb /EHsc /wd4163 -DUNICODE -D_UNICODE -DWINNT
PyACL.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDISTUTILS_BUILD -D_CRT_SECURE_NO_WARNINGS -Icom/win32com/src/include -Iwin32/src -IC:\Users\NIIT\AppData\Local\Programs\Python\Python38\include -IC:\Users\NIIT\AppData\Local\Programs\Python\Python38\include "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" /Tpwin32/src/PyDEVMODE.cpp /Fobuild\temp.win-amd64-3.8\Release\win32/src/PyDEVMODE.obj -DBUILD_PYWINTYPES /Zi /Fdbuild\temp.win-amd64-3.8\Release\pywintypes_vc.pdb /EHsc /wd4163 -DUNICODE -D_UNICODE -DWINNT
PyDEVMODE.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDISTUTILS_BUILD -D_CRT_SECURE_NO_WARNINGS -Icom/win32com/src/include -Iwin32/src -IC:\Users\NIIT\AppData\Local\Programs\Python\Python38\include -IC:\Users\NIIT\AppData\Local\Programs\Python\Python38\include "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" /Tpwin32/src/PyHANDLE.cpp /Fobuild\temp.win-amd64-3.8\Release\win32/src/PyHANDLE.obj -DBUILD_PYWINTYPES /Zi /Fdbuild\temp.win-amd64-3.8\Release\pywintypes_vc.pdb /EHsc /wd4163 -DUNICODE -D_UNICODE -DWINNT
PyHANDLE.cpp
win32/src/PyHANDLE.cpp(200): error C2440: 'initializing': cannot convert from 'int (__cdecl *)(PyObject *,FILE *,int)' to 'Py_ssize_t'
win32/src/PyHANDLE.cpp(200): note: There is no context in which this conversion is possible
win32/src/PyHANDLE.cpp(361): warning C4477: '_snwprintf' : format string '%Id' requires an argument of type '__int64', but variadic argument 2 has type 'HANDLE'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2

@terrdavis
Copy link
Author

terrdavis commented Oct 15, 2019

Now that Python 3.8 is out, please let us know if you plan on spinning up a build for this.

I've attempted a build, but I've run into a few issues:

  • It wasn't clear which permutation of MSVC build tools to install. I believe an accurate description is:
    • The most recent version that has a Windows 8.1 SDK available (2017, C++ build tools, Win 8.1 SDK and UCRT SDK)
  • I had to add some environment variables, but this was only documented in setup.py
    • MSSDK_LIB
    • MSSDK_INCLUDE
    • It also wasn't clear where exactly these should point, but based on an error, I searched for "x64" and ended up pointing these to C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\[lib|include]

I got this error after running the command py -3.8 setup.py build.

raw-out.txt:

Building pywin32 3.8.225.1
Using SDK as specified in the environment
running build
running build_py
copying win32\lib\afxres.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\commctrl.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\dbi.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\mmsystem.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\netbios.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\ntsecuritycon.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\pywin32_testutil.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\pywintypes.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\rasutil.py -> build\lib.win-amd64-3.8\win32\lib
copying win32\lib\regcheck.py -> build\lib.win-amd64-3.8\win32\lib
...
...
...
win32/src/PyUnicode.cpp(492): warning C4267: '=': conversion from 'size_t' to 'DWORD', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDISTUTILS_BUILD -D_CRT_SECURE_NO_WARNINGS -Icom/win32com/src/include -Iwin32/src -IC:\Python38\include -IC:\Python38\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" /Tpwin32/src/PyWAVEFORMATEX.cpp /Fobuild\temp.win-amd64-3.8\Release\win32/src/PyWAVEFORMATEX.obj -DBUILD_PYWINTYPES /Zi /Fdbuild\temp.win-amd64-3.8\Release\pywintypes_vc.pdb /EHsc /wd4163 -DUNICODE -D_UNICODE -DWINNT
PyWAVEFORMATEX.cpp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DDISTUTILS_BUILD -D_CRT_SECURE_NO_WARNINGS -Icom/win32com/src/include -Iwin32/src -IC:\Python38\include -IC:\Python38\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\include" /Tpwin32/src/PyWinTypesmodule.cpp /Fobuild\temp.win-amd64-3.8\Release\win32/src/PyWinTypesmodule.obj -DBUILD_PYWINTYPES /Zi /Fdbuild\temp.win-amd64-3.8\Release\pywintypes_vc.pdb /EHsc /wd4163 -DUNICODE -D_UNICODE -DWINNT
PyWinTypesmodule.cpp
win32/src/PyWinTypesmodule.cpp(690): warning C4996: 'PyObject_AsReadBuffer': deprecated in 3.0
c:\python38\include\abstract.h(337): note: see declaration of 'PyObject_AsReadBuffer'
win32/src/PyWinTypesmodule.cpp(716): warning C4996: 'PyObject_AsWriteBuffer': deprecated in 3.0
c:\python38\include\abstract.h(348): note: see declaration of 'PyObject_AsWriteBuffer'
creating build\lib.win-amd64-3.8\pywin32_system32
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python38\libs /LIBPATH:C:\Python38\PCbuild\amd64 /LIBPATH:build\temp.win-amd64-3.8\Release "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\lib\x64" advapi32.lib user32.lib ole32.lib oleaut32.lib python38.lib /EXPORT:PyInit_pywintypes build\temp.win-amd64-3.8\Release\win32/src/PyACL.obj build\temp.win-amd64-3.8\Release\win32/src/PyDEVMODE.obj build\temp.win-amd64-3.8\Release\win32/src/PyHANDLE.obj build\temp.win-amd64-3.8\Release\win32/src/PyIID.obj build\temp.win-amd64-3.8\Release\win32/src/PyLARGE_INTEGER.obj build\temp.win-amd64-3.8\Release\win32/src/PyOVERLAPPED.obj build\temp.win-amd64-3.8\Release\win32/src/PySECURITY_ATTRIBUTES.obj build\temp.win-amd64-3.8\Release\win32/src/PySECURITY_DESCRIPTOR.obj build\temp.win-amd64-3.8\Release\win32/src/PySID.obj build\temp.win-amd64-3.8\Release\win32/src/PyTime.obj build\temp.win-amd64-3.8\Release\win32/src/PyUnicode.obj build\temp.win-amd64-3.8\Release\win32/src/PyWAVEFORMATEX.obj build\temp.win-amd64-3.8\Release\win32/src/PyWinTypesmodule.obj /OUT:build\lib.win-amd64-3.8\pywin32_system32\pywintypes38.dll /IMPLIB:build\temp.win-amd64-3.8\Release\win32/src\pywintypes38.lib /MANIFEST:NO /MACHINE:amd64 /BASE:0x1e7a0000 /DEBUG /PDB:build\temp.win-amd64-3.8\Release\pywintypes.pdb
PyWinTypesmodule.obj : warning LNK4197: export 'PyInit_pywintypes' specified multiple times; using first specification
   Creating library build\temp.win-amd64-3.8\Release\win32/src\pywintypes38.lib and object build\temp.win-amd64-3.8\Release\win32/src\pywintypes38.exp
MSVCRT.lib(loadcfg.obj) : error LNK2001: unresolved external symbol __enclave_config
build\lib.win-amd64-3.8\pywin32_system32\pywintypes38.dll : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\link.exe' failed with exit status 1120

vs2017 options

@mhammond
Copy link
Owner

The build process sucks - most is for historical reasons and I'm planning on a revamp of things once I can kill the 2.7 builds, which I plan doing at the end of the year once 2.7 itself is dead. That doesn't help you now though :(

The __enclave_config error is something I've not seem before - I wonder if something in python itself changed since I build 225 - did you see the 3.8 builds of 225?

sorry I can't be more help - I expect I'll hit the same issue if I try today (but I'm not going to find time to try for a little time)

@terrdavis
Copy link
Author

I did not see the 3.8 builds! I had assumed this issue would be updated, and didn't check that assumption before going down this rabbit hole.
That's great news!

@terrdavis
Copy link
Author

Installed the new build from pypi, but it doesn't work:

py -3.8 c:\python38\scripts\pywin32_testall.py
Traceback (most recent call last):
  File "\python38\scripts\pywin32_testall.py", line 5, in <module>
    import win32api
ImportError: DLL load failed while importing win32api: The specified module could not be found.

@terrdavis terrdavis reopened this Oct 15, 2019
@v-python
Copy link

Yeah, the builds are there for 3.8, but they don't work, I'll quote a message from Python-dev, I encountered this problem too.

On 15Oct2019 1143, MRAB wrote:

On 2019-10-15 19:03, MRAB wrote:

I've installed pywin32 on Python 3.8, but when I try to import
win32clipboard it says it can't find it:

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 win32
import win32clipboard
Traceback (most recent call last):
File "", line 1, in
ImportError: DLL load failed while importing win32clipboard: The
specified module could not be found.

Does anyone else have this problem?

I found the solution: copy pywintypes38.dll and pythoncom38.dll from site-packages/pywin32_system32 into site-packages/win32.

The new os.add_dll_directory() function 1 is a way for pywin32 to work around this themselves without having to relocate files. The note in the doc also explains the cause.

Cheers,
Steve


@v-python
Copy link

Here's sample code for a workaround (for the win32clipboard, but it also works for other DLLs)

win32 = 0
pathwin32 = ''
for iz in sys.path:
if 'site-packages' in iz:
pathwin32 = os.path.join( iz, 'pywin32_system32')
if os.path.isdir( pathwin32 ):
break
pathwin32 = ''
try:
os.add_dll_directory( pathwin32 )
import win32clipboard
win32 = 1
except:
pass # checking for GUI interface module

@v-python
Copy link

Sorry, forgot that indentation would be lost, but it should be obvious.

@terrdavis
Copy link
Author

Links:

Relevant excerpt from second link:

If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library.

@CristiFati
Copy link
Contributor

CristiFati commented Oct 18, 2019

I think something has changed in Python, regarding .dll search paths / order. After a few tests, I concluded that pywintypes38.dll is the one that's not found (even if its dir is in the process' %PATH% (os.environ["PATH"]) - added by pywin32.pth). As a (temporary) workaround, force the .dll to be loaded in the process:

import pywintypes
import win32api

Notes:

  • I only tested this on a VEnv
  • It works with the latest standard version (225), installed as: python -m pip install pywin32

@terrdavis
Copy link
Author

Would it make sense to place the dlls in the Python38/DLLS folder instead of calling os.add_dll_directory every time it's imported?

@CristiFati
Copy link
Contributor

CristiFati commented Nov 1, 2019

FYI: I applied the fix (from #1430 ) to the original .whls and published them on [GitHub]: CristiFati/Prebuilt-Binaries - (master) Prebuilt-Binaries/PyWin32.

@atomcgot
Copy link

atomcgot commented Nov 7, 2019

I started using Python about a week ago.
So to summarize... if I want to use pywin32 with Python 3.8 then I need to:

  1. Rename the python folder to Python 3.7
  2. Download win32clipboard DLL (Idk where to find that)
  3. Edit win32clipboard.dll with the following workaround:
    win32 = 0
    pathwin32 = ''
    for iz in sys.path:
    if 'site-packages' in iz:
    pathwin32 = os.path.join( iz, 'pywin32_system32')
    if os.path.isdir( pathwin32 ):
    break
    pathwin32 = ''
    try:
    os.add_dll_directory( pathwin32 )
    import win32clipboard
    win32 = 1
    except:
    pass # checking for GUI interface module
  4. Im done. (Right?) Could a genius clarify this for me?

@v-python
Copy link

v-python commented Nov 7, 2019

Sure (but restore the indentation that got lost when I posted that). Or wait for the upcoming pywin32 release 226... Mark has merged a fix that will make this workaround unnecessary... but hasn't released it yet. Watch this repo for details of the release.

@CristiFati
Copy link
Contributor

CristiFati commented Nov 12, 2019

Summarizing - check:

@atomcgot: you don't have to rename anything, doing so would be a lame workaround (gainarie). Not sure where that idea came from, but it's terribly wrong. For Python 3.8(.0) feel free to use the .whls mentioned in the above URLs.

@thezoggy
Copy link

pywin32 227 is out a few days now -- https://github.com/mhammond/pywin32/releases/tag/b227

@ogaskell
Copy link

ogaskell commented Dec 3, 2019

Is this fixed yet? It doesn't seem to be working for me, I'm using 227.

@CristiFati
Copy link
Contributor

CristiFati commented Dec 3, 2019

@ogaskell: Are you still encountering the issue? Can you provide more details like Python version (3.8.0), architecture, (is it a virtual environment)? Ar you sure the PyWin32 upgrade went OK?

I've tested the v227 .whl with multiple Python 3.8 configurations, and it worked OK.

@swingfield
Copy link

Just fyi @CristiFati , I found that v227 fixed the issue for me at least, as compared to v225.

@joankaradimov
Copy link
Contributor

joankaradimov commented Jun 21, 2020

I've slowly been progressing in porting pywin32 to mingw. Right now I have a [partial] builds of version 228 that run on Python 2.7, but fail with the described error on Python 3.8.

@CristiFati
Copy link
Contributor

@joankaradimov: What's the purpose for the MinGW / MSYS2 port? Is there an official Python distribution for Windows built with the above toolchains?

@joankaradimov
Copy link
Contributor

joankaradimov commented Jun 22, 2020

Is there an official Python distribution for Windows built with the above toolchains?

There is no official binary distribution that I know of. But building with MinGW appears to be supported: https://wiki.python.org/moin/WindowsCompilers#GCC_-_MinGW-w64_.28x86.2C_x64.29

What's the purpose for the MinGW / MSYS2 port

If you're asking about the port of Python - MSYS2 is essentially a Unix userland on top of Windows. And it's hard to get a modern Unix userland running without a Python interpreter. And to solve this MSYS2 ships its own build of Python in its package manager.

If you're asking about the port of PyWin32 - a specific problem I'm trying to solve is - get emscripten to run on the tools provided by MSYS2. Managing its long list of dependencies on Windows is a hassle. A real package manager is very handy.

@CristiFati
Copy link
Contributor

I've just open Emscripten home page, I don't know anything a bout it. Does it reference PyWin32? That would be strange.

From what am I concerned Python built on MSYS2 (or any other Nix like emulator - e.g. Cygwin, ...) should only expose a Nix interface, so having PyWin32 (Win APIs exposed) there, would be incorrect from the design point of view.

@joankaradimov
Copy link
Contributor

joankaradimov commented Jun 25, 2020

Does it reference PyWin32? That would be strange.

It does, yes. Parts of it are written in Python.

From what am I concerned Python built on MSYS2 (or any other Nix like emulator - e.g. Cygwin, ...) should only expose a Nix interface

This is about porting to MinGW. Which is native Win32. It's GCC combined with a free reimplementation of the Win32 SDK. It only depends on the DLLs that are shipped in System32. So that should not be an incorrect design based on your criteria.

(However, once it's ported, in theory it could be tweaked to work on MSYS2, Cygwin, and even Linux with libwine.)

@Avasam
Copy link
Collaborator

Avasam commented Nov 21, 2023

Is this issue still relevant? Python 3.8 support was added a long time ago

@mhammond
Copy link
Owner

Nope - I guess we can expect a new one for 3.13, but this one is no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests