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
Related
I am trying to learn the basics of apis and flask restful, and was trying to run the minimal api in the flask documentation.
I installed flask and flask-restful into the scripts folder in the virtual environment using command prompt, and my ide picked up that these modules are installed.
However, having saved the script, when I try to run the python file in command prompt as an http server, it comes back with the following error:-
ModuleNotFoundError: No module named 'flask_restful'
As far as I can tell, the module is definitely actually there (since py-charm makes it pretty clear if a module referred to in the code is not actually installed).
So two questions - what is going on? And more importantly, how do I fix it?
(PS - the above is with respect to windows command prompt)
My code for reference
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {'hello':'world'}
api.add_resource(HelloWorld,'/')
if __name__ == '__main__':
app.run(debug=True)
Do you have flask-restful installed on your system? If not just use pip for installation, and type in your command prompt this command: pip install flask-restful
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
I have created a python project in VS Code and deployed it on Azure Function with all the required file like requirements.txt.
Code is running successfully on my local machine but giving error when I am running it on Azure Function as "No module named 'requests'".
My requirements.txt file consist of following elements:
azure-functions
requests
PyJWT
cryptography
So Is there any way to manually install this package on Azure Functions Linux VM. I am using consumption plan of Azure functions
Code is running successfully on my local machine but giving error when I am running it on Azure Function as "No module named 'requests'".
Your function can run successfully locally, indicating that requests has been installed.
You can try to use this command to generate your requirements.txt in case the requirements.txt created by yourself is wrong:
pip freeze > requirements.txt
Then you can try to redeploy, if it is not successful, you can try to deploy your function using this command:
func azure functionapp publish <function app name> --build remote
<function app name> is the name of your Azure Function App in your Azure Portal.
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?
Iv'e been doing some maintenance on the server side and then deployed the app to the GAE. since I deployed the new version, it doesn't recognize the flask_sqlalchemy module. It worked perfectly before the commit. is there something that I'm missing?
Ok for anyone getting this error, apparently I forgot to copy the libraries to the lib folder. I did that by using the command: pip install -t lib -r requirements.txt