OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

PyInstaller-built API Not Recognizing Routes After Building

  • Thread starter Thread starter WesleyAlmont
  • Start date Start date
W

WesleyAlmont

Guest
I'm building an API using PyInstaller 6.4.0, but it's not working.

For some reason, the built file is not recognizing my routes.

The project folder structure is:

markdown Copiar código

Code:
API
 ├── logs
 └── v1
     └── routes
         ├── router1.py
         └── router2.py

The code is:

Code:
[imports]
rprefix = f"/api/v1"

app = FastAPI()

[...]

router_prices = importlib.import_module(f"v1.routes.checkprices_routes")
router_commons = importlib.import_module(f"v1.routes.commons_routes")

[...]

app.include_router(
    router_prices.__getattribute__("check_prices_router"), prefix=rprefix
)
app.include_router(router_commons.__getattribute__("commons_router"), prefix=rprefix)

if __name__ == "__main__":
    if len(SSL_KEY) > 0 and len(SSL_CERT) > 0:
        uvicorn.run(
            "main:app",
            host=API_HOST,
            port=API_PORT,
            reload=False,
            ssl_keyfile=SSL_KEY,
            ssl_certfile=SSL_CERT,
        )
    else:
        uvicorn.run("main:app", host=API_HOST, port=API_PORT, reload=False)

traceback:

Code:
<module 'v1.routes.checkprices_routes' from 'C:\\Users\\WA\\Área de Trabalho\\\main\\_internal\\v1\\routes\\checkprices_routes.py'>
<module 'v1.routes.commons_routes' from 'C:\\Users\\WA\\Área de Trabalho\\main\\_internal\\v1\\routes\\commons_routes.py'>
Traceback (most recent call last):
  File "main.py", line 36, in <module>
    router_prices = importlib.import_module(f"v1.routes.checkprices_routes")
  File "importlib\__init__.py", line 127, in import_module
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\Users\WA\Área de Trabalho\main\_internal\v1\routes\checkprices_routes.py", line 10, in <module>
    from v1.repositories.checkprices_search.search_repository import \
  File "C:\Users\WA\Área de Trabalho\main\_internal\v1\repositories\checkprices_search\search_repository.py", line 13, in <module>
    from v1.models.dao.product_classes_DAO import ProductClassesDAO
  File "C:\Users\WA\Área de Trabalho\main\_internal\v1\models\dao\product_classes_DAO.py", line 2, in <module>
    from main import LOGGER
  File "C:\Users\WA\Área de Trabalho\main\_internal\main.py", line 61, in <module>
    router_prices.__getattribute__("check_prices_router"), prefix=rprefix
AttributeError: partially initialized module 'v1.routes.checkprices_routes' has no attribute 'check_prices_router' (most likely due to a circular import)
[16600] Failed to execute script 'main' due to unhandled exception!

P.S: The project is currently running on VSCode; it just doesn't work after building.
<p>I'm building an API using PyInstaller 6.4.0, but it's not working.</p>
<p>For some reason, the built file is not recognizing my routes.</p>
<p>The project folder structure is:</p>
<p>markdown
Copiar código</p>
<pre><code>API
├── logs
└── v1
└── routes
├── router1.py
└── router2.py
</code></pre>
<p>The code is:</p>
<pre><code>[imports]
rprefix = f"/api/v1"

app = FastAPI()

[...]

router_prices = importlib.import_module(f"v1.routes.checkprices_routes")
router_commons = importlib.import_module(f"v1.routes.commons_routes")

[...]

app.include_router(
router_prices.__getattribute__("check_prices_router"), prefix=rprefix
)
app.include_router(router_commons.__getattribute__("commons_router"), prefix=rprefix)

if __name__ == "__main__":
if len(SSL_KEY) > 0 and len(SSL_CERT) > 0:
uvicorn.run(
"main:app",
host=API_HOST,
port=API_PORT,
reload=False,
ssl_keyfile=SSL_KEY,
ssl_certfile=SSL_CERT,
)
else:
uvicorn.run("main:app", host=API_HOST, port=API_PORT, reload=False)
</code></pre>
<p>traceback:</p>
<pre><code><module 'v1.routes.checkprices_routes' from 'C:\\Users\\WA\\Área de Trabalho\\\main\\_internal\\v1\\routes\\checkprices_routes.py'>
<module 'v1.routes.commons_routes' from 'C:\\Users\\WA\\Área de Trabalho\\main\\_internal\\v1\\routes\\commons_routes.py'>
Traceback (most recent call last):
File "main.py", line 36, in <module>
router_prices = importlib.import_module(f"v1.routes.checkprices_routes")
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\WA\Área de Trabalho\main\_internal\v1\routes\checkprices_routes.py", line 10, in <module>
from v1.repositories.checkprices_search.search_repository import \
File "C:\Users\WA\Área de Trabalho\main\_internal\v1\repositories\checkprices_search\search_repository.py", line 13, in <module>
from v1.models.dao.product_classes_DAO import ProductClassesDAO
File "C:\Users\WA\Área de Trabalho\main\_internal\v1\models\dao\product_classes_DAO.py", line 2, in <module>
from main import LOGGER
File "C:\Users\WA\Área de Trabalho\main\_internal\main.py", line 61, in <module>
router_prices.__getattribute__("check_prices_router"), prefix=rprefix
AttributeError: partially initialized module 'v1.routes.checkprices_routes' has no attribute 'check_prices_router' (most likely due to a circular import)
[16600] Failed to execute script 'main' due to unhandled exception!
</code></pre>
<p>P.S: The project is currently running on VSCode; it just doesn't work after building.</p>
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Top