LoginSignup
6
0

More than 1 year has passed since last update.

poetry install で setup command: use_2to3 is invalid が発生した時の対応

Posted at

はじめに

poetry関連で探しても見つからなかったので備忘録を兼ねて。

問題点

poetry installコマンドを実行した時に以下のようなエラーが発生することがある。

  • Installing pycallgraph (1.0.1): Failed

  EnvCommandError

  Command ['/root/.cache/pypoetry/virtualenvs/sample-9TtSrW0h-py3.8/bin/pip', 'install', '--no-deps', '/root/.cache/pypoetry/artifacts/5c/0a/1d/fe9e4da1743b3cef6c270ea451449e4a0f5ef4f0c2d60ac553ebc84891/pycallgraph-1.0.1.tar.gz'] errored with the following return code 1, and output:
  Processing /root/.cache/pypoetry/artifacts/5c/0a/1d/fe9e4da1743b3cef6c270ea451449e4a0f5ef4f0c2d60ac553ebc84891/pycallgraph-1.0.1.tar.gz
    Preparing metadata (setup.py): started
    Preparing metadata (setup.py): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /root/.cache/pypoetry/virtualenvs/sample-9TtSrW0h-py3.8/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-boynbmqb/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-boynbmqb/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-6rk_9ex9
         cwd: /tmp/pip-req-build-boynbmqb/
    Complete output (1 lines):
    error in pycallgraph setup command: use_2to3 is invalid.
    ----------------------------------------
  WARNING: Discarding file:///root/.cache/pypoetry/artifacts/5c/0a/1d/fe9e4da1743b3cef6c270ea451449e4a0f5ef4f0c2d60ac553ebc84891/pycallgraph-1.0.1.tar.gz. Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.


  at /usr/local/lib/python3.8/dist-packages/poetry/utils/env.py:1183 in _run
      1179│                 output = subprocess.check_output(
      1180│                     cmd, stderr=subprocess.STDOUT, **kwargs
      1181│                 )
      1182│         except CalledProcessError as e:
    → 1183│             raise EnvCommandError(e, input=input_)
      1184│
      1185│         return decode(output)
      1186│
      1187│     def execute(self, bin, *args, **kwargs):

やってみたこと

その1 : setuptools のバージョンを下げる

急にpip installで一部のライブラリのインストールが失敗するようになった件 に書かれているように、 setuptools のバージョンを下げると解決できる模様。
ということで、

poetry run pip install -U setuptools=="57.0.0"

をやってみた。
が、更新されず。

root@f42fd5750532:/app# poetry run pip install -U setuptools=="57.0.0"
The virtual environment found in /app/.venv seems to be broken.
Recreating virtualenv sample-9TtSrW0h-py3.8 in /root/.cache/pypoetry/virtualenvs/sample-9TtSrW0h-py3.8
Collecting setuptools==57.0.0
  Downloading setuptools-57.0.0-py3-none-any.whl (821 kB)
     |████████████████████████████████| 821 kB 1.6 MB/s
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 58.3.0
    Uninstalling setuptools-58.3.0:
      Successfully uninstalled setuptools-58.3.0
Successfully installed setuptools-57.0.0
root@f42fd5750532:/app# poetry run pip list
The virtual environment found in /app/.venv seems to be broken.
Recreating virtualenv sample-9TtSrW0h-py3.8 in /root/.cache/pypoetry/virtualenvs/sample-9TtSrW0h-py3.8
Package    Version
---------- -------
pip        21.3.1
setuptools 58.3.0
wheel      0.37.0
root@f42fd5750532:/app#

どうやら何かしらの原因で Recreating virtualenv が実行されて pip でインストールしたものがなくなってしまっている模様。

その2 : python3.8-env をインストール

rasa - The virtual environment found seems to be broken | python poetry - Stack OverflowGCEのUbuntu 20.04でvenvがaptでインストールできなかった原因と回避策 を参考に python3.8-env をインストールしようとしたが全然できず。。。

その3 : poetry config virtualenvs.in-project true を実行

Recreating virtualenvの解決策として、プロジェクトフォルダに .venv を作成したら良いのではと思い、以下のコマンドを実行。

root@63d3091e4aac:/app# poetry config virtualenvs.in-project true

その後

root@63d3091e4aac:/app# poetry run pip install -U setuptools==57.0.0
root@63d3091e4aac:/app# poetry install
Creating virtualenv sample in /app/.venv
Installing dependencies from lock file
 ....

をやってみたら特に問題なく終了。

よくよく調べたら公式のIssueにも上がってた。

解決策

poetry run pip install -U setuptools==57.0.0
poetry config virtualenvs.in-project true

をやれば良い。
(setuptoolsのバージョンは、58 未満であれば良い。その中で最新の 57.5.0 でも問題なし)

注意点

古い .venv があったりすると上記対応をしても

The virtual environment found in /app/.venv seems to be broken.

が発生することがあるので、一度今ある .venv を削除した方が良い。

あとがき

「ここ違うのでは?」「こういう方法あるよ!」ってのがあればコメント頂けると嬉しいです。

6
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
6
0