cannot import name ‘Sequence’ from ‘collections’

I am developing a python-flask web application using Python 3.12 and locally it works fine.
I want to deploy it on Azure using Azure App Services (Web App).

I configured the Github actions to deploy the project on Azure App Services but after the deploy (successful), when i try to reach the web site i get the error:

ImportError: cannot import name 'Sequence' from 'collections' (/opt/python/3.12.2/lib/python3.12/collections/__init__.py)

It seems that the issue is that it is necessary to have:

from collections.abc import Sequence

I don’t get anyway why locally (even without this change) everything works fine (i created a dedicated virtual environment locally and i am using the corresponding requirements.txt file for the deploy) and online i get that error. Moreover, in case i want to have this “change” online, how can i handle it?

I tried to update the Github workflow but anyway i get the same error:

name: Build and deploy Python app to Azure Web App

env:
  AZURE_WEBAPP_NAME: MYWEBAPP    # Set this to the name of your Azure Web App
  PYTHON_VERSION: '3.12'         # Set this to the Python version to use

on:
  push:
    branches: [ "main" ]
  workflow_dispatch:

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python version
        uses: actions/[email protected]
        with:
          python-version: ${{ env.PYTHON_VERSION }}
          cache: 'pip'

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate

      - name: Install dependencies
        run: |
          source venv/bin/activate
          pip install -r requirements.txt

      - name: Debug before patching
        run: |
          source venv/bin/activate
          echo "Checking for incorrect imports in pathlib.py before patching:"
          grep 'from collections import Sequence' venv/lib/python3.12/site-packages/pathlib.py || true

      - name: Patch pathlib.py to fix import error
        run: |
          source venv/bin/activate
          echo "Patching pathlib.py..."
          sed -i 's/from collections import Sequence/from collections.abc import Sequence/' venv/lib/python3.12/site-packages/pathlib.py || true

      - name: Debug after patching
        run: |
          source venv/bin/activate
          echo "Checking for incorrect imports in pathlib.py after patching:"
          grep 'from collections import Sequence' venv/lib/python3.12/site-packages/pathlib.py || true
          echo "Checking for correct imports in pathlib.py after patching:"
          grep 'from collections.abc import Sequence' venv/lib/python3.12/site-packages/pathlib.py || true

      - name: Check Python Path and Virtual Environment
        run: |
          source venv/bin/activate
          python -c "import sys; print('Python executable:', sys.executable); print('Python path:', sys.path);"

      - name: Clean up and rebuild
        run: |
          source venv/bin/activate
          pip cache purge
          python -m pip uninstall -y -r requirements.txt
          pip install -r requirements.txt

      - name: Create .env file with secrets
        run: |
          source venv/bin/activate
          echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
          echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> .env
          # Add other secrets as needed

      # Optional: Add step to run tests here (PyTest, Django test suites, etc.)

      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v3
        with:
          name: python-app
          path: |
            .
            !venv/

  deploy:
    permissions:
      contents: none
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Development'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: ${{ env.AZURE_WEBAPP_NAME }}
          publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}

Any idea how to handle this issue?

Thanks

stefano

New contributor

user24015285 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật