当从 cmd 运行 但在 Anaconda Prompt 中运行时,Pyinstaller EXE 在 Seaborn relplot 崩溃

Pyinstaller EXE crashes at Seaborn relplot when ran from cmd but runs in Anaconda Prompt

我用 Pyinstaller 创建了一个可执行文件。 运行 来自 cmd 的可执行文件,它在开始创建 relplot 时崩溃。为了创建 exe,我使用了这个命令:pyinstaller test.py --onefile。这里是 test.py:

#!/usr/bin/env python
import seaborn as sns

print('###################relplot##########################')
tips = sns.load_dataset("tips")
g = sns.relplot(data=tips, x="total_bill", y="tip", hue="day")
g.fig.savefig('.\test.png')
print('success')

康达信息:

shell level : 2
conda version : 4.9.2
conda-build version : 3.20.5
python version : 3.8.5.final.0
virtual packages : __cuda=11.1=0
                   __win=0=0
                   __archspec=1=x86_64
platform : win-64
user-agent : conda/4.10.1 requests/2.25.1 CPython/3.8.8 Windows/10 Windows/10.0.19041
administrator : False
netrc file : None
offline mode : False

Pyinstaller warning file when the .exe is built.

Pyinstaller debug messages at runtime--debug=imports 查看底部崩溃的地方。

我已经尝试更新环境和库,编写到处都能找到的疯狂 .spec 文件。似乎没有任何效果。我知道 this post. 但解决方案不起作用,这个问题没有得到太多关注而且它不完整,我无法对其发表评论,对我来说它似乎与我的问题略有不同。

更新: exe文件在Anaconda Prompt中运行没有问题,但是在cmd中却崩溃了。我尝试了 here 提供的解决方案,但没有用。

Conda 虚拟环境Python 3.7.10:

name: test_env
channels:
  - defaults
dependencies:
  - altgraph=0.17=pyhd3eb1b0_0
  - blas=1.0=mkl
  - ca-certificates=2021.1.19=haa95532_1
  - certifi=2020.12.5=py37haa95532_0
  - cycler=0.10.0=py37_0
  - freetype=2.10.4=hd328e21_0
  - future=0.18.2=py37_1
  - icc_rt=2019.0.0=h0cc432a_1
  - icu=58.2=ha925a31_3
  - intel-openmp=2020.2=254
  - jpeg=9b=hb83a4c4_2
  - kiwisolver=1.3.1=py37hd77b12b_0
  - libpng=1.6.37=h2a8f88b_0
  - macholib=1.14=pyhd3eb1b0_1
  - matplotlib=3.2.2=0
  - matplotlib-base=3.2.2=py37h64f37c6_0
  - mkl=2020.2=256
  - mkl-service=2.3.0=py37h196d8e1_0
  - mkl_fft=1.3.0=py37h46781fe_0
  - mkl_random=1.1.1=py37h47e9c7a_0
  - numpy=1.19.2=py37hadc3359_0
  - numpy-base=1.19.2=py37ha3acd2a_0
  - openssl=1.1.1k=h2bbff1b_0
  - pandas=1.2.3=py37hf11a4ad_0
  - pefile=2019.4.18=py_0
  - pip=21.0.1=py37haa95532_0
  - pycryptodome=3.10.1=py37h2bbff1b_0
  - pyinstaller=3.6=py37h8cc25b3_6
  - pyparsing=2.4.7=pyhd3eb1b0_0
  - pyqt=5.9.2=py37h6538335_2
  - python=3.7.10=h6244533_0
  - python-dateutil=2.8.1=pyhd3eb1b0_0
  - pytz=2021.1=pyhd3eb1b0_0
  - pywin32=227=py37he774522_1
  - pywin32-ctypes=0.2.0=py37_1001
  - qt=5.9.7=vc14h73c81de_0
  - scipy=1.6.2=py37h14eb087_0
  - seaborn=0.10.1=py_0
  - setuptools=52.0.0=py37haa95532_0
  - sip=4.19.8=py37h6538335_0
  - six=1.15.0=py37haa95532_0
  - sqlite=3.35.4=h2bbff1b_0
  - tornado=6.1=py37h2bbff1b_0
  - vc=14.2=h21ff451_1
  - vs2015_runtime=14.27.29016=h5e58377_2
  - wheel=0.36.2=pyhd3eb1b0_0
  - wincertstore=0.2=py37_0
  - zlib=1.2.11=h62dcd97_4
prefix: C:\Users\alina\.conda\envs\test_env

经过多次测试后,我意识到只有在使用 conda 环境创建我的可执行文件时才会发生这种情况。我只是创建了一个 venv 而不是 conda 环境,一切都很顺利。当您想要使用 pyinstaller.

分发 Python 应用程序时,我建议尽可能远离 conda 环境