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

Unexpected python executable can be used by rez-pip #45

Closed
SuperValou opened this issue Oct 4, 2023 · 4 comments · Fixed by #47
Closed

Unexpected python executable can be used by rez-pip #45

SuperValou opened this issue Oct 4, 2023 · 4 comments · Fixed by #47
Labels
bug Something isn't working

Comments

@SuperValou
Copy link
Contributor

In some cases, rez-pip can unexpectedly use a python executable found on your machine instead of a rezified python package.

Environment

  • Windows 10.0
  • rez-pip 0.2.0
  • rez-pip being installed in its own virtual environment, not part of a rez installation

To Reproduce

  • Create an empty file named python3.exe in some arbitrary folder, e.g. "C:\foo\python3.exe"
  • Rezify a python interpreter through this utility
  • Install rez-pip into its own virtualenv
    • open a terminal
    • run rez env python -- python -m venv C:\rez-pip to generate a virtualenv that will host the rez-pip package
    • run cd C:\rez-pip\Scripts then .\activate to enter the virtualenv
    • run python -m pip install rez-pip to install rez-pip in the virtualenv
  • Through the Windows Configuration panel, add "C:\foo" at the end of your PATH environment variable
  • open a terminal
  • run cd C:\rez-pip\Scripts then .\activate to enter the virtualenv of rez-pip
  • run .\rez-pip2.exe future
  • see the error:
> .\rez-pip2.exe future
INFO     Installing requested packages for Python 3.7.7
Traceback (most recent call last):
  File "\\ ... \packages\python\3.9.10\platform-windows\arch-AMD64\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "\\ ... \packages\python\3.9.10\platform-windows\arch-AMD64\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\rez-pip\Scripts\rez-pip2.exe\__main__.py", line 7, in <module>
  File "C:\rez-pip\lib\site-packages\rez_pip\cli.py", line 318, in run
    _run(args, pipArgs, pipWorkArea)
  File "C:\rez-pip\lib\site-packages\rez_pip\cli.py", line 176, in _run
    packages = rez_pip.pip.getPackages(
  File "C:\rez-pip\lib\site-packages\rez_pip\pip.py", line 106, in getPackages
    process = subprocess.Popen(
  File "\\ ... \packages\python\3.9.10\platform-windows\arch-AMD64\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "\\ ... \packages\python\3.9.10\platform-windows\arch-AMD64\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 not a valid Win32 application

Expected behavior
Program installs future as a rez package.

Actual behavior
The exception above occurs.

Investigation
The error is due to this line checking for a "python3.exe" in PATH before checking for "python.exe". The empty python3.exe we created gets found before the python.exe of our rezified python.

Possible suggestions

  • If the rezified python package provides python in its tools section, directly use "python" instead of attempting "python3.7", "python3" then "python"
  • check that the result of which is a under the root of a rezified python package

Note
IMO being able to use an arbitrary python executable instead of the one provided by a rezified python package could be interesting, but it should be an explicit behaviour requested by the user; the default behavior of rez-pip should be to only use a rezified python package.

@SuperValou
Copy link
Contributor Author

Attempting to pass parent_environ={} to which (here) doesn't work because ultimately the ResolvedContext object creates a RexExecutor that appends PATH anyway. See here to check the call stack at the point where PATH gets added

@SuperValou
Copy link
Contributor Author

Maybe we can replicate the behaviour of find_python_in_context by setting ResolvedContext.append_sys_path = False (like here) right before this line

@JeanChristopheMorinPerso
Copy link
Owner

@SuperValou I created a PR, #47, could you try it to see if it works as you expect please?

@SuperValou
Copy link
Contributor Author

@JeanChristopheMorinPerso Yes it does! Thanks 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants