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.
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 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'm trying to deploy my Django site on Heroku, and thus, I need a requirements.txt file with the necessary packages that Heroku needs to install for me. I understand Django is a necessary package to be installed. Unfortunately, Django isn't included in the file when I run pip freeze > requirements.txt. Why is this? I'm not sure what to show you so you can tell me what's going wrong. Let me know and I'll add it. FYI the site hosts just fine on my local computer, so Django is definitely installed.
Sounds like you are working in a virtual environment, yet your Django dependency is installed globally. Check which Python packages are installed globally and uninstall Django (you probably don't need it globally). Then install it into your virtual environment. Now the freeze command should output Django as well.
General note: Most packages should be installed into your project virtual environment. There are only few packages where it makes sense to install them globally (eg aws management tools).
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.
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.