gpt4 book ai didi

python - 创建可执行的 Python

转载 作者:行者123 更新时间:2023-11-28 19:15:17 25 4
gpt4 key购买 nike

我刚刚完成了我的第一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com