AI×医療事務(カナダ)

今は医療事務しているので医療事務関連、IT関連をのんびりと備忘録も含め記載していきます カナダ・歯科助手のことも復習がてら記載中 

flask Heroku エラー内容がほぼ(途中?)

はじめに

今作成中のflaskアプリをとりあえず 上げるためにHerokuへのデプロイを行いたいと思い、備忘録も兼ねて今回記事を書きました

 

参考サイト

 

[Python] プログラム初心者のためのWebアプリ簡単作成法

 

- Qiita

Herokuのapp作成手順(buildpack-multiを使う場合も含む) - Qiita

Herokuへのデプロイ方法【Heroku+Rails+MySQL】 - Qiita

 環境:

Git管理

コマンドライン上で、作成したプロジェクトのディレクトリに移動

cd  ◎◎

以下をコマンドを実行すると、プロジェクトがGitで管理(1個ずつしないと作動しない)

git init


Initialized empty Git repository in /◎◎/◎◎/flask/flask2/.git/

git add . 

何も出ない

git commit -m "<適当なコミットメッセージ>"

(おそらく今現在 位置するディレクトリ内にあるディレクトリ、ファイル等の名前が表示される)

[master (root-commit) (英数字)] <適当なコミットメッセージ>

0 files changed, 462 insertions(+)
 create mode 100644 css/style.css
 create mode 100644 flask.py
 create mode 100644 main.py
 create mode 100644 static/javascript/sample2.js
 create mode 100644 static/javascript/sample.js
 create mode 100644 templates/form.html
 create mode 100644 templates/index.html
 create mode 100644 templates/index2.html
 create mode 100644 templates/layout.html
 create mode 100644 test.py

または

[master 43b15f] newsample
 1 file changed, 1 insertion(+)
 create mode 100644 runtime.txt

git log

commit (英数字の羅列  おそらくgitのIDかなにか) (HEAD -> master)
Author: Sample <herokuにて登録しているメールアドレス>❗
Date:   Fri Jun 17 19:28:48 2022 +0900

 

またはcommit (英数字の羅列  おそらくgitのIDかなにか) (HEAD -> master)
Author: Sample <herokuにて登録しているメールアドレス>
Date:   Fri Jun 17 20:59:02 2022 +0900

    newsample

commit (英数字の羅列  おそらくgitのIDかなにか) (HEAD -> master)
Author: Sample <herokuにて登録しているメールアドレス>
Date:   Fri Jun 17 19:28:48 2022 +0900

    <適当なコミットメッセージ>
(END)

Herokuのアカウント作成

https://jp.heroku.com/

Herokuのtoolbelt    インストール

https://devcenter.heroku.com/articles/heroku-cli

MACコマンドラインにて  

brew tap heroku/brew && brew install heroku

を実行

コマンドライン上でherokuコマンドが使えるようになる

brew tap heroku/brew && brew install heroku

Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).

You have 29 outdated formulae installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

To link this version, run:
  brew link heroku

 

Herokuのバージョンを確認

heroku -v

heroku/7.53.0 darwin-x64 node-v12.21.0

 

SSHキー

SSH キーの管理 | Heroku Dev Center

  

ssh-keygen -t rsa

実行


Generating public/private rsa key pair.
Enter file in which to save the key (/Users/◎◎/.ssh/id_rsa):         
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/◎◎/.ssh/id_rsa.
Your public key has been saved in /Users/◎◎/.ssh/id_rsa.pub.
The key fingerprint is:
(英数字の羅列+++++++++++++++++++++++)
The key's randomart image is:
+---[英数字でなにか]----+
|英語と記号の羅列 が何行か|
|英語と記号の羅列  |

|英語と記号の羅列  |

|英語と記号の羅列  |

|英語と記号の羅列  |
+----[英数字でなにか]-----+

 

作成したHerokuアカウントにキーを追加

herokuにログイン

heroku login
SSHキーがherokuのアカウントに追加
heroku keys:add ~/.ssh/id_rsa.pub
 実行
(どのようなディレクトリに入っているとしても上記で実行される)

