ModuleNotFoundError in tracebacks with Python3.6 on linux
I solved this issue for Python 3.6 by first installing the python-apt package for Python 3:
sudo apt install python3-apt
After that, I changed to the dist-packages
directory and copied the apt_pkg[...].so
file to the new default file name apt_pkg.so
, to be also recognized by Python 3.6:
cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so
Now all ModuleNotFoundError: No module named 'apt_pkg'
exceptions disappeared on expectedly thrown error messages.
If most voted answer does not work for you please try below steps (Keep in mind you must change [version]):
- run this command
sudo apt install python3-apt
- go to directory
cd /usr/lib/python3/dist-packages
- run
ls
to find correct version ofapt_pkg.cpython-[version]-i386-linux-gnu.so
in my case it was35m
- create a symlink
sudo cp apt_pkg.cpython-[version]-i386-linux-gnu.so apt_pkg.so
DON'T FORGET: type your [version]
Troubleshouting
If you get error cp: cannot stat 'apt_pkg.cpython-[your-version]-i386-linux-gnu.so': No such file or directory
try commands below:
rm -rf apt_pkg.so
- create a symlink
sudo cp apt_pkg.cpython-[version]-i386-linux-gnu.so apt_pkg.so
DON'T FORGET: type your [version]
After I posted this question to Stackoverflow, Barry A. Warsaw made the following comment to the issue tracker
Please understand that installing Python 3.6 from a random PPA does not provide full support for this version of the interpreter. Python 3.6 is not yet a supported version in any version of Ubuntu (which I'm assuming your using), although we are working on it for 17.04.
Very often, you can install a new Python 3 interpreter package and many things will work because the Ubuntu infrastructure shares pure-Python modules across all installed Python 3's. Technically speaking, they will all have /usr/lib/python3/dist-packages on their sys.path so any third party pure-Python module built for a support version of Python 3 will be importable by any (package-built) installed version of Python 3.
But that 1) is a long way from saying that those third-party modules will work; 2) does not include any packages containing C extension modules, which must be rebuilt for the specific interpreter version.
Supporting a new version of Python is a long process, for which we are just starting. Please engage with [email protected] for details.
Ubuntu does install a standard exception handler so that when Python applications and such crash, we can gather crash statistics, so that we can devote resources to fixing common problems and regressions. apport (which you see in the traceback) is that crash reporting infrastructure. apport calls apt_pkg, which is an (C++) extension module and thus won't have been built for the version of Python 3.6 you installed from that PPA, unless of course the PPA owner (who I don't know) has also done an archive-wide Python 3 rebuild. Since I'm in the process of setting that up, and I know it's quite a bit of work, I doubt that's been done for this rather random PPA.
The ubuntu-devel mailing list is a better place to discuss the ongoing work to bring Python 3.6 as a supported version on Ubuntu.