I'm rather new to Ubuntu and I'm trying to run update-manager on Ubuntu 13.10. I get:
jacopo@jacopo-laptop:~$ update-manager
Traceback (most recent call last): File "/usr/bin/update-manager", line 28, in <module> from gi.repository import Gtk File "/usr/lib/python3/dist-packages/gi/__init__.py", line 27, in <module> from ._gi import _API
ImportError: No module named 'gi._gi'
Error in sys.excepthook:
Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, 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 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in <module>
import apt_pkg
ImportError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "/usr/bin/update-manager", line 28, in <module>
from gi.repository import Gtk
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 27, in <module>
from ._gi import _API
ImportError: No module named 'gi._gi'As far as I have understood, this is a problem related to the fact that I should have python3.4 installed. I installed it in /usr/local/lib, but I always get the same error. In this way I can't even upgrade to Ubuntu 14.04.
16 Answers
Reinstall apt_pkg using:
sudo apt-get install --reinstall python3-aptThe error is primarily because of library apt_pkg.cpython-35m-x86_64-linux-gnu.so not being present in /usr/lib/python3/dist-packages.
Removing and reinstalling should help.
7update-alternatives --set python3 /usr/bin/python3.6 6 for me the following steps worked:
cd /usr/lib/python3/dist-packages
sudo ln -s apt_pkg.cpython-{35m,34m}-x86_64-linux-gnu.sothe original solution is here:
2The following solution worked for me:
cd /usr/lib/python3/dist-packages
ls -la /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.soIf you get an error message saying too many levels of symbolic links as shown below:
cp: failed to access '/usr/lib/python3/dist-packages/apt_pkg.so': Too many levels of symbolic linksThen you need to simply unlink the apt_pkg.so file. Use the following command:
sudo unlink apt_pkg.soAnd then use the command
sudo cp apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.soHope this helps!
3For me this did the trick:
apt-get remove python3-apt
apt-get install python3-aptThis problem actually is similar to this one:apt-get broken: No module named debian.deb822
2The problem for me was that I installed python3.7 next to python3.6 and made it the default.
I manually run the following command:
ln -s /usr/bin/python3.6 /usr/bin/python3so python3 now points to the correct version of python ... that solves the issue.
7If you're trying to upgrade 13.10 to 14.04, try following these instructions. If you're just trying to update your current system from the command line, open a terminal and type the following:
sudo apt-get update
sudo apt-get dist-upgrade 4 This solution used to work for me after I had upgrade to either Python 3.6 or 3.7 and add-apt-repository stopped working:
cd /usr/lib/python3/dist-packages
# where 35m is the file you have and 38m corresponds to your Python version
sudo ln -s apt_pkg.cpython-{35m,38m}-x86_64-linux-gnu.soNow I have Python 3.8 and add-apt-repository stopped working again. I found another, related SO question, with this answer that worked for me. It appears that the expected filename is now just apt_pkg.so, so you have to do this:
cd /usr/lib/python3/dist-packages
# where 35m is the file you have
sudo ln -s apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.soThe fact that the new expected filename is just apt_pkg.so is promising. Hopefully it means we won't have to keep doing this dance every time there's a new minor version of Python!
I have managed to solve this by copying apt_pkg.cpython-34m-i386-linux-gnu.so to /usr/lib/python3/dist-packages/ from another desktop running Ubuntu 14.04 LTS. I have tried almost all possibilities found over internet like, purging python installation and then reinstalling, cleaning broken upgrade files etc, but ended up with no success.
Just an advise: I avoid installing "my" python on /usr/local, but I have one dedicated directory per python version (e.g. in /opt) and I'm using virtual environments on my user account to use the python I need, which is activated by my .profile
By this approach, you will always avoid to change the python system expected configuration and dependencies.
Well, I know, it's too late for your case, but...
For me below was worth full
mansoor@LDEVOPS-MANSOOR:~/Documents/clients/HR/DevopsSimulator$ cd /usr/lib/python3/dist-packages mansoor@LDEVOPS-MANSOOR:/usr/lib/python3/dist-packages$ sudo ln -s apt_pkg.cpython-38-x86_64-linux-gnu.so apt_pkg.so 1 I had the same issue after upgrading to python 3.9, and recreating the symlink '/usr/bin/python3' to point to the new location.
The only solution that worked for me, was that from a comment on the first answer, from @Kenivia: sudo apt remove --purge python3-aptthen sudo apt install python3-apt
This solved the error but uninstalled my ubuntu Software Center. But it was not a big deal, because I just reinstalled it with sudo apt install ubuntu-software and now everything seems to be working just fine
EDIT: some issue still persisted after this (update-manger kept giving errors and wouldn't start). So I had to go back and revert the symlink /usr/bin/python3 to point to the original python3.6 location. This solved everything
Just in case it helps another, I finally solved this problem, that was apparently caused by python version conflicts, by redirecting the link python3, then redirecting it to the right python version:
sudo rm /usr/bin/python3
sudo ln -s /usr/bin/python3.4You may need to enter the correct python version, found with
python3 -V 2 I faced same problem after upgrade ubuntu 19 to ubuntu 20. In ubuntu 20 default python version is 3.8 But some packages doesn't support this version. For this I downgraded default python version to 3.7 After downgrade I faced this shit problem.
This is downgrade documentation:
Let me tell you how to solve this problem.
python3.8
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt_pkg
>>> apt_pkg
<module 'apt_pkg' from '/usr/lib/python3/dist-packages/apt_pkg.cpython-38-x86_64-linux-gnu.so'>
>>> exitAs you can see there is a ".so" file for apt_pkg and it is located to "/usr/lib/python3/dist-packages/apt_pkg.cpython-38-x86_64-linux-gnu.so" Now if you link this file to "/usr/lib/python3/dist-packages/apt_pkg.cpython-37-x86_64-linux-gnu.so" then you can use this library in python 3.7. Please take care that I changed "38" to "37" in linked file. You must be root for make link.
sudo ln -s /usr/lib/python3/dist-packages/apt_pkg.cpython-38-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/apt_pkg.cpython-37-x86_64-linux-gnu.soProbably you can do same method for other python versions. If you change 38 to 36 then you can use this library in python 3.6...
I tried using @kodmanyagha 's answer, but no apt_pkg was found in the python environment. I solved it thanks to @saranjeet 's answer:
/usr/lib/python3/dist-packages$ sudo cp apt_pkg.cpython-35m-x86_64-linux-gnu.so apt_pkg.so Weird, I ended up with multiple versions of python 3.9, I had 3.9 and 3.9.12 in ls /usr/bin/pyth* when I checked my version I was on 3.9.12 but sudo update-alternatives --list only showed version 3.9. What I did was
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9.12 2
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1That got my sudo apt upgrade working, then I was able to just copy the .so file to apt_pkg.so
#You might need this if the package isn't there
#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
sudo apt upgrade