0

I am running the following python FastAPI app using Code Runner in VSCode but I get the following error, any idea what could be causing it?

[Running] C:\IDE\Anaconda3\envs\python38_web\python.exe -u "d:\github-repos\python\fastapi-app\main.py"
Traceback (most recent call last):
  File "d:\github-repos\python\fastapi-app\main.py", line 3, in <module>
    from fastapi import FastAPI, Response, status
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\fastapi\__init__.py", line 7, in <module>
    from .applications import FastAPI as FastAPI
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\fastapi\applications.py", line 15, in <module>
    from fastapi import routing
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\fastapi\routing.py", line 22, in <module>
    from fastapi.datastructures import Default, DefaultPlaceholder
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\fastapi\datastructures.py", line 3, in <module>
    from starlette.datastructures import URL as URL  # noqa: F401
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\starlette\datastructures.py", line 7, in <module>
    from starlette.concurrency import run_in_threadpool
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\starlette\concurrency.py", line 6, in <module>
    import anyio
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\anyio\__init__.py", line 104, in <module>
    from ._core._sockets import (
  File "C:\IDE\Anaconda3\envs\python38_web\lib\site-packages\anyio\_core\_sockets.py", line 2, in <module>
    import ssl
  File "C:\IDE\Anaconda3\envs\python38_web\lib\ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified module could not be found.

[Done] exited with code=1 in 1.031 seconds

Here is the code, it runs fine if I open a terminal in VSCode and run it.

import stat
from turtle import title
from fastapi import FastAPI, Response, status
from pydantic import BaseModel
from typing import Union, Optional
import uvicorn
import models

class Blog(BaseModel):
     title: str
     body: str
     published: Optional[bool]

app = FastAPI()

@app.get('/')
def root():
    blogs = models.session.query(models.Blog).all()
    return {'data': blogs}


if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=9000)
 

Thanks!

Walid
  • 43
  • 1
  • 6
  • @relent95 Thanks for your reply! That partially helped it. In my case I had to copy all DLL files for the modules I import from the bin folder of my virtual environment for this project to the DLLs folder. Strange solution but it works! – Walid Nov 01 '22 at 14:33

0 Answers0