ctranslate2でpytorchがimportできないエラーが出たので回避方法メモ

公式のインストール方法

pip install ctranslate2

https://github.com/OpenNMT/CTranslate2

Macでは上手く動作しない

segmentatioin faultになった。

しかしlinuxでは動作するとの情報を得た。 なのでまずはMacの中でDocker環境を構築して問題を回避できないか確認しようとした。

[Read More]

pysenをインストールするとmypy周りで他のライブラリがエラーになる

pysenが入っていたらlangChainと依存関係がバッティングする?

環境

Mac OS poetry python == 3.9

LangChainのインストールに失敗する

poetry add langchain

が失敗する

CLANG 

C言語関係のエラーかと思われた。

なんだっけ

xcode-toolsのインストールとアップデート

pip install --update pip
pip install --upgrade setuptools

mypyのバージョンによるエラーらしい

[Read More]

poetry環境でpytorchをインストールしても失敗したのでその対処法

poetry add torch でパスが通らない

  • Dcokerfile+poetry で環境構築をしていた
  • poetry add torchでpytorchをインストールした
  • import torchでエラー
  • cuda周りのパスが通っていないらしい

対処法

  • poetry run python -m pip install torch
  • poetry.tomlに記述することもできるらしい

参考資料

poetry環境でstreamlitを実行する方法

症状

  • streamlitをpoetryを使ってインストールした場合に、streamlitが実行できない
  • poetry add streamlitでstreamlitを追加した場合、通常のシェルからはstreamlitのパスが通っていない
  • which streamlitの実行結果でなにもでてこない

対処

  • poetry からシェルを実行する
  • poetry shell
  • streamlit run sample.py
  • streamlitコマンドが実行できるようになる
  • 仮想環境にstreamlitをインストールした場合には通常のシェルからはstreamlitを実行できない
  • その場合の対処法は公式サイトに載っている

参考リンク

pycharmからpoetryで環境の作成ができない

症状

pycharmでinterpreterの指定にエラーが出た。 改めてpoetryの環境構築を行おうとしたところ、以下のエラーが出た。

ModuleNotFoundError No module named 'virtualenv.activation.xonsh' at <frozen importlib._bootstrap>:984 in _find_and_load_unlocked

解決方法

pip3 uninstall virtualenv

原因

  • anyenvのアップデートをかけたのが悪かったか?

反省

  • 不用意なアップデートは不具合の原因になる

Building a python environment with poetry on mac os

Pip is a major method of installing python libraries.

poetry is a more advanced version control tool for development environments.

It seems to have official support for pyenv integration.

I’ll write down how to install it on mac os and what I got stuck.

Advantages of poetry

  • Can organize library dependencies.
    • There are some unexpected side effects depending on the version of the library.
    • Trying to recreate the environment can cause errors with library versions and installation order.
    • Building the environment is an inevitable part of human work, so it should be automated if possible.
    • Also, it seems to be able to update the library version to take dependencies into account.
    • And it keeps a record of the status.
  • Is it possible to separate the dependency records by git branch?
  • The libraries you can install are comparable to pip
    • Does it have the same references as pypy?
  • Usability is not much different from pip
    • Poetry add instead of pip install
  • It recognizes virtual environments created with pyenv and works with them.

I’m going to install it because it seems to be a convenient way to build an environment without much effort.

[Read More]

ポートフォリオ

実績

pythonに引数をとらせるArgparseの例

サンプルプログラム

以下公式サイトより引用

import argparse

parser.add_argument("square", type=int,
                    help="display a square of a given number")
parser.add_argument("-v", "--verbose", action="store_true",
                    help="increase output verbosity")
args = parser.parse_args()
answer = args.square**2

解説

parser.add_argument("square", type=int,
                help="display a square of a given number")

引数の名前がsquare

型を指定できる。デフォルトはstr。

前に-がつかない名前は位置引数。

[Read More]