I am trying to deploy my python web application to Heroku and I am using the postgresql database to store user information such as login credentials etc. My app has been deployed but I am trying to create the database table by running the commands
Heroku run python
from app import db
db.create_all()
However, when I run that in my terminal, I receive this error message.
ModuleNotFoundError: No module named 'psycopg2'.
I have tried to run pip install pyscopg2 and then I receive this error
Error: pg_config executable not found.
I have also ran the command pip install psycopg2-binary and receive the same error. Any explantation for how I can resolve this... Many thanks in advance
Add a file in the root directory of your project named requirements.txt with the following contents:
psycopg2
Heroku also reccommends adding a version number like so:
psycopg2==2.9.3
Learn more here: https://devcenter.heroku.com/articles/python-pip
Related
I am currently trying to deploy a Python/Django app to Heroku. The build was successful however, I am attempting make a migration to an established postgresql database to connect it to Heroku remote.
When I run:
heroku run python manage.py migrate
I get the following error:
ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
The Django environment is currently activated in my terminal screen.
I ran python to get the version type then ran print(sys.path which showed the Django environment listed. Just for giggles I ran pip install django once again, where a message stating requirement already satisfied came up.
So it looks like django is installed, my virtual environment is working, but I cannot make the migration for Heroku...
Any advice appreciated.
What do we have:
Django app hosted on Pythonanywhere with sqlite db initialized
MySql DB activated on Pythonanywhere (it provided me with db name, pasword and host - everything that I need to setup settings.py)
pip install mysqlclient finished successfully
python manage.py makemigrations - DONE
python manage.py migrate - DONE
mysql console on Pythonanywhere shows all my tables created
but restarting app causes pythonanywhere error page and link to error log
2020-08-15 17:22:56,536: Error running WSGI application
2020-08-15 17:22:56,569: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
2020-08-15 17:22:56,569: Did you install mysqlclient?
So the question is how could it be possible? As i got it right migrations are used mysqlclient to manipulate DB, how can it be not installed?
Might be someone did face with similar issue?
you need to install mysql client, but that might also throw an error, so you need to install it using its wheels from https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient and keep installing every wheel incase an error occurs.
After I tried to deploy my Django website on Azure, I got an error saying:
ModuleNotFoundError: No module named 'django'
I added a requirements.txt in the root directory of my Django project, am I missing anything else? I've tried to install Django from Kudu BASH but it gets stuck on "Cleaning Up".
Here is the full error: https://pastebin.com/z5xxqM08
I built the site using Django-2.2 and Python 3.6.8.
Just summarized as an answer for other people. According to your error information, I can see that you tried to deploy your Django app to Azure WebApp on Linux based on Docker. So there are two offical documents will help as below.
Quickstart: Create a Python app in Azure App Service on Linux
Configure a Linux Python app for Azure App Service
The error ModuleNotFoundError: No module named 'django' indicated that there is not django package installed on the container of Azure Linux WebApp.
Due to the content of Container characteristics of #2 document above as below,
To install additional packages, such as Django, create a requirements.txt file in the root of your project using pip freeze > requirements.txt. Then, publish your project to App Service using Git deployment, which automatically runs pip install -r requirements.txt in the container to install your app's dependencies.
So the possible reason is the requirements.txt file not in the corrent path of your project or container after deployed, which path should be /home/site/wwwroot/requirements.txt on the container or the root of your project like the offical sample Azure-Samples/djangoapp on GitHub.
I had the same problem. requirements.txt was in my repository, but randomly I started getting the same error ModuleNotFoundError: No module named 'django' after changing a setting or restarting the service or something. Nothing I could do, change the setting, or reboot repeatedly fixed it. Finally what worked for me was this:
Make a small change to the code and commit it, and push it up to the app service.
This fixed it for me. It has happened a couple times now and every time this solution has worked for me. It seems like the App Service sometimes gets in this state and needs to be jostled with this trick?
I am trying to deploy my Flask endpoint on a AWS EC2 and after successfully installing requirements.txt which I run on ElasticBeanstalk, I try to run my scrip and it gives me:
from flask import Flask, jsonify
ModuleNotFoundError: No module named 'flask'
I tried manually to install flask with:
pip3 install flask
and still does not want to compile.
I haven't used AWS EC2 yet, but try adding shebang on top #!/usr/bin/env python
I've deployed a Rails application on Heroku. I also have a Python script inside the Rails bin folder. I am now using Heroku scheduler to run the Python script every 10 minutes. I want to test it first. So I run:
heroku run python bin/notify.py
in my local terminal. Then I got the following error message:
Running python bin/notify.py on ...
Traceback (most recent call last):
File "bin/notify.py", line 6, in <module>
import sendgrid
ImportError: No module named sendgrid
However, I've already had the sendgrid addon on Heroku. I can also use sendgrid in my Rails code without any problem.
Can anyone help me with this? Thanks!
Sounds like you forgot to install Python's sendgrid dependency when building the container. See declare Python app dependencies for how to install Python dependencies. As you are running both, ruby and Python, you have to install both buildpacks to ensure both dependencies are being loaded.
I contacted Heroku tech support. They told me I have to install both the ruby and python buildpack and include sendgrid in the requirements.txt in the application root directory.
https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app
Issue resolved.