擅长:python、mysql、java
<p>编辑<code>.spec</code>文件,在<code>a = Analysis part</code>之后添加下面显示的行。然后使用<code>--onefile flag</code>-例如<code>pyinstaller --onefile my_project.spec</code>构建</p>
<pre><code>a = Analysis(...)
# Add the following
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
</code></pre>
<p>这是必要的,因为PyInstaller正在获取pandas的python代码,而不是获取lib。这意味着当pandas代码运行(从可执行文件的“内部”运行)时,它找不到lib,因此它试图提供帮助,并建议您需要构建它。</p>
<p>解决方法在<a href="http://github.com/pyinstaller/pyinstaller/issues/1580" rel="noreferrer">http://github.com/pyinstaller/pyinstaller/issues/1580</a>中有详细说明,它可能不适用于所有版本/操作系统,所以祝您好运。</p>