我正在尝试用我的python脚本创建一个可执行文件。 系统配置:
python --version :
Python 2.7.15 :: Anaconda, Inc.
conda : 4.3.16
numpy : 1.14.3
pandas : 0.23.4
py2exe : 0.6.9
pyinstaller : 3.4
cx-Freeze : 5.1.1
方法1:我尝试了pyinstaller
,但是很遗憾,它需要PyQt5
,并且由于pyqt5
环境不支持python 2.7
,因此我无法继续使用此方法https://pypi.org/project/PyQt5/#files
方法2: py2exe
1)python setup.py install
2)python setup.py py2exe
但是当我在cmd
中运行我的exe文件时,出现以下错误
错误:
X:\Data_Analytics\ETL\dist>Expiry.exe
Traceback (most recent call last):
File "Expiry.py", line 5, in <module>
File "pandas\__init__.pyc", line 19, in <module>
ImportError: Missing required dependencies ['numpy']
设置代码文件:
from distutils.core import setup
import py2exe
import sys
sys.setrecursionlimit(5000)
setup(console=['Expiry.py'])
方法3: cx_Freeze
命令:python setup.py build
设置文件:
from cx_Freeze import setup, Executable
setup(name = "Expiry" ,
version = "1.0" ,
description = "" ,
executables = [Executable("Expiry.py")])
错误:
X:\Data_Analytics\ETL\build\exe.win-amd64-2.7>Expiry.exe
Traceback (most recent call last):
File "X:\Anaconda\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
module.run()
File "X:\Anaconda\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
exec(code, m.__dict__)
File "Expiry.py", line 5, in <module>
File "X:\Anaconda\lib\site-packages\pandas-0.23.4-py2.7-win-amd64.egg\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
我也尝试重新安装pandas
和numpy
,尝试重新安装anaconda,但是没有运气。
答案 0 :(得分:2)
您应该能够在Python控制台中运行以下命令而不会出现错误:
<div class="select-style">
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
如果这不起作用,则首先需要按此顺序(重新)安装import numpy
print numpy.__version__
import pandas
print pandas.__version__
和numpy
。
为了冻结与pandas
相关的pandas
(因此取决于numpy
)的脚本,您需要将cx_Freeze
显式添加到{{ 1}} numpy
选项的列表。尝试对安装脚本进行以下修改:
packages
答案 1 :(得分:1)
@jpeg如前所述,这是您提出建议后可以使用的我的解决方案。
from cx_Freeze import setup, Executable
options = {'build_exe': {'packages': ['numpy'], 'include_files':['X:\Anaconda\Lib\site-packages\mkl_intel_thread.dll']} }
setup(name = "Expiry" ,
version = "1.0" ,
description = "" ,
options = options,
executables = [Executable("Expiry.py")])