ModuleNotFoundError in tracebacks with Python3.6 on linux - python-3.x

I installed Python 3.6 on Ubuntu 16.04 by using Jonathon Fernyhough's PPA:
sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6
I made a string, using the new literal string interpolation, but I supplied an invalid format specifier. I not only got the expected ValueError: Invalid format specifier, but also the unexpected ModuleNotFoundError: No module named 'apt_pkg'.
$ python3.6
Python 3.6.0 (default, Dec 29 2016, 21:40:36)
[GCC 5.4.1 20161202] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> value = 4 * 20
>>> f'the value is {value:%A}'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Invalid format specifier
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 23, 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 "<stdin>", line 1, in <module>
ValueError: Invalid format specifier
I reported this to the Python bug tracker. There it was noted that:
It seems to be vendor's issue not CPython itself. This same issue also happens in Ubuntu 16.10's Python 3.6. Raise any exception can cause this:
Python 3.6.0b2 (default, Oct 11 2016, 05:27:10)
[GCC 6.2.0 20161005] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> raise Exception
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception
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 23, 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 "<stdin>", line 1, in <module>
Exception
>>>
Also see https://bugs.launchpad.net/ubuntu/+source/python3.6/+bug/1631367.
Finally, the issue was closed with the comment
Yes, this appears to be the vendor's failure reporting infrastructure
that is failing. Why they'd want a report for every traceback at the
interactive prompt is beyond me, but that appears to be what they are
trying to do.
My questions now are:
How do I interpret this comment? Is the vendor in this case Jonathon Fernyhough's PPA? And did he change something to to the Python code he distributes so that it tries to file a report for every Exception that produces a traceback?
Who do I need to notify or where do I need to file a bug to get this resolved?

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.

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 ubuntu-devel#ubuntu.com 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.

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 of apt_pkg.cpython-[version]-i386-linux-gnu.so in my case it was 35m
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]

I removed python3-apt and that seems to have solved it for Python 3.8
sudo apt-get remove --purge python3-apt
sudo apt-get install python3-apt

Related

CuPy import failing due to missing DLL file although it appears in my directories

I am attempting to use cuPy to speed up some background numpy operations in my python code but when attempting to import cupy I am told that the DLL load failed and the module could not be found, cupy_backends.cuda.libs import nvrtc. (Specific errors at end of post)
I've attempted almost everything the error message suggests. I check my version of cupy and cuda which are cupy-cuda111==8.4.0, I have Cuda 11.2 installed as well. I am running Windows 10 and Python 3.7.6 on Spyder 3. I have tried uninstalling cupy via pip uninstall in hopes of reinstalling correctly but it just hangs and never uninstalls the package.
It appears I have the file its looking for when I go search manually via my file explorer. (Imaged Below)
I am fairly inexperienced when it comes to handling things like this so any help would be greatly appreciated. The entire error message and trace is copied below:
import cupy as cp
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\__init__.py", line 20, in <module>
from cupy import core # NOQA
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\core\__init__.py", line 1, in <module>
from cupy.core import core # NOQA
File "cupy\core\core.pyx", line 1, in init cupy.core.core
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\cuda\__init__.py", line 5, in <module>
from cupy.cuda import compiler # NOQA
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\cuda\compiler.py", line 14, in <module>
from cupy_backends.cuda.libs import nvrtc
ImportError: DLL load failed: The specified module could not be found.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<ipython-input-1-e011b0e859cc>", line 1, in <module>
import cupy as cp
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\__init__.py", line 41, in <module>
raise ImportError(_msg) from e
ImportError: CuPy is not correctly installed.
If you are using wheel distribution (cupy-cudaXX), make sure that the version of CuPy you installed matches with the version of CUDA on your host.
Also, confirm that only one CuPy package is installed:
$ pip freeze
If you are building CuPy from source, please check your environment, uninstall CuPy and reinstall it with:
$ pip install cupy --no-cache-dir -vvvv
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
original error: DLL load failed: The specified module could not be found.

distutils.util missing after upgrading to 3.8

