How to deploy python modules on Heroku?

PythonServer Side ProgrammingProgramming

<p style="">Assuming you have set up Python 3.6, Pipenv and heroku CLI installed locally and are logged in on Heroku from the CLI using the steps mentioned here: <a href="https://devcenter.heroku.com/articles/getting-started-with-python#set-up" rel="nofollow noopener noreferrer" target="_blank">https://devcenter.heroku.com/articles/getting-started-with-python#set-up.</a></p><p>Your application needs to have a git repository to be deployed to heroku. You need to cd in the directory where the root of your git repo code resides. Now you need to create a heroku application using:</p><pre class="prettyprint notranslate">$ heroku create Creating lit-bastion-5032 in organization heroku... done, stack is cedar-14</pre><p><a href="http://lit-bastion-5032.herokuapp.com/" rel="nofollow" target="_blank">http://lit-bastion-5032.herokuapp.com/</a> | <a href="https://git.heroku.com/lit-bastion-5032.git" rel="nofollow" target="_blank">https://git.heroku.com/lit-bastion-5032.git</a></p><p>Git remote heroku added</p><p>When you create an app, a git remote (called heroku) is also created and associated with your local git repository. Heroku generates a random name (in this case lit-bastion-5032) for your app, or you can pass a parameter to specify your own app name.</p><p>Now that a remote has been added, you can push your code to heroku using:</p><pre class="prettyprint notranslate">$ 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: -----&gt; Python app detected remote: -----&gt; Installing python-3.6.0 remote: -----&gt; Installing requirements with latest pipenv... remote: &nbsp; &nbsp; &nbsp; &nbsp;Installing dependencies from Pipfile.lock... remote: &nbsp; &nbsp; &nbsp;$ python manage.py collectstatic --noinput remote: &nbsp; &nbsp; &nbsp; &nbsp;58 static files copied to &#39;/app/gettingstarted/staticfiles&#39;, 58 post-processed. remote: remote: -----&gt; Discovering process types remote: &nbsp; &nbsp; &nbsp; &nbsp;Procfile declares types -&gt; web remote: remote: -----&gt; Compressing... remote: &nbsp; &nbsp; &nbsp; &nbsp;Done: 39.3M remote: -----&gt; Launching... remote: &nbsp; &nbsp; &nbsp; &nbsp;Released v4 remote: &nbsp; &nbsp; &nbsp; &nbsp;<a href="http://lit-bastion-5032.herokuapp.com/" rel="nofollow" target="_blank">http://lit-bastion-5032.herokuapp.com/</a> deployed to Heroku remote: remote: Verifying deploy... done. To git@heroku.com:lit-bastion-5032.git &nbsp;* [new branch] &nbsp; &nbsp; &nbsp;master -&gt; 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</pre><p>You can read more about this on the heroku python docs: <a href="https://devcenter.heroku.com/articles/python-pip" rel="nofollow" target="_blank">https://devcenter.heroku.com/articles/python-pip</a></p>
raja
Updated on 15-Jun-2020 07:42:32

Advertisements