2

hi after installed python 3.5 in ubuntu, i had 2.7.6 and i wanted to be updated cause i will be working and learning python, so i installed the latest python version 3.5 and switched version to it, i have python 2.7 & 3.5 installed but set it to 3.5 as default, after making that change and update i got this error:

$ sudo add-apt-repository ppa:example/example -y
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 27, in <module>
    import apt_pkg
ImportError: No module named 'apt_pkg'

at the moment is the only one i encounter besides cant remove any python version it would break the system ,any help about how to fix it? :(

$ update-alternatives --query python
Name: python
Link: /usr/bin/python
Status: manual
Best: /usr/bin/python3.5
Value: /usr/bin/python2.7
Alternative: /usr/bin/python2.7
Priority: 1
Alternative: /usr/bin/python3.5
Priority: 2

$ ls -l /usr/bin/python3.5 /usr/bin/python2.7
-rwxr-xr-x 2 root root 3754856 dic 18 09:58 /usr/bin/python3.5
-rwxr-xr-x 1 root root 3345416 jun 22  2015 /usr/bin/python2.7
8
  • 1
    What version of Ubuntu are you using? How exactly did you install python 3.5, and how did you make it the default? – steeldriver Jan 6 '16 at 23:16
  • 14.04 , i installed from a official ppa and then, i make it default using this instructions... bit.ly/1n55JEC (system wide) – Alexdmz Jan 6 '16 at 23:20
  • If you used the update-alternatives method described in your link, then you should be able to set it back by running update-alternatives --config python and following the on-screen instructions to select python2.7 – steeldriver Jan 6 '16 at 23:29
  • i did that, but the problem still, even if i reboot the pc – Alexdmz Jan 6 '16 at 23:30
  • 1
    Please edit your question to include the outputs of the following commands: update-alternatives --query python, readlink -f $(which python), ls -l /usr/bin/python?.? – steeldriver Jan 6 '16 at 23:35
0

For Python3.5 use the command

alias python=python3.5

and for Python2.7 use

alias python=python2.7
0

See https://stackoverflow.com/a/56234758/52817:

If you look at /usr/bin/add-apt-repository it says

#! /usr/bin/python3

at the top. If you updated with a newer python (e.g. dist had 3.5 but you installed 3.7) your /usr/bin/python3 points to a python that does not have apt_pkg.

You can temporarily edit /usr/bin/add-apt-repository to point to

#! /usr/bin/python3.5

(insert your distro python version)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.