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:
现在我的问题是:
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。
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”异常的模块在预期抛出的错误消息中消失了。