Uploading /◎◎/◎◎/.ssh/id_rsa.pub SSH key... done

 

追加に成功していれば、以下のコマンドで追加したSSHキーが確認

heroku keys

 実行


 (登録しているメールアドレス ❗現在のもの❗) keys
(英数字と記号の羅列)= (use名)@(PCの機種).local

 

(違うアカウントやE-mailが出た場合)

(directory : ~/.git/config)

git config --global user.name 'Your Name' git config 
--global user.email '<your_email>'

(何も出ないが他Herokuアカウントが追加される)

Herokuにアプリケーション を作成

コマンドライン上で、プロジェクトのディレクトリに移動

cd ◎◎

Herokuにアプリケーションを作成

(※Herokuのアプリ名には英数字とハイフンしか使えない。)

heroku apps:create  ** (Herokuのアプリ名。英数字とハイフンのみ)

(Creating ⬢ flask1... !)
( ▸    Name flask1 is already taken ) →※この意味はすでに使われているという意味

                    そのためまだ作れていない     

Creating ⬢ (Herokuのアプリ名)... done
https://(Herokuのアプリ名).herokuapp.com/ | https://git.heroku.com/(Herokuのアプリ名).git

 

 

Herokuのリモートリポジトリを確認

git remote -v

heroku  https://git.heroku.com/newsample.git (fetch)
heroku  https://git.heroku.com/newsample.git (push)
origin  https://github.com/(Gitのアカウント名)/flask2.git (fetch)
origin  https://github.com/(Gitのアカウント名)/flask2.git (push)

 

 

=========

Herokuのアプリケーション名変更

git:remote -a sampleflask1    

›   Error: Couldn't find that app.
 ›
 ›   Error ID: not_found

===========

 

 

Herokuへデプロイ

 

ローカルリポジトリをHerokuへpush

git push heroku master(main)

(※master以外のローカルブランチをpushする場合は、以下のコマンドを実行)

git push heroku <ブランチ名>:master

今現在のpythonのver ⇛Python 3.8.5 (default, Sep  4 2020, 02:22:02) 

 

