I have a Heroku Python project that is emitting errors that I can't reproduce locally. I suspect that the Python virtualenv in the Heroku deployment is corrupted in some way.
Is there a way to clean the Python virtualenv in a Heroku project and start fresh?
See Heroku docs. Create a runtime.txt file with a different version of Python than your current version and push to heroku. This will purge your appication's build cache and virtualenv. Then you can revert to your previous Python version in the runtime.txt and push that up to Heroku, giving you both your desired Python runtime and a clean virtualenv.
Related
So I began to code a project with python, and I was using a tutorial that told me to use a pip environment as my virtual environment. A problem arose, however, when I performed the git push heroku master command. It could not find the package django-heroku!
I was confused, because when I ran python manage.py runserver, the server on my computer ran. I then changed to a python environment, which was located in the directory I was pushing to heroku. The problem was solved! The virtual environment, and consequently the installed packages, were inside the directory being pushed to git, and I could use them in my website!
But the question still remains: can you use a pip environment for a django project being pushed to git? Thanks!
You should not include python packages within your repo and push them to Heroku. Check https://devcenter.heroku.com/articles/python-pip. You only need a requirements.txt file in your root directory. Heroku will install the packages automatically for you.
I managed to deploy my django app (with mongodb as database) on heroku.
But I need to modify some source code in django package in the virtual environment.
How can I access to virtual environment created by heroku from requirements.txt ?
Or maybe how can I upload directly the virtual environment to heroku and make sure that my GIT django app is working on it?
thank you
If your question is how would you know git dependencies match your local environment, first you should freeze your installed modules:
pip freeze > requirements.txt
Then include this file in the root directory of your app which will be deployed to heroku. After it is pushed to git, take a look at the commands run and verify the modules are installed.
We have a python(3) venv rest api. In the same venv we have also installed and configured the application server uwsgi the api is running on. And we are looking for a clean way to deploy it.
Until now we are deploying with is a simple script that creates the venv install the dependencies from pip and then runs the app.
I am wondering if using snap would be possible to package everything nicely and simply install them on a server.
Is that possible or a good practice to deploy a web api this way?
Thanks for your time.
Yes, you can do this with snaps. You can use the python plugin module with snapcraft which extends your python path with a virtualenv.
Also, Its pretty easy to do this with a deb.
dh-virtualenv lets you use standard debian packaging tools. https://labs.spotify.com/2013/10/10/packaging-in-your-packaging-dh-virtualenv/
It is your choice.
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
I am following a guide about deployment of django application using gunicorn mysql and nginx without virtualenv.
Now the problem here is when installing the gunicorn using pip install gunicorn i cannot find where its installation directory. Im new on exploring ubuntu os.
I have searched and cant find anything where the gunicorn file resides.
Here is the guide link but it use virtualenv