2024/01/02

python py轉exe後執行失敗

 最近在更新一個python檔案,更新完要透過pyinstaller轉成exe,會用到pandas跟openpyxl兩個套件。

轉出來後卻無法執行,錯誤訊息是說numpy有問題(Error importing numpy: you should not try to import numpy from....)

這個是在裝pandas時自動裝進來的,研究到最後就是python的版本太新(3.9.x),重新建一個虛擬環境,降到3.6就排除這個問題了。

但卻產生另一個錯誤(ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd)

查到最後也是版本的問題,最快的方法就是重做一個虛擬環境,python是3.8.1,然後pip install pandas跟openpyxl,xlrd跟numpy的問題就沒了。



I have been updating a Python file recently, and after the updates, I need to convert it to an executable using pyinstaller. The script relies on two packages, pandas and openpyxl.

However, after the conversion, the executable cannot run, and the error message indicates an issue with numpy (Error importing numpy: you should not try to import numpy from....). It turns out that this issue arose because of the version of Python being too new (3.9.x) when installing pandas. I resolved this by creating a new virtual environment and downgrading to Python 3.6.

However, this led to another error (ImportError: Missing optional dependency 'xlrd'. Install xlrd >= 1.0.0 for Excel support. Use pip or conda to install xlrd). After investigation, I found that this was also a version-related problem. The quickest solution was to create a new virtual environment with Python 3.8.1 and then install pandas and openpyxl using pip. This resolved the issues with xlrd and numpy.

沒有留言:

張貼留言