I apologize for such a basic question. I've done some research online and still cannot figure out for the life of me how to turn a python folder into something like an actual app I can open in OS X. I am using Mac OS X, Terminal and Coderunner for my Python project.
Here are a few options:
Platypus is not Python-specific. It lets you wrap a simple GUI around a command line tool.
py2app is Python-specific and a good choice if you have a GUI, or need to run in the background.
PyInstaller is similar to py2app but cross-platform; I've never used it, so I don't know how well it works.
The right choice depends on what your program does; who is the expected audience — do you need to redistribute it, if so how, and so forth. If you want to make the application entirely self-contained — not dependent on anything else beyond the OS — then things get more complicated (though certainly not insoluble; there are several commercial Mac desktop apps written in Python.)
Typically you would make the script executable by putting
#!/usr/bin/env python
as the first line, and then in a terminal window typing
chmod u+x myscript.py
You might also want to put it in a special scripts folder and then add that to your PATH by editing .bash_profile. (I am putting a lot of buzz-words here to help you find the tutorials explaining how these things work.)
You can wrap your script into an Automator object if you want to try running it that way, but in the long run you will be better off getting comfortable working in a terminal window.
It would also help to know what your app does: Process files, generate a GUI, do a calculation, etc...
Related
So I just created a simple script with selenium that automates the login for my University's portal. The first reaction I got from a friend was: ah nice, you can put that on my pc as well. That would be rather hard as he'd have to install python and run it through an IDE or through his terminal or something like that and the user friendliness wouldn't be optimal.
Is there a way that I could like wrap it in a nicer user interface, maybe create an app or something so that I could just share that program? All they'd have to do is then fill in their login details once and the program then logs them in every time they want. I have no clue what the possibilities for that are, therefore I'm asking this question.
And more in general, how do I get to use my python code outside of my IDE? Thusfar, I've created some small projects and ran them in PyCharm and that's it. Once again, I have no clue what the possibilities are so I also don't really know what I'm asking. If anyone gets what I mean by using my code further than only in my IDE, I'd love to hear your suggestions!
The IDE running you program is the same as you running your program in the console. But if you dont want them to have python installed (and they have windows) you can maybe convert them to exe with py2exe. But if they have linux, they probably have python installed and can run you program with "python script.py". But tell your friends to install python, if they program or not, it will always come in handy
To be clear, not just "run python scripts"
But to make my python script a "executable" or "callable" program
that can be used in other programming languages or platforms.
More like a API maybe.
The thing is I implemented several algorithms in java and
they're supported by numpy and spipy, but others want to
call my python program in their java program.
Then the numpy and spipy are problems. They can't be in java and
jython...
Is there a solution that I can make this an executable program that others don't need the environment but just to run the program with several parameters accepted?
If you just need to make the python programs executable, then you can add a line to the top like this:
#!/usr/bin/python
Replace /usr/bin/python with the filepath to python, which can be obtained by typing
which python
into the terminal, assuming you're using a unix-based system.
You can then tell the operating system that the program is executable with
chmod +x nameofprogram
If the java programs require something more complicated than just being able to run the python parts as executables, then you'll probably need to provide more information for anyone to be able to help you.
I am developing a simple standalone, graphical application in python. My development has been done on linux but I would like to distribute the application cross-platform.
I have a launcher script which checks a bunch of environment variables and then sets various configuration options, and then calls the application with what amounts to python main.py (specifically os.system('python main.py %s'% (arg1, arg2...)) )
On OS X (without X11), the launcher script crashed with an error like Could not run application, need access to screen. A very quick google search later, the script was working locally by replacing python main.py with pythonw main.py.
My question is, what is the best way to write the launcher script so that it can do the right thing across platforms and not crash? Note that this question is not asking how to determine what platform I am on. The solution "check to see if I am on OS X, and if so invoke pythonw instead" is what I have done for now, but it seems like a somewhat hacky fix because it depends on understanding the details of the windowing system (which could easily break sometime in the future) and I wonder if there is a cleaner way.
This question does not yet have a satisfactory answer.
If you save the file as main.pyw, it should run the script without opening up a new cmd/terminal.
Then you can run it as python main.pyw
Firstly, you should always use .pyw for GUIs.
Secondly, you could convert it to .exe if you want people without python to be able to use your program. The process is simple. The hardest part is downloading one of these:
for python 2.x: p2exe
for python 3.x: cx_Freeze
You can simply google instructions on how to use them if you decide to go down that path.
Also, if you're using messageboxes in your GUI, it won't work. You will have to create windows/toplevels instead.
I am new to python programming and development. After much self study through online tutorials I have been able to make a GUI with wxpython. This GUI interacts with a access database in my computer to load list of teams and employees into the comboboxes.
Now my first question is while converting the whole program into a windows exe file can I also include the .accdb file with it...as in I only need to send the exe file to the users and not the database..if yes how.
My second question is... I actually tried converting the program into exe using the py2exe (excluding the database...am not sure how to do that) and I got the .exe file of my program into the "Dist" folder. But when I double click it to run it a black screen (cmd) appears for less than a second and disappears. Please help me understand the above issue and resolve it.
am not sure if I have a option of attaching files...then I could have attached my wxpython program for reference.
Thanks in advance.
Regards,
Premanshu
The console could possibly appear if you used the 'console' parameter to setup(). Switch to 'windows' instead if that is the case. Can't say for sure without seeing your setup.py script. Possibly your app could also be opening console, but again hard to say without seeing source. One thing to check is to make sure you are not printing anything to stdout or stderr. You might want to redirect all of stdout and stderr to your log just in case, and do this right at the top of your start script so that if some 3rd party import was writing to stdout you'd be able to capture that.
The db is not part of your executable, so py2exe will not do anything with it. However, you should probably package your application with an installer, and you can make the installer include the db and install it along with the executable.
I've written a nice Python application that is basically an HTTP proxy for SMS modems, and I'd like to make it a double-clickable application on Macs. So far I've been including a .commmand file which is double-clickable, which basically consists of
cd `dirname $0`
(sleep 8;open http://127.0.0.1:8080/)&
mac/slingshotsms.app/Contents/MacOS/slingshotsms
How can I make the main .app executable call a different place / or what's the easiest way to make an application that is basically a wrapper for a terminal utility and only displays its output? Currently double-clicking on the application will use the open utility on Macs - I want to emulate the behavior of double-clicking on Contents/MacOS/slingshotsms when double-clicking on the application icon. any tips?
If you're looking for 'easy', try just giving your python script a .command suffix, and make sure it's executable. For example:
#!/usr/bin/env python
# file: hello.command
print 'hello world'
If you're looking for 'polished', then you probably want to learn about Launch Services, PyObjC, Interface Builder, NIB files, app wrappers, and all sorts of Mac OS X-specific technology details. But, note that PyObjC is nearly impossible to use for anything non-trivial without already knowing, more or less, how to do the same task using the Objective-C Cocoa APIs. PyObjC is a fairly thin wrapper around those APIs, and you have to know the Cocoa idioms / design patterns to understand how the moving parts fit together.
If you don't actually need a terminal, but instead just want an app wrapper around a script, have a look at Platypus
Write an AppleScript application that launches Terminal and runs your Python script (which will be inside the application's bundle).