Reputation: 281
When I try:
sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
in Ubuntu, the terminal show this error message:
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'
I have two version of python, one is 2.7 the other is 3.5 .
How can I install this package on python3.5?
Upvotes: 28
Views: 42382
Reputation: 11
This worked for me :
sudo apt-get install python3-apt --reinstall
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so
Upvotes: 0
Reputation: 1799
I have found that everything that contains
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
Is a Python issue. To resolve it, one must set the correct python version. It depends on many factors what "correct version" means
sudo apt list --installed | grep python*
/usr/bin
ls -lha /usr/bin/python*
Traceback (most recent call last):
File "/usr/BAR/FOO # Is a python file and it varies
# For the case in this question the file is at
# /usr/bin/add-apt-repository
sudo
and add the "correct python version"#!/usr/bin/python3.6
# Above should be the first line of the file
Upvotes: 0
Reputation: 460
If you are using UBUNTU
, change to python3.8
version or install it
sudo apt install python3.8-dev
and after run
sudo apt-get install software-properties-common
Upvotes: 0
Reputation:
IMO, there is a neater solution to bypass the modification of a system file: sudo apt-get install --reinstall python3-apt
.
Upvotes: 0
Reputation: 301
I had the same issue with Ubuntu 20.04 and python3 pointing to python3.6.
I don't like to edit system file or similar (eg. /usr/bin/add-apt-repository) and change symlinks of certain commands (python is quite "special"). I suggest to follow the Ubuntu way to manage alternative versions of same command.
I had python3 pointing to python3.6 but python3.8 installed too so I updated alternatives to make coexist 3.6 and 3.8.
My proposed solution is to make python3 pointing to last installed version you have using thee "Ubuntu way" managing alternative.
sudo apt update && sudo apt upgrade && sudo apt install python3
python3 --version
which python3.8
sudo update-alternatives --config python3
If some are listed, check if last version installed is in and if it is choose it and you should solve your problem. Otherwise remember the highest value of Priority. Ubuntu will use the alternative with highest value. Exit typing Enter button.
Add last version installed as alternative. Here I use the dicimal part of version as priority. The command need python3
sudo update-alternatives /usr/bin/python3 python3 /usr/bin/python3.8 8
Upvotes: 0
Reputation: 483
ubuntu 18.04:
sudo vim /usr/bin/add-apt-repository
Change package header from python3
to python3.6
it's work for me
Upvotes: 18
Reputation: 343
Just chiming in since the version numbers may have changed.
Summary of fix: pointing my python3
to python 3.5 instead of 3.6
cd /usr/bin
rm python3
ln -s python3.5 python3
Detail: I had this same problem and found that /usr/bin/add-apt-repository
had a shebang hint to use /usr/bin/python3
which is pointing to 3.6. However I also have 3.5 on my system and have to toggle them often, so I toggled it back and add-apt-repository
now works.
Upvotes: 9
Reputation: 2818
I had something quite different than this. Mine failed with
No module named 'softwareproperties'
My solution is:
sudo vim /usr/bin/add-apt-repository
Change package header from `python3` to `python3.4` (or lower)
This may happen when you recently upgraded or added another python3
package.
Upvotes: 47