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

Meson build system error (v1.4.99) - blocked by group policy #13880

Open
MarquisKGlass opened this issue Nov 6, 2024 · 12 comments
Open

Meson build system error (v1.4.99) - blocked by group policy #13880

MarquisKGlass opened this issue Nov 6, 2024 · 12 comments
Labels
compilers OS:windows Winodows OS specific issues

Comments

@MarquisKGlass
Copy link

Describe the bug
Trying to create a Python environment in VSCode. When running, an error occurs stating that a program is blocked by our group policy. We have so many policies in place, it isn't clear which one may be blocking it. Is there a way to get more details? Seems to be happening in NumPy. Submitting bug here since the error logs say it is a bug with Meson and should be reported.

To Reproduce
Don't think it can be reproduced, as it is something with our policies. IT has reviewed all of them, and nothing jumps out at them as an issue. Attached is the output file. Key lines are 206 and 261.

Expected behavior
We expect meson to run successfully. Ran using the VSCode command "Python: Create Environment", "Venv", "Delete and Recreate"/"New", "Python 3.13.0 64 bit", selected "requirements.txt".

system parameters

  • Native build
  • Windows 10
  • Python 3.13.0
  • Meson Version 1.4.99
  • NumPy version - 2.0.1

Output.txt

@eli-schwartz
Copy link
Member

eli-schwartz commented Nov 6, 2024

We have so many policies in place, it isn't clear which one may be blocking it. Is there a way to get more details?

      The Meson build system
      Version: 1.4.99
      Source dir: {LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5
2024-11-06 09:38:50.147 [info]     Build dir: {LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\.mesonpy-1mi7ybxs
      Build type: native build
      Project name: NumPy
      Project version: 2.0.1
      Activating VS 17.0.5
      This program is blocked by group policy. For more information, contact your system administrator.
      Traceback (most recent call last):
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\mesonmain.py", line 188, in run
          return options.run_func(options)
                 ~~~~~~~~~~~~~~~~^^^^^^^^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\msetup.py", line 363, in run
          app.generate()
2024-11-06 09:38:50.147 [info] 
          ~~~~~~~~~~~~^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\msetup.py", line 187, in generate
          return self._generate(env, capture, vslite_ctx)
                 ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\msetup.py", line 209, in _generate
          intr = interpreter.Interpreter(b, user_defined_options=user_defined_options)
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreter\interpreter.py", line 320, in __init__
          self.parse_project()
          ~~~~~~~~~~~~~~~~~~^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\interpreterbase.py", line 129, in parse_project
2024-11-06 09:38:50.147 [info]         self.evaluate_codeblock(self.ast, end=1)
          ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\interpreterbase.py", line 195, in evaluate_codeblock
          raise e
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\interpreterbase.py", line 187, in evaluate_codeblock
          self.evaluate_statement(cur)
          ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\interpreterbase.py", line 201, in evaluate_statement
          return self.function_call(cur)
                 ~~~~~~~~~~~~~~~~~~^^^^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\interpreterbase.py", line 528, in function_call
          res = func(node, func_args, kwargs)
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\decorators.py", line 250, in wrapper
2024-11-06 09:38:50.147 [info]           return f(*nargs, **wrapped_kwargs)
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreterbase\decorators.py", line 569, in wrapper
          return f(*wrapped_args, **wrapped_kwargs)
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\interpreter\interpreter.py", line 1308, in func_project
          mesonlib.setup_vsenv(force_vsenv)
          ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\utils\vsenv.py", line 121, in setup_vsenv
          return _setup_vsenv(force)
        File "{LocalUserPath}\AppData\Local\Temp\pip-install-cu2w66bf\numpy_2e41ccae8d5a4cf9b1ed14f818f3c2a5\vendored-meson\meson\mesonbuild\utils\vsenv.py", line 97, in _setup_vsenv
          bat_output = subprocess.check_output(bat_file.name, universal_newlines=True,
2024-11-06 09:38:50.147 [info]                                           encoding=locale.getpreferredencoding(False))
        File "{LocalUserPath}\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 472, in check_output
          return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
                 ~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     **kwargs).stdout
                     ^^^^^^^^^
        File "{LocalUserPath}\AppData\Local\Programs\Python\Python313\Lib\subprocess.py", line 577, in run
          raise CalledProcessError(retcode, process.args,
                                   output=stdout, stderr=stderr)
2024-11-06 09:38:50.148 [info] 
      subprocess.CalledProcessError: Command '{LocalUserPath}\AppData\Local\Temp\tmp08d1_b1b.bat' returned non-zero exit status 1.
      
      ..\meson.build:1:0: ERROR: Unhandled python exception
      
          This is a Meson bug and should be reported!

Meson attempts to take this code:

bat_template = '''@ECHO OFF
call "{}"
ECHO {}
SET
'''

and format it and run it as a batch script:

mlog.log('Activating VS', bat_info[0]['catalog']['productDisplayVersion'])
bat_separator = '---SPLIT---'
bat_contents = bat_template.format(bat_path, bat_separator)
bat_file = tempfile.NamedTemporaryFile('w', suffix='.bat', encoding='utf-8', delete=False)
bat_file.write(bat_contents)
bat_file.flush()
bat_file.close()
bat_output = subprocess.check_output(bat_file.name, universal_newlines=True,
encoding=locale.getpreferredencoding(False))

(bat_path is going to be the vswhere.exe returned location for vcvars*.bat.)

It does not allow for the possibility of the batch script failing, so "check_output" raises a python-level traceback -- and raising a python-level traceback is standardly considered to be a UX bug in meson as we should catch exceptions and raise error messages instead.

The issue is that apparently running AppData\Local\Temp\tmp08d1_b1b.bat will print out

This program is blocked by group policy. For more information, contact your system administrator.

and error out. Meson can do without this batch script, if and only if you run pip install from a shell that has already set up Visual Studio's vcvars*.bat environment scripts.

We could likely make the error message better, of course. :)

