2

I know that ubuntu 18.04 LTS needs python 3.6 for doing a lot of its stuff, but I need to run a lot of python 3.7 applications and I don't get that why there is a conflict between them, I had to go over all non-running programs in /usr/bin and change the line #!/usr/bin/python3 to #!/usr/bin/python3.6 and I'm not sure if there are some more files I should change, and I'm worried someday my PC won't boot up 'cause of that :(

Is there a way to make that conflict go away and use only python3 command for everything?

P.S. I did a lot of searching and came up with nothing so if this is a duplicate question I'm sorry

Thank you all in advance :)

Edit:

This is the error log output when I run a system program with python3.7

Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 11, in <module>
    from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 28, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 11, in <module>
    from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 28, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

It's also the same if I run an app that needs 3.7 with the 3.6 version.

  • 2
    Keep good notes on each program changed. If system breaks boot with live usb and selectively reverse changes. – WinEunuuchs2Unix Jan 14 '20 at 22:56
  • @WinEunuuchs2Unix Yeah I forgot that Linux has such abilities, that's a very good idea in case I had to change them all, thanks :) – XamarinDev Jan 15 '20 at 01:50

1 Answers1

0

Hello I am not 100% sure what conflict you encounter. Why did you need to change those files in /usr/bin to use 3.6? What errors did you get and what is python3 pointing to right now?

The 'python3' is usually just a link, a pointer, to a particular python version on the system. If you need to work with different python versions there are a few different ways to do so. I will mention three that I commonly use:

  1. Use a virtual environment like conda. When you install conda you basically create a manager for virtual environments where you can install python modules or even python/pip versions without any impact to the outside system. I suggest you go check conda, especially if you are worried that you will break your system by changing python stuff.

  2. Run your scripts with a particular python version like

    python3.7 my_script.py

If you really want to use python3, you can just make an alias in your ~/.bashrc (or ~/.zshrc etc)

alias python3="/usr/bin/python3.7"

To check what binaries respond to the python command run

whereis python

This will give you the paths to all binaries, you can use these to make an alias like above. You can also use these to get more precise info:

whereis python3
which python3
which python3.7
  1. Add shebangs to your scripts and make them executable, this is maybe less portable and you seem to know about it already.
Andrei Dobre
  • 108
  • 4
  • the problem is I use Github projects a lot and some of them only work with a particular version of python, and they all used #!usr/bin/python3 it's not me who insist on using only python3 command it's them, they have only one version installed when making those programs so they don't worry about others, now I either have to change it in the old ones or in the new ones, BTW I'm currently running on Windows, I will soon edit my question and provide you with the error log when running with the version not supposed to. – XamarinDev Jan 15 '20 at 01:47