-2

I have Python 3.6 and I did a project in .py that I would like to put in an .exe document ; How can I do that ? I tried Py2exe but it did not worked due to my python version. Thanks for your answers.

Traftmine

  • More duplicates: https://stackoverflow.com/questions/5458048/how-can-i-make-a-python-script-standalone-executable-to-run-without-any-dependen, https://stackoverflow.com/questions/2136837/process-to-convert-simple-python-script-into-windows-executable, https://stackoverflow.com/questions/12059509/create-a-single-executable-from-a-python-project. And BTW the first is also for Python 3.6 so you should really try to search a little bit before posting a question – Tomerikoo Sep 06 '20 at 09:55

2 Answers2

3

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 vendor, 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.

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

    from sys import executable
    from cx_Freeze import setup, Executable
    
    setup(name='programName', version='0.1', description='my fancy description')
    

    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.

Carlo Zanocco
  • 1,967
  • 4
  • 18
  • 31
0

You should check out PyInstaller.

MiB_Coder
  • 865
  • 1
  • 7
  • 20
  • Read about [answer]. Link-only answers are discouraged, especially when the question is not well-asked as well – Tomerikoo Sep 06 '20 at 09:39
  • @Tomerikoo: I think the question is clear and the answer is a package which solves the problem. – MiB_Coder Sep 06 '20 at 09:46
  • Both the question and this answer doesn't follow the guidelines of this website, found in the [help]. Specifically under [ask] and [answer]. – Tomerikoo Sep 06 '20 at 09:51