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

WSL から Windows native の python 環境(e.g. conda)を呼び出したいメモ

Posted at

背景 

Conda で Python アプリを作っている.

実行は Windows native の Python 環境で行いたい(tkinter で GUI 使っていたり, pytorch で GPU 使っているなどで, Windows native の Python 環境を呼び出す必要がある).
でもファイル操作とか Windows だとめんどい(bash for windows つかったとしても)ので, WSL で行いたい.

方法

conda activate して WSL(bash)上で Windows native 側の conda 環境に入るみたいなのはやはりシェルが違うからダメでした.

windows で直接実行したいスクリプトを呼ぶのを batch file で wrap して, それを WSL から呼び出すことになります.

rem myscript.bat
call conda.bat activate myenv
python.exe myscript.py

を用意して, WSL から

$ cmd.exe /c myscript.bat

のようにします. . による相対パス指定できないようなので, .bat がカレントフォルダにない場合は Windows の絶対パス(e.g. C:/Users/<yourname>/myscript.bat)で指定します

また, WSL のフォルダで実行すると UNC path 対応していませんエラーがでるので, /c/Users/<yourname>/ などの Windows のディレクトリで実行が必要です.

TODO

  • PowerShell にしてもう少し使いやすくならないか調べる
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?