How do I compile my Python 3 app to an .exe? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
How do I convert my Python app to a .exe? I made a program with tkinter and was wondering how to make it possible for others to use. I use Python 3.3. I searched for a bit but could not find anything.

cx_Freeze does this but creates a folder with lots of dependencies. py2exe now does this and, with the --bundle-files 0 option, creates just one EXE, which is probably the best solution to your question.
UPDATE: After encountering third-party modules that py2exe had trouble "finding", I've moved to pyinstaller as kotlet schabowy suggests below. Both have ample documentation and include .exes you can run with command line parameters, but I have yet to compile a script that pyinstaller isn't able to handle without debugging or head-scratching.
Here's a simple convenience function I use to build an .exe with my defaults from the interpreter (of course a batch or similar would be fine too):
import subprocess,os
def exe(pyfile,dest="",creator=r"C:\Python34\Scripts\pyinstaller.exe",ico=r"C:\my icons\favicon.ico",noconsole=False):
insert=""
if dest: insert+='--distpath ""'.format(dest)
else: insert+='--distpath "" '.format(os.path.split(pyfile)[0])
if ico: insert+=' --icon="{}" '.format(ico)
if noconsole: insert+=' --noconsole '
runstring='"{creator}" "{pyfile}" {insert} -F'.format(**locals())
subprocess.check_output(runstring)

I have found PyInstaller to work the best.
You have many options for example you can pack everything to a one file exe.
I love to use it together with Cython for speed.

You can use cx_Freeze. There is a guide here.

Use Pyinstaller.
After installing it, open terminal in the directory where your project resides.
$ pyinstaller script1.py script2.py ... (where script1, script2, etc. are all the scripts used in your project.)
After command is completed, open dist folder and enter the subdirectory. There you'll find an executable.
Hope it helps.

Related

run my python script easily on any other laptop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have written a script (around 2k lines) for processing text.
It reads the input form my text file, and print the output in another file.
But, I want it can be run on any other laptop (with Python installed) easily as well. For example,
other people can run it without installing additional libraries (that I had imported in the script).
How can I realize my purpose? By packaging my script in a library or what else I can do? Please provide any hint.
I tried to use the pyinstaller or the py2exe, but I always have a problem of over recursion limit,
and since I have several huge sized libraries being imported, so I guess even I can finally make a .exe file,
it would be in a huge size, so I stopped to using that way. Anyone has a comment on it?
If you're sure that every client has Python and pip installed and present in PATH, you can just pip install the libraries in the beginning of your script. Something like this:
import subprocess
subprocess.run(['pip', 'install', '--user', 'your', 'libs'])
import your
import libs
This is just a general idea, maybe hacky, and definitely requires additional work with error handling, etc.

