[英]PyInstaller ImportError: No module named 'pyfiglet.fonts'
我正在嘗試使用 PyInstaller 為 Asciimatics 編譯一個演示腳本,希望最終能夠為我正在開發的基於文本的游戲創建一個簡單的 GUI,它返回以下錯誤:
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
谷歌搜索這個錯誤返回了這個線程,但在我看來,這個錯誤是由 SublimeFiglet 本身的故障引起的,並且在兩年前得到了修復。
我在 Windows 10 上使用 Python 3.4。我不得不將 setuptools 降級到 19.2(我相信是我必須降級到的版本),因為在嘗試運行編譯后的 .exe 時出現錯誤,指出缺少打包包文件。
除了運行腳本所需的其他導入之外,我還在 test.py 中導入了六個(因為它是隱藏導入)和 pyfiglet 模塊。 導入 pyfiglet 和我能想到的任何變化都不會改變。 我可以更改規范文件以添加六個的隱藏導入,但我看不出這會如何改變任何東西。
這是 Pyinstaller 使用的規范文件:
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')
Asciimatics 中包含的每個示例腳本都會為我返回同樣的錯誤。 在腳本上運行 pyinstaller 時,我嘗試使用不同的選項,但沒有成功。 我錯過了什么嗎? 我不知道如何解決這個問題。
我也面臨同樣的問題,我已經在 exe 中導入了 pyfiglet 文件夾,它對我有用。 我將 venv 文件夾作為虛擬環境,但如果您有不同的虛擬環境文件夾名稱,那么也要更改文件夾名稱,否則只需更改 AppName.py。
pyinstaller --add-data "venv\Lib\site-packages\pyfiglet;./pyfiglet" AppName.py
這個問題很老了,但我遇到了同樣的問題,只需將pyfiglet文件夾從 PYTHONPATH\Lib\site-packages 復制/粘貼到 pyinstaller dist文件夾即可解決。
在PyInstaller命令選項中提供系統上Pyfiglet文件夾的路徑,這會將文件復制到生成的 dist 中。
例如:
pyinstaller --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet";./pyfiglet MyApp.py
或者對於單個 EXE 文件:
pyinstaller --onefile --add-data "C:/Program Files/Python35/Lib/site-packages/pyfiglet";./pyfiglet MyApp.py
假設您的應用程序名稱是“MyApp.py”,您的系統是 Windows,並且 Pyfiglet 庫安裝在以下路徑:C:/Program Files/Python35/Lib/site-packages/pyfiglet
否則,更改為正確的值。
在開始工作之前嘗試以下代碼......!
!pip install pyfiglet
希望它應該工作..!
您好,我遇到過這個問題,但問題是 python 3.9 更新你必須選擇 python 3.8 作為解釋器..
安裝特定版本:
pip install pyfiglet
升級 pyfiglet
sudo pip3 install --upgrade pyfiglet
在 Window 10 中出現依賴錯誤使用代碼:easy_install 而不是 pip install
easy_install pyfiglet
使用簡易安裝升級
sudo easy_install --upgrade pyfiglet
在 OSX 系統上安裝模塊:使用代碼:brew install 而不是 pip install
brew install pyfiglet
不使用 Pip :
sudo apt-get install -y pyfiglet
在 CentOS7 或 Linux Fedora 上:
yum -y install pyfiglet
或者在 Fedora 上試試
sudo dnf install pyfiglet
如果 Homebrew 在 macOS 上搞砸了你的路徑,則命令:
python -m pip install pyfiglet
對於 Python3 MacOs Homebrew 螺絲
python3 -m pip install pyfiglet
從列表 MacO 中驗證模塊
pip freeze | grep pyfiglet
在 Anaconda 上作為您的 python 包管理器執行
conda install -c anaconda pyfiglet
對我來說,解決這個問題的最簡單方法是在運行 pyinstaller 時傳遞--collect-all pyfiglet
pyfiglet。 這似乎很容易包含整個庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.