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
- You must be installed Python 3.6 and cx_Freeze.
- To install cx_Freeze, open your command prompt and type ‘pip install cx_Freeze‘
- make a .py program of yourself say ‘my first prog.py’ .
- Create a new python file named ‘setup.py’ on the current directory of your script.
- On the setup.py, code this and save it.
- With shift pressed right click on the same directory, so you are able to open a command prompt window.
- Type in the prompt as >> python setup.py build
- 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
Yes I have done it. But now How I can run it in another computer?
LikeLike
Can’t you run it in another computer by just double clicking it…?… Does it shows any problem?
LikeLike
Thanks for your comment… Copy the whole build folder to another Computer and try it… If any issues occur, do inform us… 🙂
LikeLike
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?
LikeLike
Thanks… There’s no chance of getting an error like what you have got. Because I have changed my setup.py file to fix that error. Have you download my setup.py?
LikeLike
go to the Scripts folder and run “pip install idna”
LikeLiked by 1 person
I got the same “No module named ‘idna’…I also downloaded your setup.py
LikeLike
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
LikeLike
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.
LikeLike
hi, I got the same problem as Zhitao, please help, I also tried using pyinstaller and py2exe but none of them worked.
LikeLike
Use cx_freeze… Hope it will solve your problems
LikeLike
I did, I tried a lot of ways… and the cx_freeze way gave the same problem as Zhitao, please help.
LikeLike
In your setup.py change your ‘version’ value assignment as an integer. Contact us anytime at http://www.facebook.com/jrtinst/
LikeLike
Have you changed the setup variables in setup.py? Chances are you still have the placeholder version of
LikeLike
No changes have done here. If you suspect anything change it as favour to you. 🙂
LikeLike
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
LikeLike
thumbs up
LikeLike
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.
LikeLike
Thanks for your support… We can make a setup file for your exe file… And we are working on it… Soon, you can know that too… Stay connected with our blog..
LikeLike
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
LikeLike
Thanks.. We appreciate your comment that improve us… Sorry, I am not sure about having the encryption… We work on it and we will sure post it… Do follow our blog for more posts..
LikeLike
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?
LikeLike
nvm I fixed it
LikeLike
Good…
LikeLike
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”
LikeLike
Thanks. Keep following our blog
LikeLike
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???
LikeLike
May be the directory where you have been installed your python didn’t connected to your environment variables. Copy the path of your python directory and make it as your environment variable. It helps. 🙂
LikeLike
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?
LikeLike
Thanks a lot. Check your program. Because our exe just works as we coded.. if you wanna talk with me, catch me at @regilanj in Facebook messenger. Do follow our blog. 🙂
LikeLike
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
LikeLike
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.
LikeLike
It Worked. Thanks.
LikeLike
O que fazer?
Ao tentar:
“python setup.py build” ===> “No module named ‘idna’
Segui sua recomendação:
“pip install -I -user pyopenssl” ===> “no such option: -u”
E agora?
LikeLike
Thanks for reaching us. Please post your doubts in English. It’s easy to give you a solution
LikeLike
go to the Scripts folder and run “pip install idna”. else, To install idna, in command prompt type “pip install -I –user pyopenssl”. try it.
LikeLike
Go to the scripts folder and run “pip install idna”
Else, to install idna, in command prompt type “pip install -I -iser pyopenssl”.
Try these. 🙂
LikeLike
when i tried to run the exe file it displays following error. what should i do?
Fatal Python error: Py_Initialize: unable to load the file system codec
Traceback (most recent call last):
File “C:\Users\SHEKAR\AppData\Local\Programs\Python\Python36-32\lib\encodings\
__init__.py”, line 31, in
ModuleNotFoundError: No module named ‘codecs’
LikeLike
Reinstall your python from source and reinstall your packages. Thank you for reaching us. FOLLOW our blog for more ideas.
LikeLike
Reinstall your python, cx freeze and other major packages you have installed in your project. This may work. FOLLOW our blog for more ideas.
LikeLike
Hey, thanks for the tutorial, when I run python setup.py build I encounter this error :
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’
how can I fix it ?
thank you ,,
LikeLike
Thank you for reaching us. Give your version value as an integer not as alphabets.
Follow our blog for more information.
LikeLike
can u fix it ?
LikeLike
No! It is specified as default as an integer %d not as a string. So, we are to follow the rules. 🙂
LikeLike
I ran the codes and this error appears: “SyntaxError: unexpected EOF while parsing” with an arrow point right below the “.” in File “C:\Data Discrepency\setup.py”, line 27
Any idea on how to fix. Thank you very much for helping out!
LikeLike
Thank you for reaching us. You may have missed out any parentheses at the end of your script. If not, send us your script file we’ll fix you. Follow us for more details.
LikeLike
KeyError: ‘TCL_LIBRARY’, how to fix this? thank you in advance.
LikeLike
Check this out… https://stackoverflow.com/questions/35533803/keyerror-tcl-library-when-i-use-cx-freeze
LikeLike
The build worked fine, however for some reason I have an issue where the application will not open. It quickly opens up a command prompt, however that closes almost immediately after. Is there something I am missing?
LikeLike
Check this out.. https://stackoverflow.com/questions/41384319/cx-freeze-exe-application-closes-as-soon-as-opens
LikeLike
hello, can you do an exe file so that it runs only on the program? without a console window?
LikeLike
thanks for reaching us! Actually it is the console window that runs the program you have coded. If you don’t want the console window, make your own graphics on the program using some of our pythonic libraries like Turtle. Follow us for more news!
LikeLike
Hi, thanks for your answer. The console window does not bother me when the program starts. The problem is when there are two windows in the start bar. One is my program and the other is the console window.
LikeLike
I followed you directions and got this error when I run the file. I use pandas, but not specifically numpy. Any ideas? I imported numpy in my code, and it still happens (even though I don’t need to import numpy in my code for it to run)
——
(bandwidth36) C:\GitHub\bandwidth\build\exe.win-amd64-3.6>find_numbers.exe
Traceback (most recent call last):
File “C:\Python\Anaconda3\envs\bandwidth36\lib\site-packages\cx_Freeze\initscripts\__startup__.py”, line 14, in run
module.run()
File “C:\Python\Anaconda3\envs\bandwidth36\lib\site-packages\cx_Freeze\initscripts\Console.py”, line 26, in run
exec(code, m.__dict__)
File “find_numbers.py”, line 4, in
File “C:\Python\Anaconda3\envs\bandwidth36\lib\site-packages\pandas\__init__.py”, line 19, in
“Missing required dependencies {0}”.format(missing_dependencies))
ImportError: Missing required dependencies [‘numpy’]
LikeLike
Thanks for reaching us! Remove the numpy import line in your code since you have said that you are not using numpy in it. Else, use the command in your prompt window, “pip install numpy”. Follow us for more news!
LikeLike
Hello, I have another question. How to add another program to an already created program to make use of the same libraries?
LikeLike
An .exe was build but it doesn’t run why?
LikeLike
what was your error sir?
LikeLike
Hi!.. It works!!! Thank you!!!… only a little question…
My aplication get a huge (about 1GB) folder, I supouse it’s due to the modules import. Is there a way to obtain a smaller folder?
LikeLike
hi ,
could you please share the setup.py file, the link is no more working
LikeLike
It is working still! You can download it from here https://drive.google.com/file/d/0B3e4ErQeXruDeHpGOTlCMlBpSUU/view or say any other media to share with you! Thank you.
LikeLike
what do we do if we get *KeyError: ‘TCL_LIBRARY’*?
LikeLike
Hi Maria, thanks for this great tutorial.
I have converted my .py to .exe for multiple files and it worked like a charm. But on 1 file I’m getting an error :
ModuleNotFoundError : No module named ‘data_ser__init__’
My original data_ser.py file is running OK.
LikeLike
Hi Maria Irudaya Regilan,
I followed your steps in my ubuntu 16.04 system. I wanted to get an .exe file out of my python script. But I got an executable file where I can run that in ubuntu. But to run my script in windows I want a file with extension “.exe”.. I do not find the .exe file inside the build folder.. Should I do the above steps in my windows to get an .exe file ? Please help
LikeLike