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.12: Fix building Pillow on Windows #6942

Closed
hugovk opened this issue Feb 11, 2023 · 2 comments · Fixed by #6943
Closed

Python 3.12: Fix building Pillow on Windows #6942

hugovk opened this issue Feb 11, 2023 · 2 comments · Fixed by #6943
Labels
Bug Any unexpected behavior, until confirmed feature. Windows

Comments

@hugovk
Copy link
Member

hugovk commented Feb 11, 2023

For #6941

Pillow doesn't build for Windows on 3.12:

diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml
index e938e999d..306e34ca9 100644
--- a/.github/workflows/test-windows.yml
+++ b/.github/workflows/test-windows.yml
@@ -15,7 +15,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
+        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"]
         architecture: ["x86", "x64"]
         include:
           # PyPy 7.3.4+ only ships 64-bit binaries for Windows

Python 3.12-dev x86 fails:

   Creating library build\temp.win32-cpython-312\Release\src\_imaging.cp312-win32.lib and object build\temp.win32-cpython-312\Release\src\_imaging.cp312-win32.exp
display.obj : error LNK2001: unresolved external symbol _PyUnicode_AS_UNICODE
build\lib.win32-cpython-312\PIL\_imaging.cp312-win32.pyd : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x86\\link.exe' failed with exit code 1120

Python 3.12-dev x64 similarly fails:

   Creating library build\temp.win-amd64-cpython-312\Release\src\_imaging.cp312-win_amd64.lib and object build\temp.win-amd64-cpython-312\Release\src\_imaging.cp312-win_amd64.exp
display.obj : error LNK2001: unresolved external symbol PyUnicode_AS_UNICODE
build\lib.win-amd64-cpython-312\PIL\_imaging.cp312-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.34.31933\\bin\\HostX86\\x64\\link.exe' failed with exit code 1120

This is because PyUnicode_AS_UNICODE() was deprecated in Python 3.3 and removed in 3.12:

Changed in version 3.3: This function is now inefficient – because in many cases the Py_UNICODE representation does not exist and needs to be created – and can fail (return NULL with an exception set). Try to port the code to use the new PyUnicode_nBYTE_DATA() macros or use PyUnicode_WRITE() or PyUnicode_READ().

Deprecated since version 3.3, will be removed in version 3.12: Part of the old-style Unicode API, please migrate to using the PyUnicode_nBYTE_DATA() family of macros.

@hugovk hugovk added Bug Any unexpected behavior, until confirmed feature. Windows labels Feb 11, 2023
@nulano
Copy link
Contributor

nulano commented Feb 11, 2023

The macro is used in list_windows_callback, which is referenced from PyImaging_ListWindowsWin32, i.e. Image.core.listwindows. That is an internal function that I can't see any references to, so I think it should be safe to just remove it.

GetWindowTextW(hwnd, PyUnicode_AS_UNICODE(title), title_size + 1);

EnumWindows(list_windows_callback, (LPARAM)window_list);

{"listwindows", (PyCFunction)PyImaging_ListWindowsWin32, METH_VARARGS},

I think this was intended to be used with ImageGrab.grab(bbox=Image.core.listwindows[...][...]) (i.e. what #4415 (comment) asked for), but it would not help with that issue as applications aren't always visible on the desktop.

@hugovk
Copy link
Member Author

hugovk commented Feb 11, 2023

Thanks, I've updated #6943.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature. Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants