简体   繁体   中英

Is it possible to use cx_freeze on a python 3 project using the pip module?

I am writing an installation program for a larger program I am writing, and I am using CxFreeze to convert it to an executable file, however, when I run the .exe file, it crashes with the line "import pip", and brings up (as shown below), so basically my question is: Is it possible to use CxFreeze on an application with pip imported?

Edit: Here are all the files I am using:

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")],
      )

This brings up the error: 在此输入图像描述

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]}}
      )

This brings up an error in the setup.bat file: 在此输入图像描述

Edit: If anyone wants to look at the website where I am publishing the larger program, here is the link: alaricwhitehead.wix.com/artist

Edit2: this is the error i get when i use py2exe: 在此输入图像描述

Edit3: here is a copy of the code: https://www.dropbox.com/s/uu46iynm8fr8agu/Install%20ARTIST.txt?raw=1

please note: I didn't want to have to post a link to it, but it was too long to post directly.

The are two problems in your setup script. The first problem is that you specified extra modules to include in your frozen application under the packages option of the build_exe command: packages is for specifying which packages of your application you need to include, for the external modules (such as pip ) you need to use includes . The second problem is that you need to pass to includes a list of strings of modules and not the module itself:

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
        )
    ]
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM