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
Related
I am trying to deploy my flask app on AWS Lambda by using Zappa. I carefully followed all the tutorials but I always get deployment error :
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
I entered zappa tail and I figured out that the dependencies are not installed even after I made pip freeze > requirements.txt . The problem is, there are a lot of dependencies and it really boring to install each of them manually.
Is there any magic command that will allow me to automatically install all dependencies in the virtualenv ?
Why don't you just run
pip install -r requirements.txt?
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 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.
After deploying my python application with Zappa and visiting the aws link, I can see the following error:
When I checked the logs, I found the source of the error:
I then decided to pip install -r requirements.txt to ensure that it's installed inside my virtual environment (which it is):
Requirement already satisfied: Werkzeug==0.12 in ./flaskapi/lib/python3.6/site-packages (from -r requirements.txt (line 41))
Something is going wrong when it's uploaded to AWS. I'm not sure if this is the core issue, but I did notice the package name in the logs is different than the one inside requirements.txt file. The package name in the logs doesn't start with a capitalized 'W', while the package name in the requirements.txt does. Other than that, I'm not sure what I'm doing wrong.
Any and all help is appreciated
I solved this issue by upgrading to python 3.7 . I would recommend starting a new virtualenv, configured to use python 3.7 .
if you do not have python3.7 on your system, you will need to install it. This site is the one I used. Works on AWS cloud9 too.
installing python 3.7
virtualenv env -p python3.7
source ./env/bin/activate
python --version
output should be "Python 3.7.X"
then continue setting up your app like normal.
I try to run pip wheel azure-mgmt=0.20.1, but whenever I run it I get following pip wheel error, which is very clear:
error: [Error 183] Cannot create a file when that file already exists: 'build\\bdist.win32\\wheel\\azure_mgmt-0.20.0.data\\..'
So my question is where or how I can find that path? I want to delete that existing file. I have been searching my local computer, searched for default path in Google, but still didn't find any solution.
Also is it possible to tell pip wheel to output full log? As you can see that full error path is not displayed. I'm using virtualenv.
We can see the description of virtual env at the official python guide:
To help manage external package dependencies, Azure Git deployment supports the creation of virtual environments.
When Azure detects a requirements.txt in the root of the repository, it automatically creates a virtual environment named env. This only occurs on the first deployment, or during any deployment after the selected Python runtime has changed.
You can directly modify the dependencies and versions of them in requirement.txt, then deploy your python app to Azure Web App via git, Azure will update the python packages automatically. You can check the packages in the virtual env folder which path is env\Lib\site-packages in the root directory of your site. You can login on the kudu console of your site to check your files of you site online, the URL should be: https://{your_site_name}.scm.azurewebsites.net/DebugConsole .
Additionally, according your description, it seems that you use the global python environment to run pip install command which may directly install packages in your global python environment. To install packages in your virtual env, you need to run the similar command env\scripts\pip install -r requirements.txt in your root directory of your application. Please refer to Web app development - Windows - command line for more information.
have you tried uninstalling and reinstalling?
I tried pip wheel azure-mgmt and that installed -0.20.1 for me.
The directory for mine is /Users/me/wheelhouse, so you could look there. I found that in the initial log of the build.
#Amir,
One option is that you could generate the requirement.txt file and remove your virtual environment if you used Visual studio to develop your application. Then you can add a new virtual environment for your project and install all packages from requirement.txt file. Or after removed your virtual environment, you can try pip wheel azure-mgmt command.
And another option is that you can follow this similar issue:https://vilimpoc.org/blog/2014/01/18/time-robbing-python-errors/
The blogger modified the LOCALAPPDATA path to resolve this issue. Please try it.