Is it in the works? As soon as its available I'll be able to move forward on a lot of projects.
Forum Archive
When will OMZ release an Xcode Template for Python3?
+1 For python 3. @omz
Here's a first attempt at a Python 3-based Xcode template: https://www.dropbox.com/s/5l94m0xjbot5je0/Pythonista3AppTemplate.zip?dl=1
This is roughly equivalent to the current App Store version (not the 3.3 beta), and not final, just something to play around with for people interested in the Xcode template. Let me know if anything's unclear.
Thank you! I will give it a try.
So far it works great! Everything that wasn't working on the old template works now.
thank you I will try it!
How do I make it so that the app runs in an iPhone simulator instead of an iPad simulator?
@omz in this new template do you guys have photos working?
@omz I am not sure if it is just me but the new template works great in the simulator but I cannot upload it to the App Store because it has the same code signing errors the previous template had.
@RomSpy Could you show me a screenshot of those errors?
@omz it may be operator error. I found an issue with how I was signing the app. I tried to upload it again to see but I am just having connection errors right now.
@omz after messing around with the template and my code signing settings which work on the previous template this is what I found:
I added #import 'pythonista' to the pykit_preflight.py and the error went away on that file.
Also it seems that any .py file with a "#!" near the top also has code signing issues.
I may be doing something wrong as I am not that familiar with Xcode code signing but on the off chance that it is not me here is the error code.
The error received is:
ERROR ITMS-90035: "Invalid Signature. Code object is not signed at all. The file at path [Pythonista3AppTemplate.app/Frameworks/Py3Kit.framework/pylib/wave.py] is not properly signed. Make sure you have signed your application with a distribution certificate, not an ad hoc certificate or a development certificate. Verify that the code signing settings in Xcode are correct at the target level (which override any values at the project level). Additionally, make sure the bundle you are uploading was built using a Release target in Xcode, not a Simulator target. If you are certain your code signing settings are correct, choose "Clean All" in Xcode, delete the "build" directory in the Finder, and rebuild your release target. For more information, please consult https://developer.apple.com/library/ios/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html"
there was a long thread about this topic. The issue is that the file command says .py files are executable, and thus need to be signed. The import pythonista was to trick file into thinking it is objc source code. It should be possuble to create a custom .mgc file that file uses to determine file types, and maybe trigger on the shebang line, etc, that makes it say it is a plain text file.
others created a script to go through every file in the template and add the import statement.
@omz is there any chance we'll get a today widget for this App Template? Maybe have two separate scripts, main.py for the main app and today_widget.py for the today widget?
@JonB Where would you put the import statements? When I say #import "pythonista" it says that 'pythonista' file not found
@RomSpy Did you figure out how to get your app uploaded?
Sorry, i should have linked to the long thread:
https://forum.omz-software.com/topic/3744/xcode-template-for-pythonista/31?page=2
Near the middle, someone posted a script that automatically inserted #\input texinfo at the start of every file, but it required sometimes hundreds of these. Later omz said that tou could replace that with #import pythonista, which fools the filecommand. you could probably modify the script to use that instead.
@JonB Sorry, I'm still struggling, how do I execute this code so that it puts the line at the start of every file? And where do I put my code in the app folder?
@JonB
So for example, this file is the PYAAppDelegate.h and I put '#import pythonista' at the top as seen in the code excerpt below.
//
// AppDelegate.h
// Pythonista3AppTemplate
//
// Created by Ole Zorn on 25.08.18.
// Copyright © 2018 Ole Zorn. All rights reserved.
//import pythonista
import
@interface PYAAppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@end
This results in an error that states "Expected "FILENAME" or
What do I do to get rid of this error?
No no no. You only add this to the python files (.py), not .h or .c or .m, etc.
@JonB ok so now the only problem I'm having is the error saying :
"App Store Connect Operation Error
ERROR ITMS-90035: "Invalid Signature. Code object is not signed at all. The file at path [Pythonista3AppTemplate.app/Frameworks/Py3Kit.framework/pykit_preflight.py] is not properly signed. Make sure you have signed your application with a distribution certificate, not an ad hoc certificate or a development certificate. Verify that the code signing settings in Xcode are correct at the target level (which override any values at the project level). Additionally, make sure the bundle you are uploading was built using a Release target in Xcode, not a Simulator target. If you are certain your code signing settings are correct, choose "Clean All" in Xcode, delete the "build" directory in the Finder, and rebuild your release target. For more information, please consult https://developer.apple.com/library/ios/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html""
I think that's the last roadblock. Thanks so much for your help so far!
@JonB hmmmm, now when I try to upload it again all it says is "app store connect operation error: an error occurred uploading to the app store"
Did you add that line to the pykit_preflight.py?
@JonB what is pykit_preflight.py? I don't have that file
Did you read the error message?
Pythonista3AppTemplate.app/Frameworks/Py3Kit.framework/pykit_preflight.py
@JonB Nevermind, I found it after showing the package contents of the py3kit framework!
But now I while i'm uploading, it stopped after a full bar stating "Completed App Store Operation" and it seems like it should be done, but it's not finishing the upload.
@JonB it just ended and still resulted in the error - App Store connect operation error: An error occurred uploading to the App Store.
What else should I do for it to work?
@JonB Is there a difference between:
1) #import pythonista
and
2) #import 'pythonista'
Try searching stackoverflow for your error message
https://stackoverflow.com/questions/47667446/an-error-occurred-uploading-to-the-app-store-with-no-error-code/47672812#47672812
@omz I successfully update my app in the App Store using the new template. I did have to add more #import 'pythonista' lines to get it to work.
One question I have is it deletes the database I am using when it does the update do you know if there is a way to prevent this? The database is created in the script folder by Pythonista when it first runs the app unless the database already exists. I have not had this problem with any other updates to the app that I have done.
@vignesh Are you archiving your app before uploading? If that is not working export your .ipa file and use the application loader instead that usually solves the problem you are describing.
@RomSpy which files did you have to add the #import 'pythonista' line on? Even on application loader I am still getting the same error
@vignesh You need to add it to every .py file in the template. You shouldn’t get an upload error just the code not signed error from not having the import Pythonista.
Try this: https://stackoverflow.com/questions/46463778/xcode-9-an-error-occurred-uploading-to-the-itunes-store
@RomSpy I tried what was provided in the stackoverflow, but it did not make a difference. Do you happen to remember which files from the Pythonista3Xcode Template you had to add the #import 'pythonista' line to? I already did the one for the py3kit_preflight.py
I find the template and the info on how to use the template to be in Dropbox and scattered across numerous forum threads. It would be more helpful if the up-to-date template with docs and a few working examples were in a repo. https://github.com/omz/PythonistaAppTemplate or other.
@vignesh you have to fix every .py file. Are you getting code signing errors?
@vignesh I will upload the fixed template for you later today.
@JonB I looked into it more and I'm pretty sure I am
@RomSpy Thank you so much!
Updated template https://www.dropbox.com/s/7t6ew3ts4e58l8e/Pythonista3AppTemplate.zip?dl=0
@RomSpy So in the updated template, in the Py3kit_preflight.py file, there is no "#import pythonista' " statement at the beginning, was this intentional?
@RomSpy with the updated template, I am still getting code signing errors :(
It was not intentional I must have uploaded the wrong file. Sorry. I will get a new one.
@vignesh sorry I pasted the wrong link. I have both the original and the modified template in my Dropbox. https://www.dropbox.com/s/mvzc0lhhv6pcfju/Pythonista3AppTemplate%20Updated.zip?dl=0
@RomSpy it worked and my app is waiting on review now thank you!!
@vignesh You’re welcome.
It looks like my workaround for High Sierra has stopped working on Mojave... Replacing the file utility that Xcode uses doesn't seem entirely trivial, due to System Integrity Protection.
I still have a Mac with High Sierra to upload builds, but I think I'll have to change my approach pretty soon, and there isn't really much of a point releasing the Py3 template as it is, because it's probably broken for everyone on Mojave…
If I don't find a better way, I might just package the standard library as a zip file, and unzip it on first launch, but that would require more storage space and also slow down the first launch.
@omz The version I have posted works on Mojave
@omz From what I read, the file ~/.magic is checked by file before using the usual /usr/share/misc/magic.mgc, though maybe that is not documented anywhere. So you might try crafting a file there and see if you can get file to change its output.
@omz I just played around a little and found that #LyX at the start of a Python script apparently guarantees file to recognize it as a LyX document, overriding all of the Python code detection patterns. I'm still on OS X 10.11, but I have a newer file version (5.35) installed through MacPorts, so hopefully its behavior is close to the version that 10.14 has.
I don't quite understand how magic file entries are prioritized and why exactly this works. I'm guessing it's because the LyX pattern looks for a literal string at byte 0, whereas the "smart" Python code detection patterns do a string search over a byte range, so the LyX rule is preferred because it's simpler.
@JonB ~/.magic is documented in the manpage of my MacPorts version of file, but not in the OS X default version's manpage. Maybe it's just a version difference, in which case it should work on 10.14. A custom magic file would probably be the best solution, so we don't have to keep looking for new ways to trick file every time they improve their Python patterns.
@JonB That's really interesting, but I can't get it to work. file just ignores my custom ~/.magic file (that works when I pass it with the -m flag).
@dgelessus The #LyX approach seems to be working on Mojave, though I haven't yet tested with the entire library. Thanks!
@RomSpy
Dear Rom,
Could you share the link to the latest Pythonista3 template again as the link above does not work anymore?
Also, have you also managed to successfully upload any app on macOS Catalina?
Regards
Hi Rom,
I would also be appreciated if you could post it again.
Thanks a lot in advance.
Here is the last version I used. I have not tried to use this in a while I imagine it may not work with the latest version of Xcode but you are welcome to try.
https://www.dropbox.com/s/nq3ff9gw1xq0udt/Pythonista3AppTemplate%20Updated.zip?dl=0
@RomSpy actually your template works well with today’s XCode & latest iOS 14. I only had to on/off the Workspace checking in the build settings, and that’s it. Thanks!
Thanks for this!
When I physically connect an iPad it works beautifully in Xcode 13.3.1 (MacOS 12.3.1) on a Mac Mini M1
However, building for a simulator, I get this:
ld: building for iOS Simulator, but linking in dylib built for iOS, file
'/Users/andreas/Library/Mobile Documents/com~apple~CloudDocs/CloudSrc/Pythonista3AppTemplate Updated/Pythonista3AppTemplate/Py3Kit.framework/Py3Kit'
for architecture arm64
I suspect the linker is telling me that the arm64 version is meant for an iOS device and that it is missing an arm64 version for MacOS? Does anybody know of a solution?
Thanks!