rez
rez copied to clipboard
rez-pip fails if the user has not run `rez-bind` for a specific Python version
Summary
It looks like, when rez-pip runs with a Python version, it attempts to resolve for that version + pip. And if a pip package exists, but not for that Python version, rez-pip fails midway instead of installing the PyPI package using a different resolve.
Reproduction Steps
cd rez
git checkout 2.72.0
python install.py -v ~/rez
export PATH=~/rez/bin/rez:$PATH
source ~/rez/completion/complete.sh
rez-bind python
rez-bind pip
rez-bind python --exe `which python3` # In my case, Python 3.6
rez-pip --install parso --python-version=3.6
Error Encountered
Traceback (most recent call last):
File "/home/selecaoone///rez-2.72.0-python-2.7/bin/rez/rez-pip", line 8, in <module>
sys.exit(run_rez_pip())
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/_entry_points.py", line 178, in run_rez_pip
return run("pip")
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/_main.py", line 170, in run
returncode = run_cmd()
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/_main.py", line 162, in run_cmd
return func(opts, opts.parser, extra_arg_groups)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/pip.py", line 76, in command
extra_args=opts.extra)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 261, in pip_install_package
py_exe, context = find_pip(pip_version, python_version)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 95, in find_pip
python_version, pip_version=version
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 203, in find_pip_from_context
py_exe = find_python_in_context(context)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 142, in find_python_in_context
python_package = context.get_resolved_package("python")
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/resolved_context.py", line 434, in get_resolved_package
pkgs = [x for x in self._resolved_packages if x.name == name]
TypeError: 'NoneType' object is not iterable
Suggested Fix?
Add this code:
if context.status == ResolverStatus.failed:
print_error('Package request "%s" could not be resolved.', package_request)
return None, None, None
Here: https://github.com/nerdvegas/rez/blob/master/src/rez/pip.py#L202
When I do this, it fails to resolve the package_request, ["python-3.6", "pip"], but finds another context which it can resolve. And then the package installs properly.
Hi,
I have the same problem, I am binding a version of python (installed with asdf) different that the system one and pip is not bind by default. Running rez pip --install with that version doesn't work.
By the way is it possible to bind pip using rez bind?
Because this doesn't work:
$ pip --version
pip 20.1.1 from /home/josephhenry/.asdf/installs/python/3.7.9/lib/python3.7/site-packages/pip (python 3.7)
$ rez bind pip
searching /opt/rez/lib/python3.9/site-packages/rez/bind...
creating package 'pip' in /home/josephhenry/packages...
00:41:03 WARNING Skipping installation: Package variant already exists: /home/josephhenry/packages/pip/20.3.4/package.py[0]
Edit
I found a solution:
I actually installed rez with python3.9 so I reinstalled it with python3.7 after switching python version with asdf and it works now!
Related to #1325