質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Kivy

Kivyは、Pythonを用いたNUI開発のためのオープンソースフレームワーク。マルチタッチなど多くの入力に対応したNUIアプリなどを開発することができます。多くの環境で動作するクロスプラットフォームです。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Q&A

0回答

852閲覧

Unable to open main.py, abort.を解決したい。(kivyを使ったiOSアプリ開発)

Fuji-1996

総合スコア4

Kivy

Kivyは、Pythonを用いたNUI開発のためのオープンソースフレームワーク。マルチタッチなど多くの入力に対応したNUIアプリなどを開発することができます。多くの環境で動作するクロスプラットフォームです。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

GitHub

GitHubは、Gitバージョン管理システムを利用したソフトウェア開発向けの共有ウェブサービスです。GitHub商用プランおよびオープンソースプロジェクト向けの無料アカウントを提供しています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

0グッド

0クリップ

投稿2020/12/10 08:09

前提・実現したいこと

前提:iOSアプリをXcodeのみで作成したことがあります。
githubを使って上手くいったことがないので、自信がないです。
実現したいこと:Unable to open main.py, abort.を解決したい。

ニワカに信じがたいのですが、Runボタンを押すとmain.pyが消えてしまうことが、一番の問題と考えています。

こちらサイトを参考にしています。
https://github.com/kivy/kivy-ios
ページ内の
$ open touchtracer-ios/touchtracer.xcodeproj
までは、ある程度上手くいっていると思います。
$ brew doctorで出てくるエラーには対応しています。

ターミナルでversionを検索した時の出力
$ python --version //Python 3.9.0
$ cython --version //Cython version 0.29.17
$ brew --version //Homebrew 2.6.0
$ pyenv --version //pyenv 1.2.21

発生している問題・エラーメッセージ

発生している問題
ターミナルを使ってxcodeを開いた後で、Runするとアプリケーションが開ません。
下記エラーメッセージは、Consoleに表示されるものです。

2020-12-06 21:08:28.514060+0900 newapp[93490:1586839] Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown① 2020-12-06 21:08:28.514273+0900 newapp[93490:1586839] Initializing python② 2020-12-06 21:08:28.898615+0900 newapp[93490:1586839] Running main.py: (null)③ 2020-12-06 21:08:28.898927+0900 newapp[93490:1586839] Unable to open main.py, abort.④ 2020-12-06 21:08:28.913281+0900 newapp[93490:1586839] Leaving⑤

後で①から⑤が出てきます。

試したこと

※推測が多いです、申し訳ありません。

githubの内容をインストールすると、階層構造としては以下の様になります。
titletest.xcodeproj > Classes > bridge.hとbridge.m
titletest.xcodeproj > Sources > main.mとYourApp(後々出てきます。)
titletest.xcodeproj > Resources
titletest.xcodeproj > Frameworks
titletest.xcodeproj > Products

