Executing a Python script using rez env and the required version of Python #1113
Replies: 2 comments 3 replies
-
If I understand this correctly, your python-3.8 package.py just needs to add something like this: def commands():
import sys
if sys.platform == 'win32':
# I haven't gotten aliases to work on windows
env.PATH.prepend(r'C:\Program Files\Python38')
elif sys.platform == 'darwin':
alias('python', '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3')
else:
alias('python', '<wherever python-3.8 is installed>') When pyhon-3.8 is included in a rez environment, it's executable is added as an alias (or directory added to the %PATH%). So when you go into a rez environment with python-3.8, |
Beta Was this translation helpful? Give feedback.
-
Could you share your python package? It seems that might be the culprit. If you add your python rez package paths to PATH in your package that should win over 2.7 on PATH as all rez package appended PATH entries are prepended to the system PATH. |
Beta Was this translation helpful? Give feedback.
-
Goal
Run a Python script (from a rez package) inside a rez environment with the version of Python specified in
requires
.Constraints
What we've tried
Using an alias to invoke an alias.
> rez env cli_tool -- run
This results in
python
inalias("run", "python {root}/src/cli_tool.py")
being found from PATH rather than thepython-3.8
rez package. In our case Python 2.7 is invoked rather than Python 3.8.There is a workaround where in the
python-3.8
package we addenv.PATH.prepend("{root}/bin")
. Thenpython
will use the Python 3.8 executable. Is there a more idiomatic approach to this goal?Beta Was this translation helpful? Give feedback.
All reactions