python - 创建可执行的 Python

标签 python scikit-learn exe pyinstaller seaborn

我刚刚完成了我的第一个 python 工作,我想创建一个可执行文件来分发。但是,我很难做到这一点。我已经尝试过 py2exe、pyinstaller 和 cx_freeze,但都没有成功。搜索了很多意见,我相信 pyinstaller 是解决我的问题的最佳解决方案,但我可以让它工作。我在程序中执行的导入如下:

import os
import pygtk
import gtk
import MySQLdb
import getpass as gt
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.io import sql
from scipy import stats, integrate
from scipy.optimize import curve_fit
import seaborn as sns
from sklearn.neighbors import KNeighborsClassifier
from sklearn.cross_validation import train_test_split
from sklearn import metrics

阅读 pyinstaller 的文档我注意到它只不适用于库 scikitlearn (sklearn) 和 seaborn。当我使用“pyinstaller --onefile Principal.py”时,我得到了构建和分发粘贴,但是当我尝试运行 .exe 文件时,我收到以下消息:

C:\Users\Lucas\AppData\Local\Temp\_MEI82242\gtk\__init__.py:127: RuntimeWarning:
 PyOS_InputHook is not available for interactive use of PyGTK
Traceback (most recent call last):
  File "<string>", line 13, in <module>
  File "c:\users\lucas\appdata\local\temp\pip-build-6fpfyh\pyinstaller\PyInstall
er\loader\pyimod03_importers.py", line 363, in load_module
  File "c:\users\lucas\anaconda\lib\site-packages\pandas\__init__.py", line 13,
in <module>
    "extensions first.".format(module))
ImportError: C extension: lib not built. If you want to import pandas from the s
ource directory, you may need to run 'python setup.py build_ext --inplace' to bu
ild the C extensions first.
Principal returned -1

有人可以帮我做我必须做的事吗?

最佳答案

您的问题是您的 python 无法构建基于 C 的程序包 (numpy)。可能是安装了一些库:

  • 在你的 python 发行版 (anaconda) 中
  • 使用预编译包的 wheel 安装文件 (.whl)

您可以尝试通过两种方式解决这个问题:

  • 安装最新的 MS Visual C++ 编译器,因此您将使用 vcvarsall.bat 进行 C 扩展
  • 安装最新的Visual Studio Community其中包括一个 IDE 和多种语言的编译器。第二个选项通常有效,但它需要超过 6 GB 的硬盘空间

安装完成后,您可以启动错误消息告诉您的内容:

python setup.py build_ext --inplace

关于python - 创建可执行的 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34387701/

相关文章:

c# - 如何在 visual studio 2010 安装和部署项目中包含第三方 exe?

python - 强制在所有继承类中实现一个方法

python - sklearn : Naive Bayes classifier gives low accuracy

c# - 无需单独的项目即可获得 WinForm 的快捷方式

java - 将jar文件转换为exe

machine-learning - from_model.py 中的 SelectFromModel() 如何工作?

python - 如何以向量化方式修改具有任意索引的 numpy 数组?

python - unident 不匹配任何外部缩进级别,我需要更改什么?

python - Django - 测试失败时记录

python - SKlearn 导入 MLPClassifier 失败