Creating Executable File For Python 2.7

故事扮演 提交于 2021-02-08 06:54:19

问题


I want to make an executable file from a python file the python file is written for Python 2.7.

I tried pyinstaller but it gives me an error when installing. I'm guessing it does not have support for Python 2.7 anymore.

Are there any alternatives for pyinstaller that work with Python 2.7?

I tried installing cx_Freeze version 5.1.1 but it gives me the following error:

Cleaning up...
Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\win-10\\appdata\\local\\temp\\pip_build_win-10\\cx-Freeze\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\win-10\appdata\local\temp\pip-cn4sd_-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\win-10\appdata\local\temp\pip_build_win-10\cx-Freeze
Storing debug log for failure in C:\Users\win-10\pip\pip.log

when I install from wheel

cx_Freeze-5.1.1-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform.
Storing debug log for failure in C:\Users\win-10\pip\pip.log

setup.py

from sys import executable
from cx_Freeze import setup, Executable

setup(name='server', version='0.1', description='reverse shell server')

回答1:


I faced this problem some times ago, after a lot of googling I found the best solution for me.

Alternatives

  • Py2Exe: Which is old, the last release on PyPi is on 21 October 2014.
  • pyInstaller: Is a nice tool, but with some problem that we will see later.
  • auto-py-to-exe: Use pyInstaller to build the .exe, so suffer the same problem, but has a nice GUI and is intuitive to use.
  • cx_Freeze: I think the best solution, because it was the only one that works in my case, it is also recommended from python

Investigation

During this time I looked on google and StackOverflow for the best solution, each time that I found something it was out-dated or not well explained/documented, so I studied the official docs.

py2exe

As first try I installed py2exe it seems the best option, also recommended from python, so, give it a try. All goes fine during the installation process, so I decide to follow the tutorial and get my .exe.

During the step 3 of the tutorial, running setup I received an error, looking on google I found this.

I gave up with py2exe.

auto-py-to-exe && pyInstaller

I have installed auto-py-to-exe and all went good, the program open without problems so I create my .exe file, that works!

The only problem was that, the program works only on my laptop, on all the other machine where I try to execute the antivirus delete it.

Looking on google I found the github repository where I found one issue like the mine, reading it I understand that the problem is pyInstaller.

Looking on the pyInstaller repository I found one issue where one contributors tells to contact the antivirus vendo, so I gave up again.

cx_Freeze

Looking the docs it seems to be overcomplicated realize a simple .exe, so I have studied the documentation and found what I need. If you need support for Python 2.x, cx_Freeze version 5.1.x should be used instead, to do it just run pip install cx-Freeze==5.1.1

  • Open you project folder and create inside it a setup.py file with inside:

    import sys
    from cx_Freeze import setup, Executable
    
    setup(  name = "myProgram",
            version = "0.1",
            description = "",
            executables = [Executable("myProgram.py")])
    

    Setting up this file require a little bit of study, there are multiple options to set. You can set the option to create a simple .exe or also the create a windows/mac/linux installer.

  • Once you have your file ready, with the options that you need, just open a shell/terminal/cmd in the directory where the setup.py file is located and execute: python setup.py build

  • Now in your project folder you will see a folder where inside you can find your .exe file.



来源:https://stackoverflow.com/questions/63779334/creating-executable-file-for-python-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!