rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

Windows: `pywin32` doesn't work with the hermetic Python toolchain

Open meteorcloudy opened this issue 2 years ago • 11 comments

🐞 bug report

Affected Rule

rules_python

Is this a regression?

Probably not.

Description

I'm trying to do import win32api on Windows, but got

ModuleNotFoundError: No module named 'win32api'

even if I specify pywin32==303 in the requirements.txt file.

🔬 Minimal Reproduction

Fetch the reproducible case at https://github.com/meteorcloudy/my_tests/tree/master/pywin32_test

then run

bazel run //:bin

🔥 Exception or Error




$ bazel run //:bin
INFO: Invocation ID: 3c7000e6-65e3-4816-a2b5-551faa933a03
INFO: Reading 'startup' options from c:\users\pcloudy\.bazelrc: --output_user_root=C:/src/tmp
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=375
INFO: Options provided by the client:
  Inherited 'build' options: --python_path=C:/python3/python.exe
INFO: Reading rc options for 'run' from c:\users\pcloudy\.bazelrc:
  Inherited 'build' options: --curses=yes --color=yes --verbose_failures --announce_rc --disk_cache=C:/src/tmp/bazel_disk_cache
INFO: Analyzed target //:bin (40 packages loaded, 3463 targets configured).
INFO: Found 1 target...
Target //:bin up-to-date:
  bazel-bin/bin.exe
  bazel-bin/bin.zip
INFO: Elapsed time: 15.868s, Critical Path: 7.96s
INFO: 6 processes: 5 internal, 1 local.
INFO: Build completed successfully, 6 total actions
INFO: Running command line: bazel-bin/bin.exe
Traceback (most recent call last):
  File "C:\temp\2\Bazel.runfiles_s_pq9z9_\runfiles\__main__\bin.py", line 1, in 
    import win32api
ModuleNotFoundError: No module named 'win32api'

🌍 Your Environment

Operating System:

  
Windows
  

Output of bazel version:

  
6.3.1
  

Rules_python version:

  
0.24.0
  

Anything else relevant? If I do import win32.win32api, I get

ImportError: DLL load failed while importing win32api: The specified module could not be found.

meteorcloudy avatar Aug 02 '23 13:08 meteorcloudy

Given that pywin32 is on its way out, should we care about this here? What would be the use case for supporting this?

aignas avatar Nov 05 '23 13:11 aignas

It's used in Bazel's python integration test: https://cs.opensource.google/bazel/bazel/+/master:src/test/py/bazel/launcher_test.py;l=673?q=%22win32api%22&ss=bazel

What is the alternative of pywin32? For us, we only need the win32api.GetShortPathName API.

meteorcloudy avatar Nov 06 '23 12:11 meteorcloudy

I think I misspoke about pywin32 and we should probably investigate what is going on.

On 6 November 2023 21:42:41 GMT+09:00, Yun Peng @.***> wrote:

It's used in Bazel's python integration test: https://cs.opensource.google/bazel/bazel/+/master:src/test/py/bazel/launcher_test.py;l=673?q=%22win32api%22&ss=bazel

What is the alternative of pywin32? For us, we only need the win32api.GetShortPathName API.

-- Reply to this email directly or view it on GitHub: https://github.com/bazelbuild/rules_python/issues/1356#issuecomment-1794734761 You are receiving this because you commented.

Message ID: @.***>

aignas avatar Nov 06 '23 22:11 aignas

I think it could be related to https://github.com/indygreg/PyOxidizer/issues/442

aignas avatar Nov 07 '23 01:11 aignas

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

github-actions[bot] avatar May 05 '24 22:05 github-actions[bot]

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

github-actions[bot] avatar Jun 05 '24 22:06 github-actions[bot]

@meteorcloudy

If we are willing to try again, there is a random option from Stackoverflow that might help you avoid the dependency. https://stackoverflow.com/a/23598461

I would try it myself if I had easy access to a Windows environment.

The prebuilt indygreg interpreters struggle when they hit Tkinter or wxPython, so if you can avoid those, then you will have an easier time.

groodt avatar Jun 19 '24 04:06 groodt

@groodt Thanks, the launcher_test is the only blocker for enabling hermetic python toolchain on Windows, which basically means removing https://github.com/bazelbuild/bazel/blob/24ef85f2f7aa827eeb4595e93b0a0985409d84f4/.bazelrc#L28-L31. If you want to give it a try to test the approach, a PR is welcome!

meteorcloudy avatar Jun 19 '24 08:06 meteorcloudy

@meteorcloudy Must be our lucky day... that actually worked! https://github.com/bazelbuild/bazel/pull/22799

Time to buy a lottery ticket!

groodt avatar Jun 19 '24 10:06 groodt

Amazing, thanks a lot!

meteorcloudy avatar Jun 19 '24 10:06 meteorcloudy