@eli-schwartz eli-schwartz added compilers OS:windows Winodows OS specific issues labels Nov 6, 2024
@MarquisKGlass
Copy link
Author

Apologies, this is a project we are inheriting from a contractor, and our company doesn't use python, so we are all learning how it works.

So for the pip install, that should just be run in the root of our project? Also not sure what you mean by the environment scripts, since this error is occurring when I am trying to create the environment in the first place.

@eli-schwartz
Copy link
Member

Apologies, this is a project we are inheriting from a contractor, and our company doesn't use python, so we are all learning how it works.

No problem, happy to help either way. :) I'm trying to explain the context as I go.

So for the pip install, that should just be run in the root of our project?

Meson doesn't care one way or another, but I believe VS Code does run pip there, yeah.

Also not sure what you mean by the environment scripts, since this error is occurring when I am trying to create the environment in the first place.

There are a couple different "environments" applicable here. VS Code tries to set up a python environment. That entails running meson as a buildsystem tool during the process.

Meson wants to set up a MSVC compiler environment so it can run cl.exe to compile code. Unfortunately, the only way to successfully run Microsoft's compiler is to execute a Microsoft-supplied batch script inside of a command prompt and have it set a bunch of weird environment variables (!!!) and meson tries to automatically do that for you, on your behalf.

Without access to MSVC's own cl.exe, meson would otherwise error out saying "ERROR: cannot find a C compiler".

@MarquisKGlass
Copy link
Author

Well, 'pip install' just errors out when it is run, since it needs the "what" for what to install. I also don't see that "cannot find a C compiler" error in the output. Is there a way to run Meson manually to set the environment variables, or do you have a list of variables needed so I can manually add them to the %PATH%?

@eli-schwartz
Copy link
Member

Unfortunately Microsoft doesn't document a list of variables needed, the only official way to do that is to execute their batch script.

@eli-schwartz
Copy link
Member

Maybe another, better question: your log says you are using the brand new Python 3.13 release, which I guess makes sense as VS Code is probably saying "newer is better".

But projects like numpy provide prebuilt binary releases, which can be installed by pip install by default, only for versions of Python that were available when that numpy version was released.

Ran using the VSCode command "Python: Create Environment", "Venv", "Delete and Recreate"/"New", "Python 3.13.0 64 bit", selected "requirements.txt".

So if you try selecting Python 3.12 here instead of Python 3.13.0, your requirements.txt would install successfully.

2024-11-06 09:38:14.504 [info] Collecting numpy==2.0.1 (from -r {LocalUserPath}\Desktop\Projects\{ProjectName}\dbt\requirements.txt (line 44))

It requires numpy version 2.0.1, and from the release artifacts page at https://pypi.org/project/numpy/2.0.1/#files

numpy-2.0.1-cp312-cp312-win_amd64.whl (16.3 MB view hashes)

Uploaded Jul 21, 2024 CPython 3.12 Windows x86-64

But no versions are listed that say they are compatible with CPython 3.13, so it instead downloads the source code and tries to recompile it from scratch.

@MarquisKGlass
Copy link
Author

I will try with 3.12. I only have the newest installed, so will have to add it.

@eli-schwartz
Copy link
Member

@rgommers

@MarquisKGlass
Copy link
Author

Looks like that solved the problem. Thank you for your time. Could be useful to add error messages for python version, but it is also another product, so makes sense if you don't want to.

I will reach out to the contractors, as they were insisting you had to install the latest version.

@eli-schwartz
Copy link
Member

It's interesting that they are insisting to install the latest version of Python.

The requirements.txt says that numpy version 2.0.1 shall be used, which isn't the latest version of numpy -- the latest version of numpy is version 2.1.3, and that comes with prebuilt binary artifacts for Python 3.13

It is usually the case that if you want to upgrade to a brand new release of Python, you will also need to take a look at upgrading your thirdparty modules (like numpy) as well. Both in order to ensure that you can use prebuilt binary artifacts, and because often there are code changes in the thirdparty module that are needed in order to adapt to the new Python release.

@rgommers
Copy link
Contributor

rgommers commented Nov 7, 2024

Using NumPy 2.0.1 + Python 3.12, or using NumPy 2.1.3 + Python 3.13 sounds like the right answer. NumPy 2.0.1 doesn't even support Python 3.13, so definitely don't try to build it from source.

Meson can do without this batch script, if and only if you run pip install from a shell that has already set up Visual Studio's vcvars*.bat environment scripts.

We could likely make the error message better, of course. :)

That's like the one actionable thing here on the Meson side it looks like?

@MarquisKGlass
Copy link
Author

Yeah, that is about it. Everything else has been figured out. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compilers OS:windows Winodows OS specific issues
Projects
None yet
Development

No branches or pull requests

3 participants