Counting objects: 26, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (26/26), 9.40 KiB | 283.00 KiB/s, done.
Total 26 (delta 2), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Python app detected
remote: -----> Using Python version specified in runtime.txt
remote:  !     Python has released a security update! Please consider upgrading to python-3.8.13
remote:        Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.8.5
remote: -----> Installing pip 22.1.2, setuptools 60.10.0 and wheel 0.37.1
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote:        Collecting absl-py==0.9.0
remote:          Downloading absl-py-0.9.0.tar.gz (104 kB)
remote:          Preparing metadata (setup.py): started
remote:          Preparing metadata (setup.py): finished with status 'done'
remote:        Collecting astor==0.8.1
remote:          Downloading astor-0.8.1-py2.py3-none-any.whl (27 kB)
remote:        Collecting bleach==3.1.5
remote:          Downloading bleach-3.1.5-py2.py3-none-any.whl (151 kB)
remote:        Collecting bottle==0.12.18
remote:          Downloading bottle-0.12.18-py3-none-any.whl (89 kB)
remote:        Collecting click==7.1.2
remote:          Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
remote:        Collecting certifi==2020.6.20
remote:          Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
remote:        Collecting chardet==3.0.4
remote:          Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
remote:        Collecting flask==2.0.1
remote:          Downloading Flask-2.0.1-py3-none-any.whl (94 kB)
remote:        Collecting future==0.18.2
remote:          Downloading future-0.18.2.tar.gz (829 kB)
remote:          Preparing metadata (setup.py): started
remote:          Preparing metadata (setup.py): finished with status 'done'
remote:        Collecting gast==0.3.3
remote:          Downloading gast-0.3.3-py2.py3-none-any.whl (9.7 kB)
remote:        Collecting grpcio==1.31.0
remote:          Downloading grpcio-1.31.0-cp38-cp38-manylinux2014_x86_64.whl (3.4 MB)
remote:        Collecting gunicorn==20.0.4
remote:          Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
remote:        Collecting h5py==2.10.0
remote:          Downloading h5py-2.10.0-cp38-cp38-manylinux1_x86_64.whl (2.9 MB)
remote:        Collecting html5lib==1.1
remote:          Downloading html5lib-1.1-py2.py3-none-any.whl (112 kB)
remote:        Collecting itsdangerous==2.0
remote:          Downloading itsdangerous-2.0.0-py3-none-any.whl (18 kB)
remote:        Collecting idna==2.10
remote:          Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
remote:        Collecting Jinja2==3.0.1
remote:          Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
remote:        Collecting line-bot-sdk==1.16.0
remote:          Downloading line_bot_sdk-1.16.0-py2.py3-none-any.whl (59 kB)
remote:        Collecting Markdown==3.2.2
remote:          Downloading Markdown-3.2.2-py3-none-any.whl (88 kB)
remote:        Collecting MarkupSafe==2.0
remote:          Downloading MarkupSafe-2.0.0-cp38-cp38-manylinux2010_x86_64.whl (30 kB)
remote:        Collecting numpy==1.18.0
remote:          Downloading numpy-1.18.0-cp38-cp38-manylinux1_x86_64.whl (20.6 MB)
remote:        Collecting oauthlib==3.1.0
remote:          Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
remote:        Collecting pillow==7.2.0
remote:          Downloading Pillow-7.2.0-cp38-cp38-manylinux1_x86_64.whl (2.2 MB)
remote:        Collecting protobuf==3.12.4
remote:          Downloading protobuf-3.12.4-cp38-cp38-manylinux1_x86_64.whl (1.3 MB)
remote:        Collecting PyYAML==5.4.1
remote:          Downloading PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl (662 kB)
remote:        Collecting python-dotenv==0.14.0
remote:          Downloading python_dotenv-0.14.0-py2.py3-none-any.whl (17 kB)
remote:        Collecting requests==2.25.1
remote:          Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
remote:        Collecting scipy==1.4.1
remote:          Downloading scipy-1.4.1-cp38-cp38-manylinux1_x86_64.whl (26.0 MB)
remote:        Collecting six==1.15.0
remote:          Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
remote:        Collecting tensorboard==2.3.0
remote:          Downloading tensorboard-2.3.0-py3-none-any.whl (6.8 MB)
remote:        Collecting tensorflow-cpu==2.3.0
remote:          Downloading tensorflow_cpu-2.3.0-cp38-cp38-manylinux2010_x86_64.whl (137.4 MB)
remote:        Collecting termcolor==1.1.0
remote:          Downloading termcolor-1.1.0.tar.gz (3.9 kB)
remote:          Preparing metadata (setup.py): started
remote:          Preparing metadata (setup.py): finished with status 'done'
remote:        Collecting urllib3==1.26.5
remote:          Downloading urllib3-1.26.5-py2.py3-none-any.whl (138 kB)
remote:        Collecting Werkzeug==2.0.0
remote:          Downloading Werkzeug-2.0.0-py3-none-any.whl (288 kB)
remote:        Collecting packaging
remote:          Downloading packaging-21.3-py3-none-any.whl (40 kB)
remote:        Collecting webencodings
remote:          Downloading webencodings-0.5.1-py2.py3-none-any.whl (11 kB)
remote:        Collecting tensorboard-plugin-wit>=1.6.0
remote:          Downloading tensorboard_plugin_wit-1.8.1-py3-none-any.whl (781 kB)
remote:        Collecting google-auth<2,>=1.6.3
remote:          Downloading google_auth-1.35.0-py2.py3-none-any.whl (152 kB)
remote:        Collecting google-auth-oauthlib<0.5,>=0.4.1
remote:          Downloading google_auth_oauthlib-0.4.6-py2.py3-none-any.whl (18 kB)
remote:        Collecting tensorflow-estimator<2.4.0,>=2.3.0
remote:          Downloading tensorflow_estimator-2.3.0-py2.py3-none-any.whl (459 kB)
remote:        Collecting wrapt>=1.11.1
remote:          Downloading wrapt-1.14.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81 kB)
remote:        Collecting google-pasta>=0.1.8
remote:          Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
remote:        Collecting opt-einsum>=2.3.2
remote:          Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
remote:        Collecting keras-preprocessing<1.2,>=1.1.1
remote:          Downloading Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
remote:        Collecting astunparse==1.6.3
remote:          Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
remote:        Collecting pyasn1-modules>=0.2.1
remote:          Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
remote:        Collecting rsa<5,>=3.1.4
remote:          Downloading rsa-4.8-py3-none-any.whl (39 kB)
remote:        Collecting cachetools<5.0,>=2.0.0
remote:          Downloading cachetools-4.2.4-py3-none-any.whl (10 kB)
remote:        Collecting requests-oauthlib>=0.7.0
remote:          Downloading requests_oauthlib-1.3.1-py2.py3-none-any.whl (23 kB)
remote:        Collecting pyparsing!=3.0.5,>=2.0.2
remote:          Downloading pyparsing-3.0.9-py3-none-any.whl (98 kB)
remote:        Collecting pyasn1<0.5.0,>=0.4.6
remote:          Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
remote:        Building wheels for collected packages: absl-py, future, termcolor
remote:          Building wheel for absl-py (setup.py): started
remote:          Building wheel for absl-py (setup.py): finished with status 'done'
remote:          Created wheel for absl-py: filename=absl_py-0.9.0-py3-none-any.whl size=121939 sha256=28e42f7ac416ae3cdb1b7baf75c41647b007b5761703273c73b034d9806be73b
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-nw5e4f9c/wheels/1d/10/8e/2f79b924179ff1e6510933d63eb851bea01054fff262343b7a
remote:          Building wheel for future (setup.py): started
remote:          Building wheel for future (setup.py): finished with status 'done'
remote:          Created wheel for future: filename=future-0.18.2-py3-none-any.whl size=491070 sha256=a6907538bffc20ab8b8167ca380437922a7c8eb58c64125d802046ce5ee3b35e
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-nw5e4f9c/wheels/8e/70/28/3d6ccd6e315f65f245da085482a2e1c7d14b90b30f239e2cf4
remote:          Building wheel for termcolor (setup.py): started
remote:          Building wheel for termcolor (setup.py): finished with status 'done'
remote:          Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=4848 sha256=60791da2a76c3b8f01238054e2602f5c38d4a788022003ba8000f2b37d9500fb
remote:          Stored in directory: /tmp/pip-ephem-wheel-cache-nw5e4f9c/wheels/a0/16/9c/5473df82468f958445479c59e784896fa24f4a5fc024b0f501
remote:        Successfully built absl-py future termcolor
remote:        Installing collected packages: webencodings, termcolor, tensorflow-estimator, tensorboard-plugin-wit, python-dotenv, pyasn1, chardet, certifi, bottle, wrapt, Werkzeug, urllib3, six, rsa, PyYAML, pyparsing, pyasn1-modules, pillow, oauthlib, numpy, MarkupSafe, Markdown, itsdangerous, idna, gunicorn, gast, future, click, cachetools, astor, scipy, requests, protobuf, packaging, opt-einsum, keras-preprocessing, Jinja2, html5lib, h5py, grpcio, google-pasta, google-auth, astunparse, absl-py, requests-oauthlib, line-bot-sdk, flask, bleach, google-auth-oauthlib, tensorboard, tensorflow-cpu
remote:        Successfully installed Jinja2-3.0.1 Markdown-3.2.2 MarkupSafe-2.0.0 PyYAML-5.4.1 Werkzeug-2.0.0 absl-py-0.9.0 astor-0.8.1 astunparse-1.6.3 bleach-3.1.5 bottle-0.12.18 cachetools-4.2.4 certifi-2020.6.20 chardet-3.0.4 click-7.1.2 flask-2.0.1 future-0.18.2 gast-0.3.3 google-auth-1.35.0 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.31.0 gunicorn-20.0.4 h5py-2.10.0 html5lib-1.1 idna-2.10 itsdangerous-2.0.0 keras-preprocessing-1.1.2 line-bot-sdk-1.16.0 numpy-1.18.0 oauthlib-3.1.0 opt-einsum-3.3.0 packaging-21.3 pillow-7.2.0 protobuf-3.12.4 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyparsing-3.0.9 python-dotenv-0.14.0 requests-2.25.1 requests-oauthlib-1.3.1 rsa-4.8 scipy-1.4.1 six-1.15.0 tensorboard-2.3.0 tensorboard-plugin-wit-1.8.1 tensorflow-cpu-2.3.0 tensorflow-estimator-2.3.0 termcolor-1.1.0 urllib3-1.26.5 webencodings-0.5.1 wrapt-1.14.1
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 257.9M
remote: -----> Launching...
remote:        Released v3
remote:        https://clinic-checker.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/clinic-checker.git
 * [new branch]      master -> master

