I have a flask server with the following architecture
.
├── doc
│ ├── apidoc.json
│ ├── docAPI
│ └── generation_doc
├── images
│ ├── parking
│ └── user
├── log
│ └── file.log
├── README.md
├── requirements.txt
├── run_server.py
├── server
│ ├── controllers
│ ├── __init__.py
│ ├── models
│ ├── myServerUtils
│ ├── __pycache__
│ └── routes
└── venv
├── bin
├── include
├── lib
└── pip-selfcheck.json
Everything is running fine under python2. But I have to migrate to python3. After changing the requirements of python-mysql to pymysql and refactoring how the imports are done, here is the error I get.
/home/myUser/Documents/myServer/backend/venv/bin/python /home/myUser/Documents/myServer/backend/run_server.py
Traceback (most recent call last):
File "/home/myUser/Documents/myServer/backend/run_server.py", line 4, in <module>
from server import app
File "/home/myUser/Documents/myServer/backend/server/__init__.py", line 26, in <module>
from .controllers import *
File "/home/myUser/Documents/myServer/backend/server/controllers/__init__.py", line 1, in <module>
from .user import *
File "/home/myUser/Documents/myServer/backend/server/controllers/user.py", line 3, in <module>
from .. import UserTable
ImportError: cannot import name 'UserTable'
Process finished with exit code 1
The imports in the file controllers/user.py
are
from .. import db
from .. import return_error
from .. import UserTable
from .. import ErrorType
from .. import Logger
from .. import ParkingTable
from .. import ParkingBookedTable
from .. import reset_password as mail_reset_password
from .. import app
from flask import request, jsonify, send_file
import exrex, hashlib
from validate_email import validate_email
from datetime import datetime
import uuid
import os
import time
and here are the imports from models/users.py
where UserTable
is defined
from .. import db
from .. import ErrorType
from validate_email import validate_email
import uuid
import time
Thanks by advance!
[EDIT]: To add a complement of information regarding the answer of dmitrybelyakov, the problem was coming from my IDE that had optimised the imports and messed up some of them. Rolling back on my git and setting my imports correctly did the job.
I don't have a definitive answer, but I would start by checking if there are any circular imports happening.