I am trying to deploy a django application with AWS Elastic Beanstalk, however it is not clear to me, how to use the installed Anaconda packages.
I have successfully installed my conda packages using the .config within .ebextensions, however I don't know how to serve them to my django app.
I've tried adding them to a .pth file, but still got no module error.
files:
"/var/app/venv/*/lib/python3.7/site-packages/conda.pth":
mode: "000644"
owner: root
group: root
content: |
/miniconda3/lib/python3.7/site-packages
If you have any link where I can read about, would be appreciated. Thank you
Related
I would like to deploy my django project to AWS Elastic Beanstalk. My project was not create through eb-virt. Do I need to redo the project again in eb-virt? I have no idea of how to deploy my project directly.
It is always recommended to work on a virtual environment. it is important because you can have your very own python environment with all the modules you need for the app installed. The good news is that it's not yet late to create the virtual environment.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html
to setup the project
goto your folder
create the virtual environment using virtualenv ~/eb-virt
activate the virtual environment source ~/eb-virt/bin/activate
install django pip install django==2.1.1
create the requirements.txt file by running pip freeze > requirements.txt. because elasticbeanstalk can install the dependecies mentioned in this file.
do the 3rd to 5th steps from the link above
to deploy
follow the deploy section, basically
init the project eb init -p python-3.6 django-tutorial
create an environment eb create django-env, we used to have Dev, staging and production environments
continue steps 4th to 7th
Good day.
I'm a newbie to Django and I have a slight confusion:
When deploying my Django app, do I need to deploy it with all the Python 'come-with' modules, or the hosts already have them installed.
Also, I installed PIL for image manipulation. Would they also have it installed or i have to find a way to install it on their servers. Thanks in advance
do I need to deploy it with all the Python 'come-with' modules
Never do that. It might conflict with the dependencies on the server. Instead issue the following command to create a dependency file (requirements.txt).
pip freeze > requirements.txt (issue this command where manage.py is located)
On the server create a new virtual environment. Now copy django project to the server (you can do this using git clone or just plain old Filezilla). Activate virtual environment. Then change you current working directory to the where manage.py is located. to install all the dependencies issue the following command.
pip install -r requirements.txt
This will install the required dependencies on on server.
I have an django project (RESTful API written using Django Rest Framework) which uses the Postgres database.
I have a local git repository of the project and also I have it on my github account, and I want to deploy the porject to heroku.
In the official heroku tutorials, they don't show anything about how to prepare your app to deployment - (requirements file, settings file, Proc File, maybe more stuff that I don't know - which I saw in different tutorials that you need to do).
At the moment I only have the django app without any added file.
My question is - what do I need to do to prepare my app to deployment to heroku? as I said at the moment I have a local git repository and its also on Github.
Thanks!
1) Create a file called Procfile (no extension) in your project root with the following inside:
web: gunicorn APP_NAME.wsgi (replace APP_NAME with your app's name).
2) Pip install gunicorn and dj-database-url
3) In your virtual env terminal, run pip freeze > requirements.txt in your project root (do this every time you pip install any new packages).
4) In your production settings file, add the following to make your database work on heroku:
import dj_database_url
DATABASES['default'] = dj_database_url.config()
Note: This will cause errors in your local environment, so make sure you have a prod.py settings file as well (ask if you need an explanation).
5) Add heroku to your git settings via git remote add heroku git#heroku.com:HEROKU_APP_NAME.git (replace HEROKU_APP_NAME with your Heroku app name).
6) Once you do git add --all, git commit -m "SOME MESSAGE HERE" and git push, you can do git push heroku master.
I have a working Django application in my local machine. I tried hosting this application in Openshift, after following the Openshift official tutorial didn't get any results. Is there any proper resource to deploy local Django applications to openshift
On Openshift you can deploy Django applications using either the Django cartridge or the Python cartridge. Using the Python cartridge is often preferred as it enables you to easily install the latest version of Django using pip.
Are you using the Django or Python cartridge?
To use the Python cartridge you can follow this tutorial:
https://developers.openshift.com/en/python-getting-started.html
You mention that you already have a django application on your local machine. It can be a bit tricky to push an existing project to openshift.
If you create the application using the Python cartridge it will create a git repository for you that you then clone onto your computer. Using the website find the URI for your application repository. You should clone this onto your computer into a separate directory from your existing django project. Look into this new repository and copy the files from that repository into your existing repository. Then you can look at the remote location used in this new repository and set it as a remote in your existing django repository. Then from your existing repository push to the openshift remote using the --force flag.
$ cd /home/user
$ git clone ssh://<user_id_string>#python-yourdomain.rhcloud.com/~/git/python.git/
$ cd python
$ tree . # look at the files in the repository (wsgi.py, etc.)
$ <copy the needed files to your django dir>
$ cd ../<existing_django_dir>
$ git remote add openshift ssh://<user_id_string>#python-yourdomain.rhcloud.com/~/git/python.git/
$ git push -f openshift master
Directions on force push: Force "git push" to overwrite remote files
I have already developed an application with Python Django and it's working, I am new to Python Django and now I need to deploy it on heroku servers, there are so many blogs and websites including heroku site that explains deploying a django app on heroku from scratch I haven't found any which talks about a running app
for example all of them need installing django which makes me confused,
this is the folder structure of my app:
myapp
|_my_app
| |_Settingd.py
| |_urls.py
| |_wsgi.py
|__webapp
|_statics(folder)
|_admin.py
|_models.py
|_views.py
The app is connecting to mysql server locally
Question(s):
Now I am totally confused, how do I have to deploy my running app on heroku? among the steps to deploy an app on heroku provided below which ones are mandatory for me and which ones I can escape and according to my folder structure where should be the location of requirements.txt or Procfile and what should be the content of them?
https://devcenter.heroku.com/articles/getting-started-with-django
Do I have to install virtualenv? and yes where should I run this command(in which folder)
I think I don't have to install django or any database api or driver for django? since they are all already installed
So the first question of yours is why the app should be running inside Virtualenv?
what's the first step? Install Django, right? Not quite. One common problem with installing packages directly to your current site-packages area is that, if you have more than one project or use Python on your machine for things other than Django, you may run into dependency issues between your applications and the installed packages. For this reason, we'll be using virtualenv to manage our Django installation. This is common, and recommended, practice among Python and Django users.
Then install and activate your virtualenv using this command...
$ virtualenv env
$ source env/bin/activate
And finally we activated the environment. Now it'll look like this
(env)rs#rajasimon-desktop:~/studio/Project$
Then i guess your second doubt what is the purpose to install django-toolbelt ?
If you are installing django-toolbelt it will install all the dependencies or package need.
it contains Django, psycopg2, gunicorn, dj-database-url, dj-static, static
Firstly Heroku natively uses postgres. Life will be easier for you if you use that locally.
If you really want to use mysql, you have two paths to follow.
1) Run mysql locally, but convert to postgres when migrating to Heroku using the mysql2psql gem, as described here: https://devcenter.heroku.com/articles/heroku-mysql
2) Use a mysql addon like https://addons.heroku.com/cleardb
However my recommendation would be to use postgres end to end, as it is baked into Heroku, and you'll be working with the default ways of using Heroku, not against the
This is my project package i am currenlty working
(env)ri#rajasimon-desktop:~/studio/project$ pip freeze
Django==1.6.5
MySQL-python==1.2.5
Pillow==2.5.3
argparse==1.2.1
django-ckeditor-updated==4.2.8
wsgiref==0.1.2
where should be the location of requirements.txt & Procfile ?
How to make requirements.txt file ?
By running below command will automatically include all packages inside txt file.
pip freeze > requirements.txt
Declare process type with Procfile
The procfile is for starting the dyno when in productioin. I always right like this..
web: gunicorn project.wsgi
So finally your project structure will look like this
myapp
|_my_app
| |_Settingd.py
| |_urls.py
| |_wsgi.py
|__webapp
| |_statics(folder)
| |_admin.py
| |_models.py
| |_views.py
|__manage.py
|__requirements.txt
|__Procfile