Django Twilio module is not getting installed on Heroku - django

I tried below 2 methods to install django_twilio module on Heroku
1) Ran 'heroku run pip install django-twilio'
2) Added 'twilio==3.6.3' to requirements.txt and start the server on heroku.
When I run 'heroku run pip freeze' I can see the twilio entry. But when I go into python and run 'import django_twilio' I get a module not found error.
Please suggest how to fix this on heroku. Same steps worked fine on my local machine.

You didn't add the proper requirement, you only installed the twilio library. Your requirements.txt should include the following line:
django-twilio==0.4
Which will include all the other dependencies you'll need. The full pip freeze, after installing django-twilio looks like this:
Django==1.5.5
django-twilio==0.4
httplib2==0.8
six==1.4.1
twilio==3.6.3
unittest2==0.5.1
As a rule of thumb, always run pip freeze > requirements.txt before pushing an update to Heroku (assuming new dependencies were installed), to make sure you have a complete snapshot of your environment.

Related

ModuleNotFoundError: No module named 'flask_openid' (for Python3.6)

I was trying to run a Flask project using Python 3.6.
I encountered an error:
...
from flask_openid import OpenID
ModuleNotFoundError: No module named 'flask_openid'
Flask-OpenID is available in my Python v3.5 dist-packages.
(When I run:
"sudo pip3 install Flask-OpenID", it shows
"Requirement already satisfied (use --upgrade to upgrade): Flask-OpenID in /usr/local/lib/python3.5/dist-packages" )
What should I do to install openid for Python 3.6?
The documentation states that you should import OpenID as follows:
from flask.ext.openid import OpenID
The package itself is installed correctly (in your Python3.5 environment), as shown by pip when you try to install it again:
Requirement already satisfied (use --upgrade to upgrade): Flask-OpenID in /usr/local/lib/python3.5/dist-packages
However, as you state the in your question:
I was trying to run a Flask project using Python 3.6
You might want to make sure your python3 and pip3 are actually pointing to where you want them to, e.g. on your terminal:
$ ls -l $(which pip3)
Or even better, you should really look into creating virtualenvs for your projects, it helps a lot avoiding these kinds of problems in the first place:
create a new Python 3.6 virtualenv
activate your new virtualenv
install your requirements with pip inside the virtualenv
Then run your script in this virtualenv, and you'll be sure you are using exactly the Python you want, and your dependencies are where you expect them to be (and only there, not somewhere else messing up other projects).
Now this might look like a lot of effort, but it takes no more than a couple minutes the first time you do it, will quickly become second nature, and save you a ton of headache down the road.
For me,
python3.6 -m pip install flask_openid
solved the issue.
The above command will install openid for python3.6.

confusion in deploying module's with django

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.

how to bring out django project from virtualenv

I have django project in virtualenv and now I am publishing it in server but the problem is I can not move project from virtualenv, when I do this then related packages inside site-package, cant be read and errors occur, how can I bring out my project from virtualenv without any issuing
Create a new virtualenv on the server. It's easy
Step 1 Get the list of modules in the current virtualenv
source /path/to/current/bin/activate
pip freeze > /tmp/requirements.txt
Step 2 Create a new virtualenv. Login to your new server, copy the requirements file there. Then either change into a suitable directory before excuting the virtualenv command or give a full path.
deactivate
virtualenv -p python envname
Step 3 Install modules
source envname/bin/activate
pip install -r /tmp/requirements.txt
That's it.
As #bruno has pointed out, you really should be using a virtualenv on the server. And you should be using it on your local dev server as well. Then you can be really sure that the code will run at both ends without any surprises.

How to install Django project with all modules?

I created a Django's application which use some additional modules like crispy_forms. I would like to send this application to my friends to test it.
But I don't know how can they just install it and run it? Is it possible?
Application using also database PostgreSQL.
What is the simplest way to just run this application from any place with no errors and problems on the start?
I found only information about https://docs.djangoproject.com/en/1.10/intro/reusable-apps/
and packed my app, but I don't know how to install it.
To setup env for project i would install virtualenv, then:
pip install -r requirements.txt
You need to set database connection in settings.py, or switch to sqlite3...
hope this helps!
If you are using virtual environment then activate it and go in your project root.
If you are not using virtualenvironment then do the same thing, go in your project root.
Make sure you have requirements.txt file.
run the command
pip freeze > requirements.txt
This will add automatically all your modules to requirements.txt file
which can be then installed by
pip install -r requirements.txt

deploying to heroku from local machine

I have django project running on my machine in virtualenv. Is there a way I can deploy my project on Heroku directly? I followed steps mentioned in heroku documentation but i am kind of confused with req.txt since my project already have req.txt in virtualenv. I am new to django heroku techs. Any guidance is highly appreciated.
my project already have req.txt in virtualenv
You should not have req.txt in virtualenv. You should have requirements.txt in your project repository. requirements.txt is just a list of modules that need to be installed in the virtualenv. You create and activate a new virtualenv, then you run pip install -r requirements.txt, and it installs everything you need in the virtualenv. So requirements.txt is not part of the virtualenv, it's more like a description of how to setup the virtualenv.
If this is not clear, you may find my article, virtualenv demystified, useful.
The requirements.txt file defines what python dependencies Heroku will install. Generally speaking, what you use locally will be the same as your local development machine.
If there are differences, you may opt to have an additional file locally that contains local, development-specific packages (for example django-debug-toolbar).
First you will activate your virtual environment and then go to project root and run the command
pip freeze > requirements.txt
This will automatically add all the dependencies of your local machine in requirements.txt. Once you push the file heroku will automatically detect the changes and install them.