LoginSignup
0
0

More than 3 years have passed since last update.

WSL2でpipenv installができないときのメモ

Posted at

概要

  • WSL2でPythonを使っている
  • WindowsではPythonを使っていない
  • pipenvがうまく動かない

詳細

WSL2でpipenv installをつかうと以下の様なエラーがでた。

~/d/jupyter ❯❯❯ pipenv install 
['Traceback (most recent call last):\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/misc.py", line 159, in _create_subprocess\n    c = _spawn_subprocess(cmd, env=env, block=block, cwd=cwd,\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/misc.py", line 134, in _spawn_subprocess\n    return subprocess.Popen(cmd, **options)\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/subprocess.py", line 854, in __init__\n    self._execute_child(args, executable, preexec_fn, close_fds,\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/subprocess.py", line 1702, in _execute_child\n    raise child_exception_type(errno_num, err_msg, err_filename)\n', "OSError: [Errno 8] Exec format error: '/c/Users/xxxx/AppData/Local/Microsoft/WindowsApps/python.exe'\n", '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/contextmanagers.py", line 150, in spinner\n    yield _spinner\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/misc.py", line 304, in run\n    return _create_subprocess(\n', '  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/misc.py", line 162, in _create_subprocess\n    sys.stderr.write("Error %s while executing command %s", exc, " ".join(cmd._parts))\n', 'TypeError: write() takes exactly one argument (3 given)\n']
Traceback (most recent call last):
  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/misc.py", line 159, in _create_subprocess
    c = _spawn_subprocess(cmd, env=env, block=block, cwd=cwd,
  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pipenv/vendor/vistir/misc.py", line 134, in _spawn_subprocess
    return subprocess.Popen(cmd, **options)
  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/home/xxxx/.pyenv/versions/3.8.1/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/c/Users/xxxx/AppData/Local/Microsoft/WindowsApps/python.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

Windows側にPythonを入れていないのにPythonのパスがある。
これはWindowsStore用のPythonリンクに繋がっている。

どうもWSL内からコマンドを叩いてもWindows側のコマンドが優先される様子。

対応方法

python.exeを削除する。
しかしエクスプローラーからだとエラーが出て削除できないので、管理者権限のプロンプトから削除を行う。

管理者権限cmd
cd C:\Users\xxxx\AppData\Local\Microsoft\WindowsApps
del python.exe
del python3.exe

参考

https://github.com/pypa/pipenv/issues/3488

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