docker build成功后,为什么还是报错; ModuleNotFoundError:没有名为“sqlalchemy”的模块

问题描述 投票:0回答:0

我有一个在 docker 容器中运行的 fastapi 应用程序。我认为所有依赖项都在构建运行期间安装。成功构建后,我通过 SSH 进入后端 docker 服务以访问数据库,以便使用以下命令迁移和播种开发数据库:

docker-compose exec backend sh
# Install poetry
apt-get -qq update 
apt-get -qq -y install curl
curl -sSL https://install.python-poetry.org | python3 -
export PATH="/root/.local/bin:$PATH"

# Install Poetry task runner poe, might take long to install
poetry add --group dev poethepoet

# Migrate the changes
poetry run poe migratedb

# For seeding the database with sample data use 
poetry run poe seed_db

# Exit the backend service shell
exit

现在当我运行最后一个命令时;

poetry run poe seed_db
我得到错误;

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  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 "/app/app/commands/seed_db.py", line 3, in <module>
    from sqlalchemy import insert, select
ModuleNotFoundError: No module named 'sqlalchemy'

我跑了

poetry add sqlalchemy
,输出解释说;

该包已经存在于 pyproject.toml 中,将被跳过。

python docker-compose sqlalchemy fastapi alembic
© www.soinside.com 2019 - 2024. All rights reserved.