Python
 Computer >> コンピューター >  >> プログラミング >> Python

HerokuにPythonモジュールをデプロイする方法は?


Python 3.6、Pipenv、およびheroku CLIがローカルにインストールされており、https://devcenter.heroku.com/に記載されている手順を使用してCLIからHerokuにログインしていると仮定します。 articles / getting-started-with-python#set-up。

アプリケーションには、herokuにデプロイするためのgitリポジトリが必要です。 gitリポジトリコードのルートが存在するディレクトリにcdする必要があります。次に、以下を使用してherokuアプリケーションを作成する必要があります:

$ heroku create
Creating lit-bastion-5032 in organization heroku... done, stack is cedar-14

https://lit-bastion-5032.herokuapp.com/ | https://git.heroku.com/lit-bastion-5032.git

Gitリモートherokuが追加されました

アプリを作成すると、gitリモート(herokuと呼ばれる)も作成され、ローカルのgitリポジトリに関連付けられます。 Herokuは、アプリのランダムな名前(この場合はlit-bastion-5032)を生成します。または、パラメーターを渡して独自のアプリ名を指定することもできます。

リモコンが追加されたので、次を使用してコードをherokuにプッシュできます:

$ git push heroku master
Counting objects: 232, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (217/217), done.
Writing objects: 100% (232/232), 29.64 KiB | 0 bytes/s, done.
Total 232 (delta 118), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.0
remote: -----> Installing requirements with latest pipenv...
remote:        Installing dependencies from Pipfile.lock...
remote:      $ python manage.py collectstatic --noinput
remote:        58 static files copied to '/app/gettingstarted/staticfiles', 58 post-processed.
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 39.3M
remote: -----> Launching...
remote:        Released v4
remote:        https://lit-bastion-5032.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To git@heroku.com:lit-bastion-5032.git
 * [new branch]      master -> master
Note that you need to specify your requirements(third party modules you are importing) with their version numbers(or without if you need latest one) in the requirements.txt. For example,
Flask==0.8
Jinja2==2.6
Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1

これについて詳しくは、heroku pythonドキュメントをご覧ください:https://devcenter.heroku.com/articles/python-pip


  1. Python import Statementで複数のモジュールを使用するにはどうすればよいですか?

    1つのインポートステートメントで複数のモジュールをインポートするには、モジュール名をコンマで区切ります。たとえば、 >>> import math, sys, os モジュールがインポートされる名前を変更する場合は、各モジュール名の後にモジュールエイリアスを追加します。たとえば、 >>> import math as Mathematics, sys as system 文字列としてインポートするモジュールのリストがある場合は、組み込みの__import __(module_name)を使用できます。たとえば、 >>> modnames

  2. Pythonモジュールはどのように機能しますか?

    Pythonには、定義をファイルに入れて、スクリプトまたはインタープリターのインタラクティブインスタンスで使用する方法があります。このようなファイルはモジュールと呼ばれます。モジュールからの定義は、他のモジュールまたはメインモジュール(トップレベルおよび計算機モードで実行されるスクリプトでアクセスできる変数のコレクション)にインポートできます。 モジュール、たとえば `hello`をインポートすると、インタプリタは入力スクリプトを含むディレクトリでhello.pyという名前のファイルを検索し、次に環境変数PYTHONPATHで指定されたディレクトリのリストを検索します。 fibonacci