3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

poetry dev コンテナで .venv が壊れて、想定外の仮想環境再作成が行われたことへの対処

Posted at

発端

自身のlocal環境に .venv を作成しました。
そして、元々開発で使っていた poetry dev コンテナを立ち上げた時、
ホストの .venv がコンテナの .venv にバインドされて壊れてしまいました。
気が効く poetry は仮想環境の再構築を始めました。
(ここまではありそうな話の想定)

しかし、poetry は想定外の仮想環境の構築をし始めてしまいました :thinking:

root@e4a563668462:/var/www# poetry run uvicorn apps.main:app --reload --host 0.0.0.0
The virtual environment found in /var/www/.venv seems to be broken.
Recreating virtualenv www-p9HyaoIY-py3.9 in /root/.cache/pypoetry/virtualenvs/www-p9HyaoIY-py3.9

  FileNotFoundError

  [Errno 2] No such file or directory: b'/bin/uvicorn'

  at /usr/local/lib/python3.9/os.py:607 in _execvpe
       603│         path_list = map(fsencode, path_list)
       604│     for dir in path_list:
       605│         fullname = path.join(dir, file)
       606│         try:
    →  607│             exec_func(fullname, *argrest)
       608│         except (FileNotFoundError, NotADirectoryError) as e:
       609│             last_exc = e
       610│         except OSError as e:
       611│             last_exc = e

現在ディレクトリに .venv を作ってもらうにはどうしたら良いかというお話です。

poetry config を設定し直し、 .venv を再構築してパッケージを入れ直す

virtualenvs.in-project を true に修正することで、現在ディレクトリに .venv を作ってくれました。

root@531b098ed9d3:/var/www# poetry config --list
cache-dir = "/root/.cache/pypoetry"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.path = "{cache-dir}/virtualenvs"  # /root/.cache/pypoetry/virtualenvs


root@531b098ed9d3:/var/www# poetry config virtualenvs.in-project true

root@531b098ed9d3:/var/www# poetry config --list
cache-dir = "/root/.cache/pypoetry"
experimental.new-installer = true
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.path = "{cache-dir}/virtualenvs"  # /root/.cache/pypoetry/virtualenvs

root@531b098ed9d3:/var/www# poetry install
The virtual environment found in /var/www/.venv seems to be broken.
Recreating virtualenv www in /var/www/.venv
Installing dependencies from lock file

Package operations: 60 installs, 0 updates, 0 removals

  • Installing certifi (2021.10.8)
  • Installing charset-normalizer (2.0.7)
  • Installing idna (3.3)

この後無事パッケージ install が進み、 uvicorn が起動してくれました。

参考

poetry の設定のリファレンス

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?