python - 是否可以使用 pip 模块在 python 3 项目上使用 cx_freeze?

标签 python python-3.x pip cx-freeze

我正在为我正在编写的更大程序编写安装程序,我正在使用 CxFreeze 将其转换为可执行文件,但是,当我运行 .exe 文件时,它崩溃并显示“import pip”行,并启动(如下所示),所以基本上我的问题是:是否可以在导入了 pip 的应用程序上使用 CxFreeze?

编辑: 以下是我正在使用的所有文件:

setup.py (V1):

from cx_Freeze import *
import os, pip
setup(name=("ARTIST"),
      version = "1",
      description = "ARTIST installation file",
      executables = [Executable("Install ARTIST.py"), Executable("C:\\Python34\\Lib\\site-packages\pip\\__init__.py")],
      )

这会引发错误: enter image description here

setup.py (V2):

from cx_Freeze import *
import os, pip
setup(name=("ARTIST"),
      version = "1",
      description = "ARTIST installation file",
      executables = [Executable("Install ARTIST.py"],
      options = {"build_exe": {"packages":[pip]}}
      )

这会在 setup.bat 文件中引发错误: enter image description here

编辑: 如果有人想查看我发布更大程序的网站,这里是链接: alaricwhitehead.wix.com/artist

编辑2: 这是我在使用 py2exe 时遇到的错误: enter image description here

编辑3: 这是代码的副本: https://www.dropbox.com/s/uu46iynm8fr8agu/Install%20ARTIST.txt?raw=1

请注意:我不想发布指向它的链接,但直接发布它太长了。

最佳答案

安装脚本中有两个问题。第一个问题是您在 build_exe 命令的 packages 选项下指定了要包含在卡住应用程序中的额外模块:packages 用于指定您需要包含的应用程序包,对于您需要使用includes 的外部模块(例如pip)。第二个问题是您需要传递给 includes 模块字符串列表而不是模块本身:

setup(
    name=("ARTIST"),
    version="1",
    description="ARTIST installation file",
    options={
        'build_exe': {
            'excludes': [], # list of modules to exclude
            'includes': ['pip'], # list of extra modules to include (from your virtualenv of system path),
            'packages': [], # list of packages to include in the froze executable (from your application)
        },
    },
    executables=[
        Executable(
            script='run.py', # path to the entry point of your application (i.e: run.py)
            targetName='ARTIST.exe', # name of the executable
        )
    ]
)

关于python - 是否可以使用 pip 模块在 python 3 项目上使用 cx_freeze?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35527835/

相关文章:

python - 从源代码构建 OpenCV4 和 pip install opencv-python 有什么区别?

python - 比较 NumPy 数组以便 NaN 比较相等

python - 无论元组顺序如何,在两个元组列表中查找交集

python-3.x - 设置 tkinter ttk 框架的背景颜色

python - 为什么范围在 Python-3 中不会耗尽?

git - Pip 未安装最新的 GitHub 版本

python - 使用 reload 时出现奇怪的 Python 问题

python - 沿具有一些缺失行的 DataFrame 列进行平均

python - 从 Python 中的两个替代源输入?

python - Pip 未安装在 virtualenv 中