アプリケーションにアクセス

heroku open

 

(Homebrew をアップデート)

brew update

 

(python をアップデート)

brew upgrade python3

 

アプリを実行  上手く行けばアプリが出る

heroku open

 

<<私のコード自体が パスが相対パスだったりエラーが有ったのと そもそもHerokuは使わないほうが良かったので一旦ここまで>

================

エラー1:

fatal: Not a git repository (or any of the parent directories): .git

 

エラー2;

remote: !       Your account(Herokuの登録しているメールアドレス) does not have access to newsample.
fatal: unable to access 'https://git.heroku.com/newsample.git/': The requested URL returned error: 403

 

git push heroku master をすると403エラーが発生する - スタック・オーバーフロー

 

エラー3; 

error: failed to push some refs to 'https://git.heroku.com/clinic-checker.git'

 

**

Counting objects: 26, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (20/20), done.

Writing objects: 100% (26/26), 9.40 KiB | 137.00 KiB/s, done.

Total 26 (delta 2), reused 0 (delta 0)

remote: Compressing source files... done.

remote: Building source:

remote:

remote: -----> Building on the Heroku-22 stack

remote: -----> Using buildpack: heroku/python

remote: -----> Python app detected

remote: -----> Using Python version specified in runtime.txt

remote: ! Requested runtime (python-3.8.5) is not available for this stack (heroku-22).

