Skip to content

Failed to get pip from package python when rez-pip installing to a specific python version #2020

@annedol

Description

@annedol

When trying to install a package with rez-pip to a specific python version, the process does not properly detect the available python versions, so it throws an assertion error. there is no issue when I do not specify a specific python version and just use the one that rez was installed with.

Environment

  • Windows
  • Rez 3.2.1
  • Rez python version Python 3.11.6

My colleague also tried it with the following setup:

  • Linux
  • Rez 3.2.1
  • Rez python version 3.9.21

To Reproduce
I tried to install the package dotenv for python-3.9 using the following command:

rez pip --install dotenv --python-version 3.9 -r --verbose

I have a python-3.9 package that I create using rez-bind. I can use the python 3.9 package perfectly fine when resolving environments via commandline.

Expected behavior
I would expect the process to detect the pip inside the python-3.9 package that I created using rez bind.

Actual behavior
It is not correctly finding the python package, so it is throwing an assertion error.
Result on windows:

rez pip --install dotenv --python-version 3.9.13 -r --verbose
09:45:20 INFO     Trying to use pip from python package
09:45:21 DEBUG    Failed to get pip from package python
09:45:21 DEBUG
09:45:21 DEBUG
09:45:21 DEBUG    Needs pip>=19, but found 'None' for Python 'None'
09:45:21 INFO     Trying to use pip from pip package
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\ado\Documents\rez\Scripts\rez\rez.exe\__main__.py", line 7, in <module>
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\cli\_entry_points.py", line 69, in run_rez
    return run()
           ^^^^^
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\cli\_main.py", line 189, in run
    returncode = run_cmd()
                 ^^^^^^^^^
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\cli\_main.py", line 181, in run_cmd
    return func(opts, opts.parser, extra_arg_groups)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\cli\pip.py", line 52, in command
    pip_install_package(
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\pip.py", line 262, in pip_install_package
    py_exe, context = find_pip(pip_version, python_version)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\pip.py", line 92, in find_pip
    py_exe, found_pip_version, context = find_pip_from_context(
                                         ^^^^^^^^^^^^^^^^^^^^^^
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\pip.py", line 201, in find_pip_from_context
    py_exe = find_python_in_context(context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\users\ado\documents\rez\Lib\site-packages\rez\pip.py", line 141, in find_python_in_context
    assert python_package
AssertionError

Result on Linux:

rez-pip -i dotenv --python-version 3.11 --verbose
11:28:29 INFO     Trying to use pip from python package
11:28:29 DEBUG    Failed to get pip from package python
11:28:29 DEBUG    
11:28:29 DEBUG    Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pip'

11:28:29 DEBUG    Needs pip>=19, but found 'None' for Python 'None'
11:28:29 INFO     Trying to use pip from pip package
Traceback (most recent call last):
  File "/opt/rez/bin/rez/rez-pip", line 8, in <module>
    sys.exit(run_rez_pip())
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/_entry_points.py", line 183, in run_rez_pip
    return run("pip")
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/_main.py", line 189, in run
    returncode = run_cmd()
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/_main.py", line 181, in run_cmd
    return func(opts, opts.parser, extra_arg_groups)
  File "/opt/rez/lib64/python3.9/site-packages/rez/cli/pip.py", line 52, in command
    pip_install_package(
  File "/opt/rez/lib64/python3.9/site-packages/rez/pip.py", line 262, in pip_install_package
    py_exe, context = find_pip(pip_version, python_version)
  File "/opt/rez/lib64/python3.9/site-packages/rez/pip.py", line 92, in find_pip
    py_exe, found_pip_version, context = find_pip_from_context(
  File "/opt/rez/lib64/python3.9/site-packages/rez/pip.py", line 201, in find_pip_from_context
    py_exe = find_python_in_context(context)
  File "/opt/rez/lib64/python3.9/site-packages/rez/pip.py", line 141, in find_python_in_context
    assert python_package
AssertionError

The issue seems to be getting the correct python package, not detecting the pip that is installed in it. When I check the context._resolved_packages variable for the context created here, this is empty, even though the context successfully resolved, and the request did contain the python-3.9 requirement:

Result when I check this context:
package_request: ['python-3.9']
context: solved(python-3.9 ~platform==windows ~arch==AMD64 ~os==windows-10.0.19045.SP0 ==> platform-windows[] arch-AMD64[] os-windows-10.0.19045.SP0[] python-3.9.13[0])

Result when I use the _resolved_packages variable as seen in this function
context._resolved_packages: None

Related Issues/PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions