Linux上使用Python3.6的追溯中的ModuleNotFoundError [英] ModuleNotFoundError in tracebacks with Python3.6 on linux

查看:249
本文介绍了Linux上使用Python3.6的追溯中的ModuleNotFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ubuntu 16.04上安装了Python 3.6 使用 Jonathon Fernyhough的PPA

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

我使用新的文字字符串内插法创建了一个字符串,但是提供了无效的格式说明符。我不仅得到了预期的 ValueError:无效的格式说明符,而且还有了意外的 ModuleNotFoundError:没有名为 apt_pkg的模块

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

我向 Python错误跟踪器。在那里注意到:


这似乎是供应商的问题,而不是CPython本身。在Ubuntu 16.10的Python 3.6中也会发生相同的问题。引发任何异常都可能导致以下情况:

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
>>> 




另请参阅 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.

我现在的问题是:


  1. 如何解释此评论?在这种情况下,卖方是Jonathon Fernyhough的PPA吗?并且他是否对他分发的Python代码进行了更改,以便它尝试为产生追溯的每个异常提交报告?

  2. 我需要通知谁,或在哪里需要通知提交错误来解决该问题?


推荐答案

在我将问题发布到Stackoverflow之后, Barry A. Warsaw对问题跟踪器做了以下评论

After I posted this question to Stackoverflow, Barry A. Warsaw made the following comment to the issue tracker


请注意,从随机PPA安装Python 3.6确实会为该版本的解释器提供全面支持。 Python 3.6尚未在任何版本的Ubuntu
(我假设您正在使用)中受支持,尽管我们正在以
17.04进行开发。

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.

通常,您可以安装一个新的Python 3解释程序包,而
会起作用,因为Ubuntu基础结构在所有已安装的Python 3中共享
个纯Python模块。从技术上讲
而言,它们在
sys.path上都将具有/ usr / lib / python3 / dist-packages,因此,任何为支持
版本的Python 3构建的第三方纯Python模块可以通过安装了Python 3的任何(打包构建的)
安装版本导入。

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.

但是1)距离说那些第三方还有很长的路要走
模块将起作用; 2)不包括任何包含C扩展
模块的软件包,必须针对特定的解释器版本进行重建。

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.

支持Python的新版本是一个漫长的过程,为此,我们刚刚开始
。请与ubuntu-devel@ubuntu.com联系以获取有关
的详细信息。

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会安装标准的异常处理程序,以便在使用Python
应用程序等时崩溃,我们可以收集崩溃统计信息,以便我们可以将
的资源用于解决常见问题和回归分析。
分配(您在回溯中看到)是崩溃,报告
基础结构。 apport调用apt_pkg,这是一个(C ++)扩展
模块,因此不会为从该PPA安装的Python 3.6
版本构建,除非PPA所有者(我
不知道)也完成了档案范围内的Python 3重建。由于我在进行设置时需要
,而且我知道这是相当多的
工作,因此我怀疑是否已经为这种相当随机的PPA完成了工作。

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.

ubuntu-devel邮件列表是讨论正在进行的
将Python 3.6作为Ubuntu上受支持的版本的工作的好地方。

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.

这篇关于Linux上使用Python3.6的追溯中的ModuleNotFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