PyInstaller ImportError: No module named 'pyfiglet.fonts'

跟風遠走 提交于 2021-02-07 04:01:26

问题


I'm attempting to use PyInstaller to compile one of the demo scripts for Asciimatics, in hopes to eventually be able to create a simple GUI for a text-based game I'm developing, and it returns the following error:

C:\Users\X\Documents\Python Scripts\asciimatics samples\dist\test>test.exe

Traceback (most recent call last):
  File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources\__init__.py", line 443, in get_provider
KeyError: 'pyfiglet.fonts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 22, in <module>
  File "site-packages\asciimatics\screen.py", line 859, in wrapper
  File "<string>", line 12, in demo
  File "site-packages\asciimatics\renderers.py", line 276, in __init__
  File "site-packages\pyfiglet\__init__.py", line 710, in __init__
  File "site-packages\pyfiglet\__init__.py", line 717, in setFont
  File "site-packages\pyfiglet\__init__.py", line 90, in __init__
  File "site-packages\pyfiglet\__init__.py", line 100, in preloadFont
  File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources\__init__.py", line 1160, in resource_exists
  File "site-packages\setuptools-19.2-py3.4.egg\pkg_resources\__init__.py", line 445, in get_provider
ImportError: No module named 'pyfiglet.fonts'
test returned -1

Googling this error returned this thread, but it seems to me that the error is caused by a fault within SublimeFiglet itself, and was fixed two years ago.

I'm using Python 3.4 on Windows 10. I had to downgrade setuptools to 19.2 (I believe is the version I had to downgrade to) because I was getting an error stating that the packaging package was missing when attempting to run the compiled .exe file.

I've imported both the six (due to it being a hidden import) and pyfiglet modules in test.py, in addition to the other imports necessary to run the script. Importing pyfiglet and any variations I can think of changes nothing. I could change the spec file to add a hidden import for six, though I don't see how that would change anything.

Here is the spec file Pyinstaller uses:

block_cipher = None


a = Analysis(['test.py'],
             pathex=['C:\\Users\\Sirindil\\Documents\\Python Scripts\\asciimatics samples'],
             binaries=None,
             datas=None,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='test',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='test')

Every sample script included with Asciimatics returns this same error for me. I've tried using different options when running pyinstaller on the script, with no success. Am I missing something? I have no idea how to fix this.


回答1:


I was also facing the same issue and i have imported the pyfiglet folder inside in exe and it works for me. I'm having venv folder as a virtual environment but in case you are having different virtual environment folder name then change the folder name as well, otherwise only change the AppName.py.

pyinstaller --add-data "venv\Lib\site-packages\pyfiglet;./pyfiglet" AppName.py



回答2:


It looks like you're building your EXE without including the font files from pyfiglet. This is because PyInstaller cannot interpret the pkg_resources call from inside pyfiglet when building the set of files to package up.

I've not used it myself, but it looks like you might be able to add the font files to your package by updating your spec file to include all the missing files. However, you should pay attention to the FAQ, which says that there is only limited support for pkg_resources (and so it may be that you simply cannot package pyfiglet).




回答3:


The question is quite old but I had the same issue and solved it by simply copy/pasting the pyfiglet folder from PYTHONPATH\Lib\site-packages to the pyinstaller dist folder.




回答4:


Provide the path of the Pyfiglet folder on the system in the PyInstaller command options, which will copy the files into the generated dist.

Eg .:

pyinstaller --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet";./pyfiglet MyApp.py

Or for a single EXE file:

pyinstaller --onefile --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet";./pyfiglet MyApp.py

Assuming your App name is "MyApp.py", your system is Windows and the Pyfiglet lib is installed at the following path: C:/Program Files/Python35/Lib/site-packages/pyfiglet

Otherwise, change to the correct values.




回答5:


Try the below code before you start your work...!

!pip install pyfiglet

Hope it should work..!



来源:https://stackoverflow.com/questions/36970026/pyinstaller-importerror-no-module-named-pyfiglet-fonts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!