How to show finished project? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am a complete, absolute beginner so please excuse my ignorance!
I have created my first 'coding project' using Visual Studio Code IDE in Python, here is a link to it below:
https://github.com/monicaneill/Projects/blob/master/guessinggame.py
Basically my question is how do I show this to others in a way that they can interact with it and not just look at a bunch of text? I'm really proud of my achievement and want other people to be able to play the game who might not have the likes of Visual Studio etc to run the code, is there any way I can do this so someone on say Facebook could open up a file and then run the game?
Thank you so much and apologies in advance if this is not the right place to ask this sort of question!
A python file needs the python runtime to be run. With the python runtime on your system, you can simply do, in your terminal-
> python guessinggame.py
(assuming guessinggame.py is on the same directory)
However, I assume you want people to be able to run the code without having the python runtime installed.
In that case, you need to compile your python code to an executable native binary. There are tools to aid in this process - perhaps the most straightforward tool is pyinstaller
Firstly, you need to install pyinstaller in your own system-
pip install pyinstaller
Now, in your terminal, you simply have to do-
pyinstaller guessinggame.py
(Make sure you're on the same folder where guessinggame.py is)
This will create a folder on the same directory that contains all the files needed to launch your script as well as an .exe (if you're on windows) - your friends will only need this folder and all they have to do is run the .exe
You can find more information about pyinstaller and how to make executables with it here
Search by flask -> documentation
I think this is more or less what you are looking for.

Which packaging is appropriate for a Python Application? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
py2exe is great, and I use it whenever I want to package up a python program to run on a Windows system.
My question is, is there an equivalent tool that I can use to package up the program on Windows, but that I can then run on Linux?
here is also PyInstaller that supports Linux, MacOS and Windows - I have not used it (yet) so I don't know if you can package stuff on windows for linux, but glancing over the manual it seems to be possible.
EDIT:
The FAQ states explicitly that you can not create a windows package from linux and no mac os package from linux neither - there is nothing about creating a linux package from the other two sources, but it might not work.
EDIT2:
After googling a bit I found cx_freeze which might also be worth a look.
I really doubt that you can do something like that at all.
What you could do is just configure yourself 3 build VMs one for Windows, one for MacOS and one for Linux that have everyhing you need to run your program.
Then use either a combination of py2exe/py2app/pyinstaller to generate a distribution for each of the platforms. You will have 3 different pacakges but each one of them will be nicely packed and with no need to install anything else on the client machines.
Ok, I've done this. It's a little hacky, but it works very well for my use case.
The gist of it is to use ModuleFinder to find all imported modules, filter out any system ones, compile them and zip them up.
Unfortunately my code for this is littered with additional complications that don't have any relevance to this question, so I can't paste a working program, just some snippets:
zipfile = ZipFile(os.path.join(dest_dir, zip_name), 'w', ZIP_DEFLATED)
sys.path.insert(0, '.')
finder = ModuleFinder()
finder.run_script(source_name)
for name, mod in finder.modules.iteritems():
filename = mod.__file__
if filename is None:
continue
if "python" in filename.lower():
continue
subprocess.call('"%s" -OO -m py_compile "%s"' % (python_exe, filename))
zipfile.write(filename, dest_path)

Python development in Windows [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I've been writing and using short Python scripts (~100 lines) for various tasks in Ubuntu using the Geany text editor, which I like for it's simplicity (setup, F5 to run, etc.) and syntax highlighting.
I would like to know if there is a similar application for Windows. Because what I've found so far requires downloading 3 different applications or using a big IDE like eclipse.
You can use the Geany build for Windows
You can still use Geany to run Python in windows.
But if you need to debug, auto-complete and beautiful IDE, I suggest that you head for pycharm.
Microsoft's Python Tools for Windows now works as a plugin for Visual Studio Express (and not just the paid version of Visual Studio) so you get nice free solution that has everything you need with a pretty simple install. It can be found at: http://pytools.codeplex.com/
Any good programmer's text editor will do. I personally use SublimeText 3, but I've used Eclipse + PyDev before to great success, and the usual suspects (emacs, vim, Notepad++) will work just fine too.

Basic steps to develop python API in Unix environment [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am developing an API in Unix environment for virtual machines. Most of the modules are developed in python. I have few questions on this.
I have the file extension as abc.py . I would like to make this as a command. For example , "virtman dominfo [vmid]" should be the command syntax. Now I have to give "virtman.py dominfo [vmid]" to achieve this. So how can make this as a command?
I want to make this as an installable API, I mean to install through apt-get/ yum install. What are the steps I need to do to achieve this or some reference URL's would be helpful.
Inside the API I am using absolute path like '/root/virtman/manager/' . Consider running this API in any unix environment , how can I make this absolute path generic to any OS/machine. Or should I have to assume some location where the API will get installed and give that path everywhere?
I read lot of articles but I didn't get the clear picture,so any hints/suggestions would be helpful.
This seems like it's three questions in one, so I'll attempt to answer each in turn:
File Extensions
Python scripts don't need to have a .py extension in order to be run. For example:
#!/usr/bin/python
print("Hello, World!")
Save this as a file called hello and flag it as executable. You should be able to run it from a terminal window by entering ./hello
apt-get / yum
Different systems use different packaging systems. For example, Debian and derivatives such as Ubuntu use .deb files, while Red Hat and co. use .rpm instead (though Debian can load .rpm files via the "Alien" tool). Each is slightly different, so I can't really give you a "generic" answer - hopefully this should be enough to get you started: https://fedoraproject.org/wiki/How_to_create_an_RPM_package
Generic Paths
You should be okay if you stick to the usual /var, /etc, /tmp layout - see this Wikipedia page for details.

Categories