I just upgraded to Pop OS(Ubuntu) 20.04, which upgraded Python 3.7 to 3.8. Now I get this error below when I run sam (from the AWS SAM CLI). Solutions found online all had to do with making sure python3-distutils is installed. I have verified that python3-disutils is installed. /usr/lib/python3.8/distutils looks fine, just not getting picked up for some reason.
One thing I noticed is that in the traceback below, it's using the system-wide pip, while I have a later version of pip installed under my .local. I don't know if those two symptoms are related but looks like I'm missing some config somewhere so none of the 3.8 or user space stuff is picked up.
Build Failed
Error: PythonPipBuilder:ResolveDependencies - Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pip/_internal/main.py", line 14, in main
from pip._internal.utils.entrypoints import _wrapper
File "/usr/lib/python3/dist-packages/pip/_internal/utils/entrypoints.py", line 3, in <module>
from pip._internal.cli.main import main
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 19, in <module>
from distutils.util import strtobool
ModuleNotFoundError: No module named 'distutils.util'
I have the same issue on Debian Bullseye (or rather mixed Bullseye/Buster).
Package python3-distutils (3.8.6) contains module for Python 3.8 and 3.9 (!).
Old package (3.7.3) for Python 3.7. You have to choose.
My workaround is just copy module.
mkdir -p /usr/lib/python3.7/distutils
cp -a /usr/lib/python3.8/distutils/* /usr/lib/python3.7/distutils/

numpy import error ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

I got the following numpy error. I have tried 1. But it did solve the problem. Would you please let me know how to fix the problem? Thanks.
$ python3
Python 3.8.0a3 (v3.8.0a3:9a448855b5, Mar 25 2019, 17:05:20)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/multiarray.py", line 14, in <module>
from . import overrides
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/numpy/core/__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.8 from "/Library/Frameworks/Python.framework/Versions/3.8/bin/python3",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: No module named 'numpy.core._multiarray_umath'
The problem is that I had Python 3.8.0a3 installed. I updated it to 3.8.1. Now the problem is solved.

NameError: name 'unicode' is not defined when I install package - Python 3

I'm trying to install the package. But there is the error. How can I fix it?
C:\WINDOWS\system32>python -m pip install zopyx.convert2
Collecting zopyx.convert2
Using cached zopyx.convert2-2.4.6.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Admin\AppData\Local\Temp\pip-build-e90y11sx\zopyx.convert2\setup.py", line 17, in <module>
desc = unicode(file(os.path.join('docs', 'source', 'README.rst')).read().strip(), 'utf-8')
NameError: name 'unicode' is not defined
It looks to me like this library, which has not been updated since 2012, is not compatible with Python 3 and they haven't properly indicated that in the pypi metadata.
The source code is here, if you can't find an alternative library, you may be able to update it to python3 yourself and either make a pull request or a fork.

Python3.4 - Install pyautogui - Raspberry Pi 3

I've been trying to install pyautogui for Python 3.4 on my Raspberry Pi 3 for the last 2 hours... I need it because I wrote a touch keyboard application that needs to run on it. On my main machine (elementary OS 0.4 with Python 3.5) I was able to install it without any problems. First I tried sudo pip install pyautogui but that only installed the Python 2.7 version of pyautogui. Of course next I tried sudo pip3 install pyautogui but that gave me this error:
Running setup.py (path:/tmp/pip-build-hf289jja/pyautogui/setup.py) egg_info for package pyautogui
Traceback (most recent call last):
File "<string>", line 17, in <module>
File "/tmp/pip-build-hf289jja/pyautogui/setup.py", line 6, in <module>
version=__import__('pyautogui').__version__,
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/__init__.py", line 114, in <module>
from . import _pyautogui_x11 as platformModule
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/_pyautogui_x11.py", line 6, in <module>
from Xlib.display import Display
File "/usr/local/lib/python3.4/dist-packages/Xlib/display.py", line 20, in <module>
import new
ImportError: No module named 'new'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip-build-hf289jja/pyautogui/setup.py", line 6, in
version=__import__('pyautogui').__version__,
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/init.py", line 114, in
from . import _pyautogui_x11 as platformModule
File "/tmp/pip-build-hf289jja/pyautogui/pyautogui/_pyautogui_x11.py", line 6, in
from Xlib.display import Display
File "/usr/local/lib/python3.4/dist-packages/Xlib/display.py", line 20, in
import new
ImportError: No module named 'new'
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-hf289jja/pyautogui
Storing debug log for failure in /root/.pip/pip.log
... sorry for the formatting of the above, I couldn't get it to stay inside one code box.
I have no idea what module "new" is. I tried everything else under the sun, such as installing from the official resources: https://pypi.python.org/pypi/PyAutoGUI and various other guides, with NO results.. I'm kinda loosing my mind right now.
ANY Help is grately appreciated :)
Try the following:
sudo pip3 install python3-xlib
sudo pip3 install pyautogui
This assumes you have some other python3 libraries already installed, but you will see missing installs in the above if not.

Resources