热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在linux上与Python3.6进行回溯。-ModuleNotFoundErrorintracebackswithPython3.6onlinux

IinstalledPython3.6onUbuntu16.04byusingJonathonFernyhoughsPPA:我在Ubuntu16.04上用Jonathon

I installed Python 3.6 on Ubuntu 16.04 by using Jonathon Fernyhough's PPA:

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

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

我使用新的字串插值创建了一个字符串,但我提供了一个无效的格式说明符。我不仅得到了预期的ValueError:无效的格式说明符,而且还有意外的ModuleNotFoundError:没有名为“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 "", line 1, in 
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 
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in 
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in 
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in 
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in 
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "", line 1, in 
ValueError: Invalid format specifier

I reported this to the Python bug tracker. There it was noted that:

我向Python bug跟踪器报告了这一点。在那里,人们注意到:

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:

这似乎是供应商的问题,而不是CPython本身。同样的问题也发生在Ubuntu 16.10的Python 3.6中。提出任何例外都可能导致:

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 "", line 1, in 
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 
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in 
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in 
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in 
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in 
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "", line 1, in 
Exception
>>> 

Also see https://bugs.launchpad.net/ubuntu/+source/python3.6/+bug/1631367.

也看到https://bugs.launchpad.net/ubuntu/ +源/ 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:

现在我的问题是:

  1. 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?
  2. 我如何解释这个评论?这里的小贩是Jonathon Fernyhough的PPA吗?他是否改变了他分配的Python代码的某些内容,从而试图为每一个产生回溯的异常提交报告?
  3. Who do I need to notify or where do I need to file a bug to get this resolved?
  4. 我需要通知谁,或者我需要在哪里提交错误来解决这个问题?

2 个解决方案

#1


11  

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

在我把这个问题提交给Stackoverflow之后,Barry A. Warsaw对问题跟踪器做了如下评论。

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.

请理解,从随机PPA中安装Python 3.6并不能完全支持这个版本的解释器。Python 3.6还不是Ubuntu任何版本的支持版本(我假定您使用的是这个版本),尽管我们正在为它开发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.

通常情况下,您可以安装一个新的Python 3解释器包,并且很多东西都可以工作,因为Ubuntu基础设施在所有安装的Python 3中共享purepython模块。从技术上讲,他们在系统上都有/usr/lib/python3/dist包。因此,为Python 3的支持版本构建的任何第三方pure-Python模块都可以通过安装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.

但是,这是一个很长的路,从说那些第三方模块将起作用;2)不包括任何包含C扩展模块的包,必须为特定的解释器版本重新构建。

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.

支持新版本的Python是一个漫长的过程,我们才刚刚开始。请与ubuntu-devel@ubuntu.com了解详情。

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确实安装了一个标准的异常处理程序,这样当Python应用程序和这样的崩溃时,我们可以收集崩溃统计信息,这样我们就可以投入资源来解决常见的问题和回归。apport(在traceback中看到)是崩溃报告基础结构。apport调用apt_pkg,它是一个(c++)扩展模块,因此不会为您从该PPA中安装的Python 3.6版本而构建,当然,除非PPA所有者(我不知道)也完成了一个关于Python的Python 3的重建。因为我正在制定这个计划,而且我知道这是相当多的工作,我怀疑这是为这个相当随机的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.

ubuntu-devel邮件列表是一个更好的地方,可以讨论正在进行的工作,将Python 3.6作为支持版本的Ubuntu。

#2


3  

I solved this issue for Python 3.6 by first installing the python-apt package for Python 3:

我在Python 3.6中首先安装了Python 3的Python -apt包,从而解决了这个问题:

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:

在那之后,我更改为dist-package目录并复制apt_pkg[…]。所以文件到新的默认文件名apt_pkg。因此,要得到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.

现在,所有的ModuleNotFoundError:没有一个名为“apt_pkg”异常的模块在预期抛出的错误消息中消失了。


推荐阅读
  • Ubuntu安装常用软件详细步骤
    目录1.GoogleChrome浏览器2.搜狗拼音输入法3.Pycharm4.Clion5.其他软件1.GoogleChrome浏览器通过直接下载安装GoogleChro ... [详细]
  • 在Docker中,将主机目录挂载到容器中作为volume使用时,常常会遇到文件权限问题。这是因为容器内外的UID不同所导致的。本文介绍了解决这个问题的方法,包括使用gosu和suexec工具以及在Dockerfile中配置volume的权限。通过这些方法,可以避免在使用Docker时出现无写权限的情况。 ... [详细]
  • 树莓派语音控制的配置方法和步骤
    本文介绍了在树莓派上实现语音控制的配置方法和步骤。首先感谢博主Eoman的帮助,文章参考了他的内容。树莓派的配置需要通过sudo raspi-config进行,然后使用Eoman的控制方法,即安装wiringPi库并编写控制引脚的脚本。具体的安装步骤和脚本编写方法在文章中详细介绍。 ... [详细]
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • Python字典推导式及循环列表生成字典方法
    本文介绍了Python中使用字典推导式和循环列表生成字典的方法,包括通过循环列表生成相应的字典,并给出了执行结果。详细讲解了代码实现过程。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • ZSI.generate.Wsdl2PythonError: unsupported local simpleType restriction ... [详细]
  • imx6ull开发板驱动MT7601U无线网卡的方法和步骤详解
    本文详细介绍了在imx6ull开发板上驱动MT7601U无线网卡的方法和步骤。首先介绍了开发环境和硬件平台,然后说明了MT7601U驱动已经集成在linux内核的linux-4.x.x/drivers/net/wireless/mediatek/mt7601u文件中。接着介绍了移植mt7601u驱动的过程,包括编译内核和配置设备驱动。最后,列举了关键词和相关信息供读者参考。 ... [详细]
  • 31.项目部署
    目录1一些概念1.1项目部署1.2WSGI1.3uWSGI1.4Nginx2安装环境与迁移项目2.1项目内容2.2项目配置2.2.1DEBUG2.2.2STAT ... [详细]
  • 本文介绍了在Ubuntu下制作deb安装包及离线安装包的方法,通过备份/var/cache/apt/archives文件夹中的安装包,并建立包列表及依赖信息文件,添加本地源,更新源列表,可以在没有网络的情况下更新系统。同时提供了命令示例和资源下载链接。 ... [详细]
  • 本文介绍了在Ubuntu系统中清理残余配置文件和无用内容的方法,包括清理残余配置文件、清理下载缓存包、清理不再需要的包、清理无用的语言文件和清理无用的翻译内容。通过这些清理操作可以节省硬盘空间,提高系统的运行效率。 ... [详细]
  • tcpdump 4.5.1 crash 深入分析
    tcpdump 4.5.1 crash 深入分析 ... [详细]
  • Ubuntu 用户安装 Linux Kernel 3.15 RC1
    nsitionalENhttp:www.w3.orgTRxhtml1DTDxhtml1-transitional.dtd ... [详细]
author-avatar
文艺范老大叔
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有