In Azure, using Python with the Flask and pandas modules to create a RESTful webservice. Azure doesn't appear able to find the requests_file module.
Launching the web page keeps returning error: No module named requests_file
I have installed "requests" and "requests_file" manually using the Kudu CLI https://"yoursitename".scm.azurewebsites.net/DebugConsole.
They both appear to be there. What am I missing or is there a bug in Azure?
You could configure your requirements.txt file in your flask project.
Put the list of your python modules in the requirements.txt
requests==2.18.4
Install wheel module using below command
python.exe -m pip install wheel
Use Below Command to create wheel files inside wheelhouse folder in Local environment
python.exe -m pip wheel -r requirements.txt -w wheelhouse
Then upload your project to your azure web app.
You could use code as below to test requests module
import requests
r= requests.get("https://www.bing.com")
print r.status_code
More details , please refer to this blog and this thread: Publishing MVC app that uses python script
Hope it helps you.
Related
I am attempting to deploy a Django app to a Linux server via an Azure App Service. During the deployment via Azure Devops Pipelines, all requirements are installed from my requirements.txt file in the root directory of my project.
I have used the Kudu console to confirm the dependencies are installed to /antenv/lib/python3.7/site-packages on the server, however, the app crashes due to an error:
ModuleNotFoundError: No module named 'django'
I am beginning to think the virtual environment may be failing to actually start but do not know how to check or how to start it if this is the case.
Has anyone had a similar issue to this during their deployment? If so how did you resolve it? Any advise is much appreciated. Thank you!
Newest
Change target path ,--target="./.python_packages/lib/site-packages" .
- bash: |
python3.8 -m venv worker_venv
source worker_venv/bin/activate
pip3.8 install setuptools
pip3.8 install --target="./.python_packages/lib/site-packages" -r requirements.txt
displayName: 'Install Application Dependencies'
You need to install a new Python runtime at the path D:\home via Kudu site extensions.(Windows)
The problems is, azure app service use virtualenv by default, so the requirements.txt package is automaticly installed to python in the virtualenv... so I just edit the deploy.cmd to install requirements to python (extension)
For more details, you can refer Peter Pan's answer in below post.
Why is the azure app service django deploy keep failing?
I am facing some issue with deploying a custom package (to be more specific 2checkout https://github.com/2Checkout/2checkout-python ) in a Django Project via Google App Engine.
As in order to deploy, we do need a file requirements.txt to be included with the python package dependencies (which can be installed via pip), but in the case of a custom package (like the above mentioned), how can we implement the custom package in Google App Engine.
If you're using the standard environment you can install the package into your application locally so that it's deployed as part of your app. From Private dependencies:
Dependencies are installed in a Cloud Build environment that does not
provide access to SSH keys. Packages hosted on repositories that
require SSH-based authentication must be copied into your project
directory and uploaded alongside your project's code using the
pip package manager.
To use private dependencies:
Run pip install -t lib my_module to copy dependencies into a local
folder named lib.
Add an empty __init__.py file to the lib directory to make it a
module.
Import the module in your app. For example:
import lib.my_module
If you're using the flexible environment you can build a custom runtime, see Deploy Python app with textract module to Google Cloud Platform.
I am trying to run dev_appserver.py on this Google App Engine Standard Flask Sample
As the instructions say I run:
pip install -t lib -r requirements.txt
dev_appserver.py app.yaml
I should be able to go to http://localhost:8080/form but I get ImportError: No module named msvcrt.
I found that using Flask==0.10.1 and Werkzeug==0.12.2 works but nothing newer.
Versions:
OS: Windows 10 Pro
Python 2.7.14
Google Cloud SDK 182.0.0
app-engine-go
app-engine-python 1.9.63
app-engine-python-extras 1.9.63
bq 2.0.27
core 2017.12.01
gsutil 4.28
I have tried the example myself from the Cloud Shell, and I also found some issues with the imports. It looks like newer releases of Werkzeug have transferred code to different locations, so as suggested in this recent post if you want to use the example as it is, you should better work with the version 0.12.2 of Werkzeug.
To do so, I recommend you the following steps:
Delete the lib file in the directory of the application, and all of its content.
Edit the requirements.txt file to be as follows:
requirements.txt:
Flask==0.12.2
werkzeug==0.12.2
Run again the command pip install -t lib -r requirements.txt.
Now you can try running your application locally with the dev_appserver. Please make sure that the appengine_config.py file is pointing to the proper location of the lib folder where the libraries are being installed.
Once you have done all that, everything should be working fine. I have tried browsing for the localhost URL you mentioned and a simple HTML page with a form appears.
I am on Mac OS and developing for google cloud platform.
I have created vitualenv - virtualenv xyz.
I activated using - source xyz/bin/activate
Then, I installed the pkg I needed - pip install python-dateutil
When I do pip list, I do see the python-dateutil is there
But when i run my service using dev_appserver.py . and try to make a post request. I get the ImportError: No module named dateutil.parser
Questions: In my appengine_config.py, I have vendor.add('lib') but the packages are installed under my_project-> xyz -> lib -> python2.7 -> site-packages -> dateutil. How does my app knows where to look for packages?
Second question: When I am ready to deploy to production, how do I deploy the packages. pip freeze > requirements.txt. Is that enough for prod server to know what packages to use. Do I need lib folder under my_project? I am confused about how packages get referred in virtualenv and in production.
You're mixing the instructions for installing dependencing for the standard environment with those for the flexible environment. Related: How to tell if a Google App Engine documentation page applies to the standard or the flexible environment
You're using dev_appserver.py so I assume your app is a standard environment one, in which case you need to install the library into your app (note the -t lib arguments), not on the system/venv. Assuming you execute from your app's dir:
pip install python-dateutil -t lib
Disclosure : First time Azure experience
I am deploying a Flask app to Azure Webapp. All deployment steps are fine till I hit the bcrypt package installation and it fails.
After much research based on error log output, I found out that I might need to install bcrypt using wheelhouse (*.WHL)
I downloaded the below files from here
bcrypt-3.1.0-cp27-cp27m-win32.whl
bcrypt-3.1.0-cp27-cp27m-win_amd64.whl
and I copied them to D:\home\site\repository\wheelhouse
Then, I activated the virtualenv through KUDU and I run this command:
d:\home\site\wwwroot\env\scripts\pip install -r requirements.txt --find-links d:\home\site\repository\wheelhouse
I get no messages or any log output. When I run a pip freeze > tmp.txt I get a blank file.
But when I run d:\python27\scripts\pip install -r requirements.txt --find-links d:\home\site\repository\wheelhouse
It starts installing the packages until it gets to bcrypt and it errs out with this message:
Skipping bcrypt-3.1.0-cp27-cp27m-win32.whl because it is not compatible with
this Python
Which is a confusing message because the wheel is for Python 2.7
Since my Flask app works fine on both my Linux and Windows dev machines, I went ahead and created my own brypt wheel file in my Windows computer which runs the same Python version on Azure. I uploaded the new .whl, redid the steps above and I still get the same error message
Extra notes:
python -V on Azure console returns 2.7.8
python -V while virtualenv is activated also returns 2.7.8
Azure portal > Application Settings shows "Python version 2.7" and "Platform 32bits".
After deployment, all packages in requirements.txt are installed except bcrypt.
Visiting the web page gives a 500 error (which i expect due to missing lib)
I removed the virtualenv and GIT pushed the repo with --find-links wheelhouse at the top of requirements.txt as stated here.
However, I get a Unable to find vcvarsall.bat error. That's why I m trying to manually install via wheel
I deleted the whole virtualenv, uploaded wheel files for all required packages to \repository\wheelhouse and added --no-index to my pip install command. Everything gets installed except bcrypt.
I tried bcrypt==3.1.1, bcrypt==3.1.0 and just bcrypt without specifying the version and it doesnt make any difference.
I ran out of ideas. Anyone knows what's wrong? How do I go about installing bcrypt on Azure webapp?
I was finally able to get the Flask app working on Azure Webapps.
Unfortunately, I couldn't do it using my usual dev tools.
Solution:
I created a VirtualEnv in Visual Studio using my requirements.txt file
Moved my Flask code to Visual Studio
Click on Publish to Azure Webapps
It does what it does and once completed, you may still get a 500 error.
If that is the case, use KUDU and take a look at your web.config file and modify the WSGI_ALT_VIRTUALENV_HANDLER value to match your Flask app name.
This is the only way I was able to get bcrypt to install correctly for my Flask app to work. I hope this saves someone valuable time.
That's all folks.
You could have tried using easy_install to install dependencies that failed to do so by pip. What I did was :
Go into KUDU debug Console. This is listed under Development Tools
Try executing env\scripts\pip install -r requirements.txt
For every failed dependency (as bcrypt), try and install it through env\scripts\easy_install bcrypt==3.1.0
You could also try and automate this by editing the deploy.cmd file. Such that at any point that pip fails, easy_install is executed