不能得到莱克塞斯.Python()来自用PyIns构建的Kivy应用程序

2024-05-16 19:24:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Python应用程序,它运行得非常好,在里面我可以做一些类似的事情:

from pygments import lexers

然后。。。在

^{pr2}$

只需运行脚本就可以了,我得到了PythonLexer的一个新实例。然而。。。当我使用PyInstaller为应用程序创建一个构建文件夹并运行它时,该行失败:

File "blah\myfile", line 31, in __init__ AttributeError: 'module' object has no attribute 'PythonLexer'

有什么想法吗?我认为这是因为pygments在运行时从PyInstaller构建文件夹中丢失的一些文件中构建了它的对象,但我不太明白怎么做。在

这个应用程序使用的是Kivy,但实际上我不认为这与这个问题有太大关系。在


Tags: 实例fromimport脚本文件夹应用程序pygmentsmyfile
3条回答

我在使用pyinstaller打包Kivy的“showcase”演示应用程序时遇到了类似的问题。在

好像是Pygments的虫子。在

在我修补\pygments\lexers\__init__.py之后,错误消失了:

 - __init__old.py
+++ __init__.py
@@ -15,6 +15,7 @@
import fnmatch
from os.path import basename

+from pygments.lexers.agile import PythonLexer
from pygments.lexers._mapping import LEXERS
from pygments.modeline import get_filetype_from_buffer

您可以使用PyInstaller的一个建议来修复它,包括那些没有自动找到的模块。http://pythonhosted.org/PyInstaller/#helping-pyinstaller-find-modules

问题是包pygments.lexers不包含名为PythonLexer.py的文件。要解决问题,可以执行以下操作:

from pygments.lexers.agile import PythonLexer
testing = PythonLexer()

相关问题 更多 >