我确实有一个简单的FastAPI应用程序,我使用了pip和venv来管理环境。当我通过uvicorn安装的包运行它时,我的导入是不可见的。它在python终端上工作。
简化文件夹结构: /venv /src main.py .requirements.txt ..
requirements.txt
alembic==1.4.3
click==7.1.2
fastapi==0.61.1
FastAPI-SQLAlchemy==0.2.1
pydantic==1.6.1
SQLAlchemy==1.3.20
uvicorn==0.12.2
python-dotenv==0.14.0在python中,在激活环境之后,导入fastapi_sqlalchemy工作:
Python 3.8.5 (default, Aug 25 2020, 14:19:38)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastapi_sqlalchemy
>>> 但是当我通过uvicorn运行时,应用程序会在fastapi_sqlalchemy导入上抛出错误。
uvicorn src.main:app --reload ✔ 16:58:54
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [40567] using statreload
3.8.5 (default, Aug 25 2020, 14:19:38)
[Clang 11.0.3 (clang-1103.0.32.62)]
Process SpawnProcess-1:
Traceback (most recent call last):
(... stacktrace here ...)
File "./src/main.py", line 8, in <module>
import fastapi_sqlalchemy
ModuleNotFoundError: No module named 'fastapi_sqlalchemy'src/main.py
import uvicorn
from fastapi import FastAPI
from dotenv import load_dotenv
import sys
print(sys.version)
import fastapi_sqlalchemy我不知道如何使这个库在运行uvicorn/应用程序的上下文中可见。
发布于 2020-10-26 09:00:50
最后..。我确实重新启动了我的电脑,它运行了♂️。
感谢所有看过这个的人。
发布于 2020-10-27 08:55:25
import fastapi_sqlalchemy 应该是
import FastAPI-SQLAlchemyhttps://stackoverflow.com/questions/64526011
复制相似问题