[lug] Running a mixed Python environment

D. Stimits stimits at comcast.net
Fri Sep 11 08:39:02 MDT 2020


I have not run into your exact situation, but have run into the system having confusion between Python 2 and 3 in Ubuntu 18.04. Lots of people have that issue. Normally "/usr/bin/python" is what the program tries to use, and this is in turn a symbolic link to either a version 2 Python or a version 3. Check:
   ls -l `which python`

There will a similar setup for version 2 and 3:
   ls -l `which python2`
   ls -l `which python3`

You could change the link in "/usr/bin/" for "python" to a different version, but then a lot of other scripts would probably break. If your app is something you can edit, then just specifically specify "python2" or "python3".

If you cannot edit your script, then create your own link in "/usr/local/bin" which points to the version of Python you want, and for your application, start it by changing the PATH to start with the local version:
   PATH="/usr/local/bin:$PaTH" yourPythonApp


> On 09/11/2020 8:13 AM Jed S. Baer <blug at jbaer.cotse.net> wrote:
> 
>  
> Hi Everyone.
> 
> I just finished up an install of Ubuntu 20.4. Of course, various things are
> broken. Anyways...
> 
> I have some Python scripts which still need to run under Python2. It
> exists, but some pieces are missing, and aren't in the repositories. The 2
> that come to mind are PyRSS2Gen and serial. I have them for Python3, but
> the scripts don't see them. Of course, it's a path issue. I've read that
> PyRSS2Gen works with both v2 and v3 scripts. I don't know about the Python3
> serial module.
> 
> Is fixing this as simple as setting up something like ~/python2 and putting
> it in PYTHONPATH, and then using pip (or setup.py) to put things there? I'm
> seeing references to "--user" installing to "HOME", but the articles don't
> go into any detail on that.
> 
> Once I get that figured, I assume I'll have to do some other thing to force
> running in Python2, maybe change the #! to /usr/bin/env python2? Or just
> /usr/bin/python2? (I guess there's no practical difference.)
> 
> If it creates any complications, 2 of the scripts run under invocation of
> Liferea to create RSS feeds. Those live in /usr/local/bin, but could just
> as well sit in ~/bin. Liferea is running under my username, but I'm
> uncertain of the environment - these days, I don't want to assume that
> anything from my bashrc or bash_profile is getting set. (No, I have no
> trust left.)
> 
> -- 
> All operating systems suck, but Linux just sucks less
>  - Linus Torvalds
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety


More information about the LUG mailing list