LoginSignup
10
4

More than 3 years have passed since last update.

pipenv on WSLでwindowsのpythonが呼ばれてしまう問題

Posted at

状況

少し前まで、WSL(ubuntu18.04LTS)上でpipenvを使っていて、
WSL上のpythonが呼ばれていて全く問題なかったのに、しばらくWSL使っていなかったら気づいたら表題の状況になっていた。

windows側のアップデートやらなんやらしていたので何が原因かはわからない。

方法

アプリと機能>アプリ実行エイリアスでpythonをオフにする
apl.png

蛇足

pipenvを入れればいいとか、pyenvを入れればいいとか混乱したので、一回全部消して下記に落ち着いた。1

pyenv install


$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ source ~/.bashrc

お好みのpython

$ pyenv install 3.8.1
$ python -V
Python 3.8.1

pipenv install

$ pip list
Package    Version
---------- -------
pip        19.2.3
setuptools 41.2.0
WARNING: You are using pip version 19.2.3, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip install --upgrade pip
$ pip install pipenv
$ pip list
Package          Version
---------------- ----------
certifi          2019.11.28
pip              19.3.1
pipenv           2018.11.26
setuptools       41.2.0
virtualenv       16.7.9
virtualenv-clone 0.5.3

pipenvの環境作成

プロジェクトのディレクトリでpipenv installでほしいバージョンを指定すると
pyenvですでにインストールしていない場合、インストールするか聞いてくる。

$ cd your_project
$ pipenv install --python 3.7
Warning: Python 3.7 was not found on your system…
Would you like us to install CPython 3.7.6 with pyenv? [Y/n]:y

PipfileとPipfile.lockが生成されている。

$ pipenv shell
(your_project) $ python -V
Python 3.7.6
(your_project) $ pyenv versions
  system
  3.7.6
* 3.8.1 (set by PYENV_VERSION environment variable)

無事イケそうです。

参考

https://qiita.com/mashita1023/items/10239f5621ef2fc8acb9
https://qiita.com/foewhoew32f320/items/bfa90ae1003e45cefe33
https://github.com/pypa/pipenv/issues/3488
https://github.com/pyenv/pyenv/tree/4e0ba2f47d97acd1284439cff57af059ce376b9d#installation


  1. ちゃんと消えてるかはしりません 

10
4
1

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
10
4