remote: ! Aborting. More info: https://devcenter.heroku.com/articles/python-support

remote: ! Push rejected, failed to compile Python app.

remote:

remote: ! Push failed

remote: !

remote: ! ## Warning - The same version of this code has already been built: 4309db9e87801c563af9e7776c083d43d6561fc3

remote: !

remote: ! We have detected that you have triggered a build from source code with version 4309db9e87801c563af9e7776c083d43d6561fc3

remote: ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.

remote: !

remote: ! If you are developing on a branch and deploying via git you must run:

remote: !

remote: ! git push heroku <branchname>:main

remote: !

remote: ! This article goes into details on the behavior:

remote: ! https://devcenter.heroku.com/articles/duplicate-build-version

remote:

remote: Verifying deploy...

remote:

remote: ! Push rejected to clinic-checker.

remote:

To https://git.heroku.com/clinic-checker.git

! [remote rejected] master -> master (pre-receive hook declined)

error: failed to push some refs to 'https://git.heroku.com/clinic-checker.git'

**

heroku のアップグレードをしたので 

Anaconda内のpythonのverが合っていなかった

(   Heroku Python Support | Heroku Dev Center)


しかしAnacondaのアップグレードがとても時間がかかったので下記URLを実行

Anaconda navigatorのアップデートが終わらないときの対処方法メモ

MACの場合、Command + スペース キーにて Spotlight検索を出す

 

Anacondaを起動

AnacondaNavigater   の仮想環境にて(ここではbaseにて) ▶を左クリック(右クリックにするとロード?になりしばらく触れなくなるので左クリック)

Open Terminal をクリックし Anaconda Promptを開く

 

conda update --all 

 をコマンドにて実行

にて

yを入れてエンター(リターンキー)

AnacondaPromptを閉じる

 

conda update --all 

 をコマンドにて実行

# All requested packages already installed.

 

pythonのverを該当のものをインストール

conda install python-3.10.5 



 

終了

============