close

https://devcenter.heroku.com/articles/getting-started-with-python#set-up

It may surprise you, but it's not easy to find the deployment tool on Heroku official webpage. 

 

 

 Open a console window when you finished the installation

 > heroku login

I neglected the first question about credentials because I had no idea what should I input.

Then I logged in successfully by entering my Email and Password.

 > pip install virtualenv

> virtualenv herokuenv

The system creates a new folder called "herokuenv" 

> cd herokuenv

>Scripts\activate

> pip install flask

>pip install gunicorn

>pip install requests

> pip list

(herokuenv) C:\herokuenv>cd weather

(herokuenv) C:\herokuenv\weather>pip freeze > requirements.txt

 

create a file and name it as "Procfile"

 

Input the following contents 

create runtime.txt

 

Now we are in the middle of the deployment of our application,

go to the following link and add a new app,

 https://dashboard.heroku.com/new-app

 

In this case, my own app's name is called "me1237guy", remember to change it to yours

 

(herokuenv) C:\herokuenv\weather>git init
Initialized empty Git repository in C:/herokuenv/weather/.git/

(herokuenv) C:\herokuenv\weather>heroku git:remote -a me1237guy

set git remote heroku to https://git.heroku.com/me1237guy.git

(herokuenv) C:\herokuenv\weather>git add .

 

(herokuenv) C:\herokuenv\weather>git commit -m "init commit"
[master (root-commit) 4d7491f] init commit
4 files changed, 71 insertions(+)
create mode 100644 Procfile
create mode 100644 requirements.txt
create mode 100644 runtime.txt
create mode 100644 weather.py

(herokuenv) C:\herokuenv\weather>git push heroku master

 

Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 1.34 KiB | 684.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0), pack-reused 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.7.12
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.7.9
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: Collecting certifi==2021.5.30
remote: Downloading certifi-2021.5.30-py2.py3-none-any.whl (145 kB)
remote: Collecting charset-normalizer==2.0.6
remote: Downloading charset_normalizer-2.0.6-py3-none-any.whl (37 kB)
remote: Collecting click==8.0.1
remote: Downloading click-8.0.1-py3-none-any.whl (97 kB)
remote: Collecting colorama==0.4.4
remote: Downloading colorama-0.4.4-py2.py3-none-any.whl (16 kB)
remote: Collecting Flask==2.0.1
remote: Downloading Flask-2.0.1-py3-none-any.whl (94 kB)
remote: Collecting gunicorn==20.1.0
remote: Downloading gunicorn-20.1.0-py3-none-any.whl (79 kB)
remote: Collecting idna==3.2
remote: Downloading idna-3.2-py3-none-any.whl (59 kB)
remote: Collecting itsdangerous==2.0.1
remote: Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
remote: Collecting Jinja2==3.0.1
remote: Downloading Jinja2-3.0.1-py3-none-any.whl (133 kB)
remote: Collecting MarkupSafe==2.0.1
remote: Downloading MarkupSafe-2.0.1-cp37-cp37m-manylinux2010_x86_64.whl (31 kB)
remote: Collecting requests==2.26.0
remote: Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)
remote: Collecting urllib3==1.26.7
remote: Downloading urllib3-1.26.7-py2.py3-none-any.whl (138 kB)
remote: Collecting Werkzeug==2.0.1
remote: Downloading Werkzeug-2.0.1-py3-none-any.whl (288 kB)
remote: Collecting importlib-metadata; python_version < "3.8"
remote: Downloading importlib_metadata-4.8.1-py3-none-any.whl (17 kB)
remote: Collecting typing-extensions>=3.6.4; python_version < "3.8"
remote: Downloading typing_extensions-3.10.0.2-py3-none-any.whl (26 kB)
remote: Collecting zipp>=0.5
remote: Downloading zipp-3.5.0-py3-none-any.whl (5.7 kB)
remote: Installing collected packages: certifi, charset-normalizer, typing-extensions, zipp, importlib-metadata, click, colorama, MarkupSafe, Jinja2, itsdangerous, Werkzeug, Flask, gunicorn, idna, urllib3, requests
remote: Successfully installed Flask-2.0.1 Jinja2-3.0.1 MarkupSafe-2.0.1 Werkzeug-2.0.1 certifi-2021.5.30 charset-normalizer-2.0.6 click-8.0.1 colorama-0.4.4 gunicorn-20.1.0 idna-3.2 importlib-metadata-4.8.1 itsdangerous-2.0.1 requests-2.26.0 typing-extensions-3.10.0.2 urllib3-1.26.7 zipp-3.5.0
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 53.1M
remote: -----> Launching...
remote: Released v3
remote: https://me1237guy.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/me1237guy.git
* [new branch] master -> master

 

Finally, we can test the web API that we just deployed

https://me1237guy.herokuapp.com/weather

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()