mhammond / pywin32

Python for Windows (pywin32) Extensions
4.92k stars 785 forks source link

[REQ] Install instructions for pywin32 under MingGW/msys2 #1552

Open brianddk opened 4 years ago

brianddk commented 4 years ago

There are notes in CHANGES.txt discussing work by @joankaradimov to make pywin32 buildable under MingGW/msys2

Significant work by @joankaradimov in porting pywin32 so that it works in a MingGW/msys2 environment.

but there are no relevant instructions in build_env.md as to how to build it.

There seems to be some interesting patches listed in mingw-w64-python-pywin32, but since it never released, its hard to tell how stale these patches are.

Doing the obvious stuff yields obvious errors

wget https://github.com/mhammond/pywin32/archive/b228.tar.gz
tar -xzvf b224.tar.gz
cd pywin32-b224
python setup.py install

yields

Building pywin32 3.8.228.0
running install
running build
running build_py
copying win32\lib/afxres.py -> build/lib.mingw-3.8/win32\lib

<... clip ...>

Refactoring build/lib.mingw-3.8/adodbapi/adodbapi.py
Refactoring build/lib.mingw-3.8/adodbapi/ado_consts.py
Refactoring build/lib.mingw-3.8/adodbapi/apibase.py
Refactoring build/lib.mingw-3.8/adodbapi/is64bit.py
Refactoring build/lib.mingw-3.8/adodbapi/process_connect_string.py
Refactoring build/lib.mingw-3.8/adodbapi/remote.py
Refactoring build/lib.mingw-3.8/adodbapi/schema_table.py
Refactoring build/lib.mingw-3.8/adodbapi/setup.py
Refactoring build/lib.mingw-3.8/adodbapi/__init__.py
running build_ext
Traceback (most recent call last):
  File "setup.py", line 2478, in <module>
    dist = setup(name="pywin32",
  File "<redacted>/.venv/lib/python3.8/site-packages/setuptools/__init__.py", line 165, in setup
    return distutils.core.setup(**attrs)

<... clip ...>

  File "<redacted>/msys64/mingw64/lib/python3.8/distutils/msvccompiler.py", line 602, in get_msvc_paths
    r"\Win32 (%s)\Directories" % (self.__root, platform))
AttributeError: 'my_compiler' object has no attribute '_MSVCCompiler__root'

Thoughts?

joankaradimov commented 4 years ago

There seems to be some interesting patches listed in mingw-w64-python-pywin32, but since it never released, its hard to tell how stale these patches are.

These are stale, yes. My patches are not included in the master for MINGW-packages yet. But you can find them here: https://github.com/joankaradimov/MINGW-packages/tree/pywin32-updates/mingw-w64-python-pywin32

Doing the obvious stuff yields obvious errors

You'll need to do a bunch more. See the prepare and build functions in pacman's PKGBUILD. And unfortunately -- even after that the build that's produced will not work on Python 3.8 -- most likely because of https://github.com/mhammond/pywin32/issues/1327.

Thoughts?

I'm interested in writing instruction and getting CI builds working for mingw. But I'd say it's too early now.

This is still a WIP. You can see the current progress here: https://github.com/msys2/MINGW-packages/pull/5615. It turned out to be quite the task. It included a bunch of patches in mingw-w64. A few more patches would need to be submitted in mingw to get mapi and propsys to compile. I'll also need to figure out a nicer way to distribute my SEH code (I might have some ideas). And some more stuff would need to be polished and brought in as pull requests here.

TL;DR It's too early. But if you're willing to experiment - you could get Python 2.7 to work by looking at this.

mhammond commented 4 years ago

even after that the build that's produced will not work on Python 3.8 -- most likely because of #1327.

I'd like to understand that issue better, but it's a commonly reported problem when there are duplicate DLLs etc installed (eg, from another or different installation). 3.8 installs seem to work OK on a clean system (although obviously not any mingw specific stuff).

It's too early. But if you're willing to experiment - you could get Python 2.7 to work by looking at this.

I'd advise against putting too much effort into anything 2.7 specific - I'm hoping to land https://github.com/mhammond/pywin32/pull/1510 in the next week or 2, which will remove all 2.x support forever.

That branch also has better CI integration which should make some things easier. Let me know if I can help further.

raedrizqie commented 3 years ago

Hi Mark and all..

I had successfully built pywin32 on mingw-w64. Using Python v3.5.2 (x64) & MinGW-w64 5.3.0 (mingw-build).

Here is the build log:

pywin32-220-3.5-w64-5.3.0-build.txt

Install log:

pywin32-220-3.5-w64-5.3.0-install.txt

Some changes are required to support UNICODE for the includes files from Win SDK 7.1 & Exchange.

I also had to use libs from winddk 7.1 in order to compile successfully: ADSIid.Lib Bits.Lib Htmlhelp.Lib MsXml2.Lib NtQuery.Lib propsys.lib RunTmChk.lib Uuid.lib windowscodecs.lib

Here is the patch:

pywin32-220_mingw-python.diff.txt

mhammond commented 3 years ago

Thanks - but that's a massive patch, and if it was against build 220, is almost certainly out of date. Any chance of a pull request?

QGB commented 1 year ago

嗨,马克和所有..

我已经在 mingw-w64 上成功构建了 pywin32。使用 Python v3.5.2 (x64) 和 MinGW-w64 5.3.0 (mingw-build)。

这是构建日志:

pywin32-220-3.5-w64-5.3.0-build.txt

安装日志:

pywin32-220-3.5-w64-5.3.0-install.txt

Win SDK 7.1 和 Exchange 中的包含文件需要进行一些更改才能支持 UNICODE。

我还必须使用 winddk 7.1 中的库才能成功编译: ADSIid.Lib Bits.Lib Htmlhelp.Lib MsXml2.Lib NtQuery.Lib propsys.lib RunTmChk.lib Uuid.lib windowscodecs.lib

这是补丁:

pywin32-220_mingw-python.diff.txt

could you provide the mingw_x64 pywin32 .whl file?

mhammond commented 1 year ago

could you provide the mingw_x64 pywin32 .whl file?

Not until it actually builds.

Avasam commented 4 months ago
wget https://github.com/mhammond/pywin32/archive/b228.tar.gz
tar -xzvf b224.tar.gz
cd pywin32-b224
python setup.py install

Note to readers that python setup.py and the use of setup.py as a command line tool are deprecated. pywin32 itself needs to move away from it. #2208