GNOME Bugzilla – Bug 688353
PYTHONPATH wrong when using python 3
Last modified: 2021-05-17 15:55:29 UTC
I'd expect this to work:
# jhbuild run python3 -c "import cairo"
Traceback (most recent call last):
from _cairo import *ImportError: No module named _cairo
PYTHONPATH is wrong.
Comment from Frederic Peters bug 688062 comment 5:
It would have been much easier if Python 3 had a different environment variable
(looks like that was discussed in <http://bugs.python.org/issue2375>); actually
I don't know, I have no idea how we're supposed to get both python versions to
So far I got by with running python3-y stuff in jhbuild with an explicit
PYTHON=python3 jhbuild run ...
which tells jhbuild to set the correct $PYTHONPATH for the py3 libs. However, as much as a $PYTHON3PATH would have made sense (as in practice python 3 is a different language), I guess it's too late for this now.
I don't really have a good solution for this, as jhbuild cannot know in advance whether you are going to call py2 or py3 (or even both).
The only thing that comes to my mind is a hack:
* Let jhbuild set up PYTHONPATH for python3, as this will over time become "the" python.
* Install a "python" and "python2" shell script wrapper alongside the "jhbuild" binary (i. e. in ~/.local/bin) which modifies $PYTHONPATH for python2, and then execs the real python with all arguments.
Does anybody have a better idea?
maybe jhbuild could install both "jhpython" and "jhpython3" wrapper scripts that set the PYTHONPATH properly and then export PYTHON=jhpython and PYTHON3=jhpython3
But usually projects use $PYTHON to determine exactly that -- which python version to run. If that would work, we could just set PYTHON3=python and be done with it. :-)
> we could just set PYTHON3=python
Err, PYTHON3=python3, of course.
(In reply to comment #4)
> But usually projects use $PYTHON to determine exactly that -- which python
> version to run. If that would work, we could just set PYTHON3=python and be
> done with it. :-)
No what I mean is that those wrappers would only be used in "jhbuild run" and not "jhbuild build". So a program with "#!/bin/env python3" would get "jhpython3" as the interpreter and that in turn would set up the right PYTHONPATH
Ah, but then I think it would be better to have a jhbuild specific python3 wrapper which sets up $PYTHONPATH correctly and calls the real python3. Then we do not require programs to respect $PYTHON.
-- GitLab Migration Automatic Message --
This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.
You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/jhbuild/-/issues/154.