skip to Main Content

I am attempting to deploy a django web-app to an Azure web server. According to the documentation, for dependencies, it automatically looks for either a requirements.txt or a setup.py. (https://learn.microsoft.com/en-us/azure/app-service/configure-language-python#could-not-find-setuppy-or-requirementstxt).

Due to a bug in one of the sub dependencies of one of the packages, I cannot use a requirements.txt (See the 3rd comment of the answer of the following: AttributeError: type object 'Callable' has no attribute '_abc_registry').

And instead, I must use a Pipfile.lock file instead. Just wondering how to actually use this in the install step. I am presuming I have to use the only other option which is a setup.py file, but I’m not sure what this file would look like. All the documentation I have seen online doesn’t involve running a Pipfile in the setup.py script.

Any help is appreciated~

2

Answers


  1. To deploy a Django web app to Azure using a Pipfile.lock instead of a requirements.txt, modify the setup.py file to read the Pipfile.lock and extract the dependencies, then use the extracted dependencies in the install_requires argument of the setup() function. This allows Azure to install the specified dependencies during deployment.

    Login or Signup to reply.
  2. In my Django app, I generated piplock file by using the method below:-

    pip install pipenv
    pipenv lock
    

    enter image description here

    My Pipfile.lock:-

    {
        "_meta": {
            "hash": {
                "sha256": "xxxx76effee8c7b80e4681e9321520166449ce8999a4ad0c168efdd"
            },
            "pipfile-spec": 6,
            "requires": {
                "python_version": "3.9"
            },
            "sources": [
                {
                    "name": "pypi",
                    "url": "https://pypi.org/simple",
                    "verify_ssl": true
                }
            ]
        },
        "default": {
            "asgiref": {
                "hashes": [
                    "sha256:xxxxa16eef663bc0e2e703ec6468e2fa8a5cd61cd449786d4f6e",
                    "sha256:xxxxxxb45120216b23878cf6e8525eb3848653452b4192b92afed"
                ],
                "markers": "python_version >= '3.7'",
                "version": "==3.7.2"
            },
            "django": {
                "hashes": [
                    "sha256:xxxx3d6df1b141b1481e193b033fd1fdbda3ff52677dc81afdaacbaed",
                    "sha256:xxxxc5a3da5a8d5b35cc6168f31b605971441798dac845f17ca8028039"
                ],
                "index": "pypi",
                "version": "==4.2.3"
            },
            "sqlparse": {
                "hashes": [
                    "sha256:xxxxd0f93e66f1efc6e1338a41884b7ddf2a350cedd20ccc4d9d28f3",
                    "sha256:xxxxxb8349fa3061f0fe7f06ca94ba65b426946ffebe6e3e8295332420c"
                ],
                "markers": "python_version >= '3.5'",
                "version": "==0.4.4"
            },
            "typing-extensions": {
                "hashes": [
                    "sha256:xxxxxxx0174bf433bccd69b0babc3b15b1a8dca43789fd7f61514b36",
                    "sha256:xxxx5db7ba217daeb99701ad295353c45f9e95963337ceeeffb2"
                ],
                "markers": "python_version < '3.11'",
                "version": "==4.7.1"
            },
            "tzdata": {
                "hashes": [
                    "sha256:xxxxx95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a",
                    "sha256:xxxxx099b6939b5546db7adce1e7d6f2e179e3df563c70511eda"
                ],
                "markers": "sys_platform == 'win32'",
                "version": "==2023.3"
            },
            "whitenoise": {
                "hashes": [
                    "sha256:xxxxccaebxxx48450b8f0307ca368195a8",
                    "sha256:xxxx9031cc9bb2cdbc8e5e53365407acf99f7ade9ec"
                ],
                "index": "pypi",
                "version": "==6.5.0"
            }
        },
        "develop": {}
    }
    

    Now create a setup.py file like below and run it:-

    setup.py file:-

    import os
    from setuptools import setup
    
    def read_requirements():
        with open('Pipfile.lock') as f:
            requirements = f.readlines()
        return [req.strip() for req in requirements]
    
    setup(
        name='msdocs-python-django-webapp-quickstart',
        version='1.0',
        install_requires=read_requirements(),
    )
    

    And install the setup.py file by running the command below:-

    python setup.py install
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search