まず先程の、エラーコード①〜⑤がmain.m由来であることが分かりました。
(①については少し怪しいです...)
次に③と⑥に着目しました。
エラー内容2020-12-06 21:08:28.898615+0900 newapp[93490:1586839] Running main.py: (null)③
③ NSLog(@"Running main.py: %s", prog);
⑥ const char * prog = [
⑥ [[NSBundle mainBundle] pathForResource:@"YourApp/main" ofType:MAIN_EXT]

エラー内容と③を比較すると、%sのところに、(null)が代入されて、出力されていると推測しました。
→ %sは他に見当たらないので、progが関係していると思いました。
→ progが⑥にあることと、出力されるエラー②〜⑤の全てに@があることから、@の後が怪しいと思いました。
→ @"YourApp/main"のYourAppは、以下の場所にありました。

titletest.xcodeproj > Sources > main.mとYourApp

そして、YourAppの中身は空でした。
確かにnullだと思い、main.pyを作成しました。構造は次の様になります。
titletest.xcodeproj > Sources > YourApp > main.py

Runボタンを押したのですが、押すとmain.pyが消えます。

titletest.xcodeproj > Sources > main.pyの場合は消えません。
(この場合は、YourAppにmain.pyは無いので(null)となってしまいます。)

Runボタンを押す
titletest.xcodeproj > Sources > YourApp > main.pyが消える
%s = prog = @"YourApp/main" = nullとなる。
consoleに出力:2020-12-06 21:08:28.898615+0900 newapp[93490:1586839] Running main.py: (null)③

⑦のpycをpyにすると良いというサイトがあったので試しましたが、変化はありませんでした。

以下、main.mの全文です。
左側に①〜⑦を記載しています。

Python

1// 2// main.m 3// titletest 4// 5 6#import <Foundation/Foundation.h> 7#import <UIKit/UIKit.h> 8#include "Python.h" 9#include "/Users/satoshi/Desktop/128/kivy-ios/dist/include/common/sdl2/SDL_main.h" 10#include <dlfcn.h> 11 12void export_orientation(); 13void load_custom_builtin_importer(); 14 15int main(int argc, char *argv[]) { 16 int ret = 0; 17 18 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 19 20 // Change the executing path to YourApp 21 chdir("YourApp"); 22 23 // Special environment to prefer .pyo, and don't write bytecode if .py are found 24 // because the process will not have a write attribute on the device. 25 putenv("PYTHONOPTIMIZE=2"); 26 putenv("PYTHONDONTWRITEBYTECODE=1"); 27 putenv("PYTHONNOUSERSITE=1"); 28 putenv("PYTHONPATH=."); 29 putenv("PYTHONUNBUFFERED=1"); 30 putenv("LC_CTYPE=UTF-8"); 31 // putenv("PYTHONVERBOSE=1"); 32 // putenv("PYOBJUS_DEBUG=1"); 33 34 // Kivy environment to prefer some implementation on iOS platform 35 putenv("KIVY_BUILD=ios"); 36 putenv("KIVY_NO_CONFIG=1"); 37 putenv("KIVY_NO_FILELOG=1"); 38 putenv("KIVY_WINDOW=sdl2"); 39 putenv("KIVY_IMAGE=imageio,tex,gif"); 40 putenv("KIVY_AUDIO=sdl2"); 41 putenv("KIVY_GL_BACKEND=sdl2"); 42 43 // IOS_IS_WINDOWED=True disables fullscreen and then statusbar is shown 44 putenv("IOS_IS_WINDOWED=False"); 45 46 #ifndef DEBUG 47 putenv("KIVY_NO_CONSOLELOG=1"); 48 #endif 49 50 // Export orientation preferences for Kivy 51 export_orientation(); 52 53 NSString * resourcePath = [[NSBundle mainBundle] resourcePath]; 54 NSString *python_home = [NSString stringWithFormat:@"PYTHONHOME=%@", resourcePath, nil]; 55 putenv((char *)[python_home UTF8String]); 56 57 NSString *python_path = [NSString stringWithFormat:@"PYTHONPATH=%@:%@/lib/python3.8/:%@/lib/python3.8/site-packages:.", resourcePath, resourcePath, resourcePath, nil]; 58 putenv((char *)[python_path UTF8String]); 59 60 NSString *tmp_path = [NSString stringWithFormat:@"TMP=%@/tmp", resourcePath, nil]; 61 putenv((char *)[tmp_path UTF8String]); 62 63② NSLog(@"Initializing python"); 64 Py_Initialize(); 65 66 wchar_t** python_argv = PyMem_RawMalloc(sizeof(wchar_t *) *argc); 67 for (int i = 0; i < argc; i++) 68 python_argv[i] = Py_DecodeLocale(argv[i], NULL); 69 PySys_SetArgv(argc, python_argv); 70 71 // If other modules are using the thread, we need to initialize them before. 72 PyEval_InitThreads(); 73 74 // Add an importer for builtin modules 75 load_custom_builtin_importer(); 76 77 // Search and start main.py 78#define MAIN_EXT @"pyc" 79 80⑥ const char * prog = [ 81[[NSBundle mainBundle] pathForResource:@"YourApp/main" ofType:MAIN_EXT] cStringUsingEncoding: 82 NSUTF8StringEncoding]; 83③ NSLog(@"Running main.py: %s", prog); 84 FILE* fd = fopen(prog, "r"); 85 if ( fd == NULL ) { 86 ret = 1; 87④ NSLog(@"Unable to open main.py, abort."); 88 } else { 89 ret = PyRun_SimpleFileEx(fd, prog, 1); 90 if (ret != 0) 91 NSLog(@"Application quit abnormally!"); 92 } 93 94 Py_Finalize(); 95⑤ NSLog(@"Leaving"); 96 97 [pool release]; 98 99 // Look like the app still runs even when we left here. 100 exit(ret); 101 return ret; 102} 103 104// This method reads the available orientations from the Info.plist file and 105// shares them via an environment variable. Kivy will automatically set the 106// orientation according to this environment value, if it exists. To restrict 107// the allowed orientation, please see the comments inside. 108void export_orientation() { 109 NSDictionary *info = [[NSBundle mainBundle] infoDictionary]; 110 NSArray *orientations = [info objectForKey:@"UISupportedInterfaceOrientations"]; 111 112 // Orientation restrictions 113 // ======================== 114 // Comment or uncomment blocks 1-3 in order the limit orientation support 115 116 // 1. Landscape only 117 // NSString *result = [[NSString alloc] ①initWithString:@"KIVY_ORIENTATION=LandscapeLeft LandscapeRight"]; 118 119 // 2. Portrait only 120// NSString *result = [[NSString alloc] initWithString:@"KIVY_ORIENTATION=Portrait PortraitUpsideDown"]; 121 122 // 3. All orientations 123① NSString *result = [[NSString alloc] initWithString:@"KIVY_ORIENTATION="]; 124 for (int i = 0; i < [orientations count]; i++) { 125 NSString *item = [orientations objectAtIndex:i]; 126 item = [item substringFromIndex:22]; 127 if (i > 0) 128 result = [result stringByAppendingString:@" "]; 129 result = [result stringByAppendingString:item]; 130 } 131 // ======================== 132 133 putenv((char *)[result UTF8String]); 134→→→→ NSLog(@"Available orientation: %@", result); 135} 136 137void load_custom_builtin_importer() { 138 static const char *custom_builtin_importer = \ 139 "import sys, imp, types\n" \ 140 "from os import environ\n" \ 141 "from os.path import exists, join\n" \ 142  //中略 143 PyRun_SimpleString(custom_builtin_importer); 144}

違和感について

「この質問に関係あるのか」すら分かっていないのですが、記載いたします。(一部抜粋)

kivy-ios % toolchain recipes ios master itsdangerous master jinja2 master kivent_core master kivy 067064c23a275187e67f1c9d7de7cc06f384af4d libcurl 7.65.3 libffi 3.2.1 libjpeg v9a sdl2 7cc4fc886d9e sdl2_image 2.0.4 sdl2_mixer 2.0.4 sdl2_ttf 2.0.14 werkzeug master zbarlight 1.2

kivy の値が見るからに変なのですが、何に影響するのかよく分からない状況です。

欠けている情報があれば、もってきます。
何かご存知の方がいらっしゃれば、ご回答をよろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問