I’ve written andspokenat some length about shipping software in the abstract. Sometimes I’ve evenhad the occasional concrete tidbit, but thatadvice wasn’t really complete.
On Mac OS or Linux: sudo pip install pygamecards-0.1.tar.gz On Windows (run command prompt as administrator): pip install pygamecards-0.1.zip ####Installation from sources: To install the pygamecards framework, download this repository, in terminal cd into pygamecards folder and run command: python setup.py install Usage Getting Started. ACCESS the FULL COURSE here: Learn Python 3.6 from scratch while creating your own 'Frogger' style game!. # create a virtualenv called 'anenv' and use it. Python3 -m virtualenv anenv./ anenv / bin / activate # venvdotapp helps the python be a mac 'app'. So the pygame window can get focus. Python - m pip install venvdotapp venvdotapp python - m pip install pygame # See if pygame works with the oo module, and the aliens example. Python - m pygame.
In honor of Eevee’s delightful Games MadeQuick???, I’d like to help youpackage your games even quicker than you made them.
Who is this for?
About ten years ago I made a prototype of a little PyGame thing which I wantedto share with a few friends. Building said prototype was quick and fun, andvery different from the usual sort of work I do. But then, the project gotjust big enough that I started to wonder if it would be possible to share theresult, and thus began the long winter of my discontent with packaging tools.
I might be the only one, but.. I don’t think so. The history ofPyWeek, for example, looks to be a history of gamesdistributed as Github repositories, or, at best, apps which don’t launch. Itseems like people who participate in game jams with Unity push a button andpublish their games to Steam; people who participate in game jams with Pythonwander away once the build toolchain defeats them.
So: perhaps you’re also a Python programmer, and you’ve built something withPyGame, and you want to put it on your website so your friends can download it.Perhaps many or most of your friends and family are Mac users. Perhaps youtried to make a thing with py2app once, and got nothing but inscrutabletracebacks or corrupt app bundles for your trouble.
If so, read on and enjoy.
What changed?
If things didn’t work for me when I first tried to do this, what’s differentnow?
There are still weird little corner cases you have to work around — hence thispost – but mostly this is the story of how years of effort by the Pythonpackaging community have resulted in tools that are pretty close to working outof the box now.
Step 0: Development Setup
Get a good Python.
My recommendation is to use an official build from python.org; these are already compiled in such a way that they will run on a wide range of macs, both new and old. Use a recent Python 3 version, if you can; there are a variety of low-level improvements which make it better for redistribution.
You probably also want to use a
virtualenv for development. This post isabout how to build a for-real thing that other people can download, but part ofthe magic of Python is the interactive, real-time dynamic nature of everything.Running the full build pipeline every time you change a file or an asset isslow and annoying. However, there’s a weird thing where certain parts of themacOS GUI won’t work right (in PyGame’s case, mostly keyboard focus) unlessyour code appears to be in an application bundle.
I made this dumb littlethingwhich lets you fake out enough of this that the OS won’t hassle you: you needto
pip install venvdotapp; venvdotapp inside the virtualenv where you’remaking your pygame app.
Finally:
pip install all your requirements into your virtualenv , includingPyGame itself.
Step 1: Make an icon
All good apps need an icon, right?
When I was young, one would open up
.tiff file.icns file. Nowadays there’s some weird opaquestuff with xcassets files and Contents.json and “Copy Bundle Resources” inthe default Swift and Objective C project templates and honestly I can’t bebothered to keep track of what’s going on with this nonsense any more.
![]()
Luckily the OS ships with the macOS-specific “scriptable image processingsystem”, which can helpfully convert an icon for you. Make yourself a 512x512PNG file in your favorite image editor (with analpha channel!) that you want to use as your icon, then run it something likethis:
somewhere in your build process, to produce an icon in the appropriate format.
There’s also one additional wrinkle with PyGame: once you’ve launched thegame, PyGame helpfully assigns the cute, but ugly, default PyGame icon toyour running process. To avoid this, you’ll need these two lines somewhere inyour initialization code, somewhere before
pygame.display.init (or, for thatmatter, pygame.display.<anything> ):
Obviously this is pretty Mac-specific so you probably want this under some kindof platform-detection conditional, perhaps thisone.
Step 2: Include All The Dang Files, I Don’t Care About Performance
Unfortunately py2app still tries really hard to jam all your code into a
.zip file, which breaks the world in various hilarious ways. Your app will probablyhave some resources you want to load, as will PyGame itself.
Supposedly,
packages=['your_package'] in your setup.py should address this,and it comes with a “pygame” recipe, but neither of these things worked for me.Instead, I convinced py2app to splat out all the files by using thenot-quite-public “recipe” plugin API:
This is definitely somewhat less efficient than py2app’s default of stuffingthe code into a single zip file, but, as a counterpoint to that: it actuallyworks.
Step 3: Build it
Hopefully, at this point you can do
python setup.py py2app and get a shinynew app bundle in dist/$NAME.app . We haven’t had to go through the hell ofquarantineyet, so it should launch at this point. If it doesn’t, sorry :-(.
You can often debug more obvious fail-to-launch issues by running theexecutable in the command line, by running
./dist/$NAME.app/Contents/MacOS/$NAME . Although this will run in a slightlydifferent environment than double clicking (it will have all your shell’s envvars, for example, so if your app needs an env var to work it mightmysteriously work there) it will also print out any tracebacks to yourterminal, where they’ll be slightly easier to find than in Console.app.
Once your app at least runs locally, it’s time to..
Step 4: Code sign it
All the tutorials that I’ve found on how to do this involve doing Xcode projectgoop where it’s not clear what’s happening underneath. But despite the factthat the introductory docs aren’t quite there, the underlying model forcodesigning stuff is totally common across GUI and command-line cases.However, actually getting your cert requires Xcode, an apple ID, and acredit card.
After paying your hundred dollars, go into Xcode, go to Accounts, hit “+”,“Apple ID”, then log in. Then, in your shiny new account, go to “ManageCertificates”, hit the little “+”, and (assuming, like me, you want to putsomething up on your own website, and not submit to the Mac App Store), andchoose Developer ID Application. You probably think you want “mac appdistribution” because you are wanting to distribute a mac app! But you don’t.
Next, before you do anything else, make sure you have backups of your certificate and private key.You really don’t want to lose the private key associated with that cert.
Now quit Xcode; you’re done with the GUI.
You will need to know the identifier of your signing key though, which should be output from the command:
You probably want to put that in your build script, since you want to sign withthe same identity every time. Further commands here will assume you’ve copied one of the lines of results from that command and done
export IDENTITY='..' with it.
Step 4a: Become Aware Of New Annoying Requirements
Best journaling apps android. Update for macOS Catalina: In Catalina, Apple has added a newcode-signing requirement; evenfor apps distributed outside of the app store, they still have to be submittedto and approved by Apple.
![]()
In order to be notarized, you will need to codesign not only your app itself,but to also:
So the actual code-signing step is now a little more complicated.
Step 4b: Write An Entitlements Plist That Allows Python To Work
One of the features that notarization is intended to strongly encourage1 isthe “hardened runtime”, a feature of macOS which opts in to stricter run-timebehavior designed to stop malware. One thing that the hardened runtime does isto disable writable, executable memory, which is used by JITs, FFIs .. andmalware.
Unfortunately, both Python’s built-in
ctypes module and various popular bitsof 3rd-party stuff that uses cffi , including pyOpenSSL , require writable,executable memory to work. Furthermore, py2app actually imports ctypes during its bootstrapping phase, so you can’t even get your own code to startrunning to perform any workarounds unless this is enabled. So this is justif you want to use Python, not if your project requires ctypes directly.
To make this long, sad story significantly shorter and happier, you cancreate an entitlements property list that enables the magical property whichallows this to work. It looks like this:
https://newspeedy210.weebly.com/blog/mac-install-unsigned-app. Subsequent steps assume that you’ve put this into a file called
entitleme.plist in your project root.
Step 4c: SIGN ALL THE THINGS
Notarization also requires that all the executable files in your bundle, notjust the main executable, are properly code-signed before submitting. Soyou’ll need to first run the
codesign command across all your sharedlibraries, something like this:
Then finally, sign the bundle itself.
Now, your app is code-signed.
Step 5: Archive it
The right way to do this is probably to usedmgbuild or something like it,but what I promised here was quick and dirty, not beautiful and best practices.
You have to make a Zip archive that preserves symbolic links. There are acouple of options for this:
Most importantly, if you use the
zip command line tool, you must use the-y option. Without it, your downloadable app bundle will be somewhatmysteriously broken even though the one before you zip ped it will be fine.
Step 6: Actually The Rest Of Step 4: Request Notarization
Notarization is a 2-step process, which is somewhat resistant to fullyautomating. You submit to Apple, then they email you the results of doingthe notarization, then if that email indicates that your notarization succeded,you can “staple” the successful result to your bundle.
The thing you notarize is an archive, which is why you need to do step 5 first.Then, you need to do this:
Be sure that
YOUR_BUNDLE_ID matches the CFBundleIdentifier you told py2appabout before, so that the tool can find your app bundle inside the archive.
You’ll also need to type in the iCloud password for your Developer ID accounthere.2
Step 6a: Wait A Minute
Anxiously check your email for an hour or so. Hope you don’t get any errors.
Step 6b: Finish Notarizing It, Finally!
Once Apple has a record of the app’s notarization, their tooling will recognizeit, so you don’t need any information from the confirmation email or theprevious command; just make sure that you are running this on the exact same
.app directory you just built and archived and not a version that differs inany way.
Finally, you will want to archive it again:
Step 7: Download it
Ideally, at this point, everything should be working. But to make sure thatcode-signing and archiving and notarizing and re-archiving went correctly, youshould have either a pristine virtual machine with no dev tools and no Pythoninstalled, or a non-programmer friend’s machine that can serve the samepurpose. They probably need a relatively recent macOS - my own experience hasshown that apps made using the above technique will definitely work on HighSierra (and later) and will definitely break on Yosemite (and earlier); theyprobably start working at some OS version between those.
There’s no tooling that I know of that can clearly tell you whether your macapp depends on some detail of your local machine.
Updated 2019-06-27: It turns out there is an
auditwheel like thing for macOS: delocate ! Infact, it predated and inspired auditwheel !Thanks to Nathaniel Smith for the update(which he provided in, uh, January of 2018 and I’ve only just now gotten aroundto updating..).
Nevertheless, it’s always a good idea to check your final app build on a freshcomputer before you announce it.
Coda
If you were expecting to get to the end and download my cool game, sorry todisappoint! It really is a half-broken prototype that is in no way ready forpublic consumption, and given my current load ofpersonal andprofessional responsibilities, you definitely shouldn’t expect anything from mein this area any time soon, or, you know, ever.
But, from years of experience, I know that it’s nearly impossible to summon anymotivation to work on small projects like this without the knowledge that theend result will be usable in some way, so I hope that this helps someone elseset up their Python game-dev pipeline.
I’d really like to turn this into a 3-part series, with a part for Linux(perhaps using flatpak? is that a good thing?) and apart for Windows. However, given my aforementioned time constraints, I don’tthink I’m going to have the time or energy to do that research, so if you’vegot the appropriate knowledge, I’d love to host a guest post on this blog, oreven just a link to yours.
If this post helped you, if you have questions or corrections, or if you’d liketo write the Linux or Windows version of this post, let meknow.
All right guys, Best crm app mac.
Pygame Mac Download
I assume that you guys are already install correctly pygame, PGS4A, Java and Android driver (only for windows). How to access iphone apps on mac. If you haven’t, check PGS4A official website and my previous posting.
So, how we can convert / porting the app to Android app?
Step 1:
Rename your main app python file to ‘main.py’
Step 2:
Include ‘import android’ into your main.py
Step 3:
Create a directory that stores your python. All necessary things (images, python files, even libraries or API if it is required). And you must create a directory inside of PGS4A directory.
Pygame Mac Os
Ex) In my case, I just put ‘app1’
Step 4:
Configure the setting. Type ‘python android.py app1 configure’
This command will help you to setup your app.
Step 5:
Then, build & release. Type ‘python android.py build app1 release’
Step 6:
Check ‘bin’ directory. There should be ‘your_app.apk’
Once you success once, next time will be dang easy. ?
I faced a little problem. The game I developed didn’t work on Android. Why? Because of input. My game was using keyboard, but it didn’t work in PGS4A.
Pygame Mac Install
So, I will show you guys how to change your app/games input for Android in next posting.
Pygame To Mac App Offline
Author: Jimy (https://jimypython.wordpress.com/)
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |