gpt4 book ai didi

python-3.x - Linux 上 Python3.6 回溯中的 ModuleNotFoundError

转载 作者:行者123 更新时间:2023-12-02 22:29:05 25 4
gpt4 key购买 nike

installed Python 3.6 on Ubuntu 16.04通过使用 Jonathon Fernyhough's PPA :

sudo add-apt-repository ppa:jonathonf/python-3.6
sudo apt-get update
sudo apt-get install python3.6

我使用新的文字字符串插值创建了一个字符串,但我提供了无效的格式说明符。我不仅得到了预期的 ValueError: Invalid format specifier,而且还得到了意外的 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

我将此报告给 Python bug tracker 。其中指出:

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.

最后,这个问题通过评论结束了

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.

我现在的问题是:

  1. 我该如何解读这条评论?本案中的供应商是 Jonathon Fernyhough 的 PPA 吗?他是否对他分发的 Python 代码进行了某些更改,以便尝试为每个产生回溯的异常提交报告?
  2. 我需要通知谁或需要在哪里提交错误才能解决此问题?

最佳答案

我通过首先安装 Python 3 的 python-apt 包解决了 Python 3.6 的这个问题:

sudo apt install python3-apt

之后,我切换到 dist-packages 目录,并将 apt_pkg[...].so 文件复制到新的默认文件名 apt_pkg .so,Python 3.6 也能识别:

cd /usr/lib/python3/dist-packages
sudo cp apt_pkg.cpython-34m-i386-linux-gnu.so apt_pkg.so

现在,所有 ModuleNotFoundError: No module named 'apt_pkg' 异常在预期抛出的错误消息中消失了。

关于python-3.x - Linux 上 Python3.6 回溯中的 ModuleNotFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41720578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com