Python Flask Project migration from python3.6.8 to python 3.12.3

I have a Python Flask project created using Python 3.6.8 that needs to be updated to the latest version, Python 3.12.3. During this process,I am encountering numerous issues with the PIP packages. Can you help me with the migration steps to follow? is it possible to migrate project ?

I’d probably start by trying to upgrade to the lowest version with security support eg 3.8.19 then upgrading gradually minor version at a time to 3.12

What problems specifically are you having with your packages? It’s likely they will need upgrades also to support the new python versions

You probably wanted to ask this in the python help category not ideas Python Help - Discussions on Python.org

2 Likes

Could someone move this to help?

The Flask docs at Installation — Flask Documentation (3.0.x) only say it supports Python 3.8 and newer. That’s the first thing I check.

I have Python 3.11 and it works there.

What are the exact errors you are getting? Can you install just Flask and post the errors here as formatted code?

@graingert Thanks for your response. will change this to Python help discussion.

And, I have successfully installed all the packages with the latest versions. However, when I try to run the application, it shows errors related to the PIP packages in the site-packages directory, such as import errors

ImportError: cannot import name ‘Mapping’ from ‘collections’
AttributeError: module ‘inspect’ has no attribute ‘formatargspec’.

I am resolving these errors in the pip files, even though it may lead to other similar issues

Thanks in advance…

Can you show the full traceback, using a code block, eg:

```
traceback here
```

@c-rob Thanks for the response.

Here are the detailed steps.

The lists of packages we are using in the project.
alembic
aniso8601
attrs
bcrypt
certifi
cffi
chardet
click
Flask
Flask-Bcrypt
Flask-Cors
Flask-Mail
Flask-Migrate
flask-restplus
Flask-Script
Flask-SQLAlchemy
Flask-Testing
honcho
idna
itsdangerous
Jinja2
jsonschema
Mako
pyrsistent
python-crontab
python-dateutil
python-editor
pytz
pypng
PyQRCode
redis
requests
semantic-version
six
smmap2
SQLAlchemy
urllib3
virtualenv
Werkzeug
markupsafe
zeep
weasyprint
wheel
importlib_metadata
psycopg2-binary
PyJWT
pandas

1)They are all version-based in Python 3.6.8.
2) So now i have removed all the versions to install the latest for Python 3.12.3.
3) The packages installation has been installed successfully
4)Now, when trying to run the application, it shows import errors in the site-packages directory.

ImportError: cannot import name ‘Mapping’ from 'collections its from jinja2
AttributeError: module ‘inspect’ has no attribute ‘formatargspec’ its from alembic

Please help me on this… is it possible to convert the project?

Thank you

Something like this?

No that’s a screen shot, not a code block. Read about code blocks for Markdown here: About the Python Help category - #10

2 Likes

Can you show the output of pip when you install your requirements? Remember to use a code block. for some reason you have an alembic version older than 1.0.5

1 Like

We will probably need to see exactly how you did this - the actual commands, in the terminal. Please read the thread that @c-rob linked you above, and format anything that was in the terminal like multi-line code.

Another useful piece of information is to show the result of python3.12 -m pip list (make sure it refers to the exact Python environment that you will use for the project).

Package Version


adal 1.2.7
alembic 1.13.1
altgraph 0.17.4
aniso8601 3.0.0
attrs 19.1.0
auto-py-to-exe 2.29.0
bcrypt 3.1.4
blinker 1.8.2
bottle 0.12.25
bottle-websocket 0.2.9
Brotli 1.0.9
cached-property 1.5.2
cachelib 0.6.0
certifi 2024.2.2
cffi 1.15.1
chardet 3.0.4
charset-normalizer 3.3.2
click 8.1.7
colorama 0.4.5
comtypes 1.1.14
cryptography 40.0.2
cssselect2 0.4.1
dataclasses 0.8
delta 0.4.2
Eel 0.14.0
elastic-transport 8.4.0
elasticsearch 7.0.2
et-xmlfile 1.1.0
fillpdf 0.7.2
Flask 3.0.3
Flask-Bcrypt 0.7.1
Flask-Cors 3.0.4
Flask-Mail 0.9.1
Flask-Migrate 2.1.1
Flask-RESTful 0.3.6
flask-restplus 0.13.0
Flask-Script 2.0.6
Flask-Session 0.4.0
Flask-SQLAlchemy 3.1.1
Flask-Testing 0.7.1
fonttools 4.27.1
future 0.18.3
gevent 22.10.2
gevent-websocket 0.10.1
greenlet 2.0.2
honcho 1.0.1
html5lib 1.1
idna 3.7
imgkit 1.2.3
importlib-metadata 4.8.3
importlib-resources 5.4.0
install 1.3.5
isodate 0.6.1
itsdangerous 2.2.0
Jinja2 3.1.4
jose 1.0.0
jsonschema 2.6.0
lxml 4.9.2
Mako 1.3.5
MarkupSafe 2.1.5
mouse 0.7.1
msal 1.26.0
mysql-connector-python 8.0.33
numpy 1.19.5
oauthlib 3.2.2
opencv-python 4.5.5.62
openpyxl 3.1.2
pafy 0.5.5
pandas 1.1.5
pdf2image 1.16.0
pdfkit 1.0.0
pdfrw2 0.5.0
pefile 2023.2.7
Pillow 8.4.0
pip 24.0
platformdirs 2.4.0
protobuf 3.19.6
psycopg2-binary 2.8.2
pycparser 2.18
pycryptodome 3.20.0
pydyf 0.1.2
pyinstaller-hooks-contrib 2022.0
PyJWT 2.4.0
pymssql 2.2.10
PyMuPDF 1.19.0
PyMySQL 1.0.2
pyodbc 4.0.39
pyparsing 3.1.1
PyPDF2 3.0.0
pyphen 0.11.0
pypiwin32 223
pypng 0.0.20
PyQRCode 1.2.1
pyrsistent 0.15.2
python-crontab 2.3.6
python-dateutil 2.7.0
python-editor 1.0.3
pyttsx3 2.90
pytube 12.1.3
pytz 2024.1
pywin32 305
pywin32-ctypes 0.2.2
pyzbar 0.1.9
redis 3.2.1
reportlab 3.6.8
requests 2.31.0
requests-file 1.5.1
requests-toolbelt 0.10.1
routingpy 0.3.3
typing_extensions 4.11.0
urllib3 1.26.2
virtualenv 16.4.3
weasyprint 54.3
webencodings 0.5.1
Werkzeug 3.0.3
wheel 0.37.1
whichcraft 0.6.1
wkhtmltopdf 0.2
xlrd 1.2.0
XlsxWriter 3.0.4
youtube-dl 2021.12.17
zeep 4.1.0
zipp 3.6.0
zope.event 4.6
zope.interface 5.5.2
zopfli 0.1.9

When am trying to run using. python manage.py run. it gives the above screenshot error.

manage file screens.
image
image

Please use code blocks instead of screenshots. What error do you get?

In Python, all functions must be declared before they are used. Here’s the general outline of a Python program.

# Imports go here. 
import re
import os

# Define all functions here. 
def func1(): 
    pass # Do nothing, this is a placeholder

# Main program goes here. 
if __name__ == '__main__': 
    run()