Posted in Programming

.py to .exe in Python 3.6.1

The thing is, I suffered a lot to do this. Spent many days working on it. Finally, I got the answer. I realized that I got not only the answer but also an ImportError.  Then, I found a solution for that too and I made my python script to an application. Wanna know how? Follow the following steps and so you make people to follow you. Have a nice day 🙂

Steps to convert .py to .exe in Python 3.6

  1. You must be installed Python 3.6 and cx_Freeze.
  2. To install cx_Freeze, open your command prompt and type ‘pip install cx_Freeze
  3. make a .py program of yourself say ‘my first prog.py’ .
  4. Create a new python file named ‘setup.py’ on the current directory of your script.
  5. On the setup.py, code this and save it.
  6. With shift pressed right click on the same directory, so you are able to open a command prompt window.
  7. Type in the prompt as >> python setup.py build
  8. If your script is error free, then there is no problem on creating application. Check the newly created folder ‘build‘. It has another folder in it. Within that folder you can able to find your application. Run it. Make yourself happy.

Wanna know your try and your success. Don’t forget to share your comments.

Also take a look How to send notifications to your phone using python script. Code Sheet of Python is also available.

From,

Maria Irudaya Regilan J

Advertisements

Author:

I am J Maria Irudaya Regilan from Chennai. A programmer who urges to develop new things and think on revolutionary ideas that could change the world. I am not enough good in internet but I am on my effort to stand alone. I am inspired by some great men like Sundar Pichai (a local guy from my hometown), Bill Gates, Mark Zuckerberg, Steve Jobs, Elon Musk and sorry, I can't tell everyone since the list goes more than I thought. I like to get beaten up by my own projects, because they test my confidence and ability to get up. Follow my blog and stay connected for receiving ideas on programming languages. Have a cup of coffee!!

34 thoughts on “.py to .exe in Python 3.6.1

  1. Hey, thanks for the tutorial, when i run python setup.py build i get the error “ImportError: No module named ‘inda’”. Any idea on a fix?

    Like

  2. Hi, Maria,
    it’s good to see your blog. It’s very helpful.
    I got the built file under build>exe.win-amd64-3.6>main.exe, and python36.dll. But i can’t run it.
    This is the error infomation.
    PS D:\Python\SnakeGame> python setup.py build
    running build
    running build_exe
    creating directory build\exe.win-amd64-3.6
    copying C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win-amd64-3.6\main.exe
    copying C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\python36.dll -> build\exe.win-amd64-3.6\python36.dll
    Traceback (most recent call last):
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\win32\lib\win32verstamp.py”, line 120, in stamp
    bits = [int(i) for i in ver.split(“.”)]
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\win32\lib\win32verstamp.py”, line 120, in
    bits = [int(i) for i in ver.split(“.”)]
    ValueError: invalid literal for int() with base 10: ”
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
    File “setup.py”, line 26, in
    executables = executables
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\dist.py”, line 349, in setup
    distutils.core.setup(**attrs)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\distutils\core.py”, line 148, in setup
    dist.run_commands()
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py”, line 955, in run_commands
    self.run_command(cmd)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py”, line 974, in run_command
    cmd_obj.run()
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\distutils\command\build.py”, line 135, in run
    self.run_command(cmd_name)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\distutils\cmd.py”, line 313, in run_command
    self.distribution.run_command(command)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py”, line 974, in run_command
    cmd_obj.run()
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\dist.py”, line 219, in run
    freezer.Freeze()
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py”, line 623, in Freeze
    self._FreezeExecutable(executable)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py”, line 225, in _FreezeExecutable
    self._AddVersionResource(exe)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py”, line 166, in _AddVersionResource
    stamp(fileName, versionInfo)
    File “C:\Users\Zhitao\AppData\Local\Programs\Python\Python36\lib\site-packages\win32\lib\win32verstamp.py”, line 123, in stamp
    raise ValueError(“–version must be a.b.c.d (all integers) – got %r” % ver)
    ValueError: –version must be a.b.c.d (all integers) – got ‘.0.0.0’
    PS D:\Python\SnakeGame> python setup.py build
    running build
    running build_exe
    thank you.
    Zhitao

    Like

    1. Thanks for your support… We are working to post some best posts that will be useful for you. On dealing with errors we could see a ValueError. If your have both the int() error and ValueError then change your script by using some more exception handling blocks. This will sure helps you. I trust you have a snake game application soon.

      Like

      1. hi, I got the same problem as Zhitao, please help, I also tried using pyinstaller and py2exe but none of them worked.

        Like

  3. I too got a similar error to Zhitao. Not sure this solution works as it appears to be same issue as py2exe and python 3.6

    Like

  4. Hey…many thanks for this useful tutorial… just 2 quick questions: Any suggestion on how to convert it to a single exe file? also, how to reduce the file size? thanks.

    Like

  5. Hi Maria,
    very good tool!!! All others I tried are not working, so yours is the best! 🙂
    One comment:
    In addition to install “cx_Freeze” I have to install “inda” too. This is not mentioned
    One question:
    Some tools give an option to use key for encryption of source codes. I expect in executable file we have interpreter and sources, right? So, is it possible to have this option?
    Best regards
    ILIJA

    Like

  6. Hi, I followed everything through and managed to make the .exe file of the Python program I had. In my original Python script I had imported the tweepy module which I had installed using pip. Now when I try to run the .exe file I get an error telling me that the tweepy module can’t be found. I reinstalled tweepy from command line using pip and I tried running the .exe file again and it still doesn’t work. It’s strange because when I run the Python file it works. Do you know how I can get it to run as the .exe file?

    Like

  7. Very good described steps from Maria.

    To the issue of “ImportError: No module named ‘inda’”:
    2. To install cx_Freeze, open your command prompt and type ‘pip install cx_Freeze‘
    To install idna, in command prompt type “pip install -I –user pyopenssl”

    Like

  8. Maybe a silly question, but how to make “pip install cx_Freeze” work on Windows console command? Let me just add that I’ve tried adding path to python script to system variables just to get info that ‘pip’ is not recognized as an internal or external command… And does so basic feature must be really so hard to turn on. What do you all guys do with python applications? Run in compilers only???

    Like

  9. hi, Maria,thanks for your tutorial. I followed your steps, I got the similar error to Zhitao, and I changed version value”” to “1.0.0.0”, so it is error free. But when I double clicked the exe, it flashed back. Do you know why?

    Like

  10. Thanks for the post. I was able to build an exe. When I run the exe, I get an error message
    “Import Error : cannot import name ‘_methods’”
    Please advise whats missing. Thanks

    Like

    1. Add these things in your setup.py

      addtional_mods = [‘numpy.core._methods’, ‘numpy.lib.format’]
      setup(name=…, version=…, description=…, options = {‘build_exe’: {‘includes’: addtional_mods}}, executables = … )

      Convert it again and I hope this will help you. Thanks for your comment and don’t forget to follow the blog to get our new posts.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s