LoginSignup
0
0

More than 1 year has passed since last update.

PoetryはColaboratoryで使えない??(2022.08現在)

Last updated at Posted at 2022-08-16
  • Poetryはgoogle Colaboratoryでは使えない様子。
    • venv非作成モードで、packageのインストール箇所がわかれば、解決できる可能性はあるかもしれない。
    • 解決策が分かる人がいたら教えていただきたい。
  • 症状
    • 一見、インストールも行われるのだが、vevn-pythonに切り替えられない
    • 手動で無理やり使えるかもしれないが、再利用のたびにコード修正は対象外としているため。

venvに切り替わらない

故に、折角パッケージをインストールできても、コードでvenvに切り替えて実行ができない


# 期待通り表示される。このPATHを「手動」で指定してのvenv-pythonでのrunは可能だろう
!poetry env info --path

# 切替1: セルのrunが終わらない
!poetry shell

# 切替2: 処理にエラー表示されないが、次のwhich pythonでは/usr/local/bin/pythonを指し、venvのpyを差さない。
!source $(poetry env info --path)/bin/activate

!which python # /usr/local/bin/pythonと表示されてしまう

venvを非作成に指定

下記を実行すれば、venvを作らないようにできる。

poetry config virtualenvs.create false

筆者の環境では、installに失敗する事も多々あるが、インストールした後は次の通りになる。

!poetry config virtualenvs.create false 
#
!poetry instal

上記の出力結果が下記。

...
Skipping virtualenv creation, as specified in config file.
Installing dependencies from lock file

Package operations: 1 install, 0 updates, 0 removals

  • Installing strenum (0.4.8): Pending...
  • Installing strenum (0.4.8): Installing...
  • Installing strenum (0.4.8)
!poetry show       

上記の出力結果が下記。

Skipping virtualenv creation, as specified in config file.
strenum 0.4.8 An Enum that inherits from str.
!pip freeze | grep -i strenum # 何も表示されない。
!poetry env info --path
%ls -lga /usr
!poetry shell
!source $(poetry env info --path)/bin/activate
!which python
!pip freeze | grep -i strenum

上記の出力結果が下記。

total 60
drwxr-xr-x 1 root 4096 Aug  3 20:14 ./
drwxr-xr-x 1 root 4096 Aug 16 15:13 ../
drwxr-xr-x 1 root 4096 Aug 16 15:26 bin/
drwxr-xr-x 2 root 4096 Apr 24  2018 games/
drwxr-xr-x 1 root 4096 Aug  3 20:14 grte/
drwxr-xr-x 1 root 4096 Aug  3 20:13 include/
drwxr-xr-x 1 root 4096 Aug  3 20:13 lib/
drwxr-xr-x 3 root 4096 Aug  3 19:50 lib32/
drwxr-xr-x 1 root 4096 Aug 12 13:32 local/
drwxr-xr-x 1 root 4096 Aug  3 20:12 sbin/
drwxr-xr-x 1 root 4096 Aug  3 20:19 share/
drwxr-xr-x 1 root 4096 Aug  3 20:13 src/
Skipping virtualenv creation, as specified in config file.
Virtual environment already activated: /usr
/bin/bash: /bin/activate: No such file or directory
/usr/local/bin/python
import strenum # ModuleNotFoundError: No module named 'strenum'

仮想環境を作成しないに指定した場合、既に居るvenvか.localにインストールされると思っているのだが、 違うみたい。このPATHを正しく指定し直せれば、使えるのだろうか....

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