Help us understand the problem. What is going on with this article?

python3 開発環境構築 on WSL

More than 1 year has passed since last update.


  • 気づいたらすでに python も python3 もインストールされていましたが pyenv で python をインストールして使うように設定してみました
  • 以下をインストールしてパスを通します
    • pyenv
    • pipenv
    • python3
  • ※すでに rails な開発環境は導入済なので以下の手順の通り実施しても何かしらライブラリ不足があるかもしれません


  • Windows10
  • ubuntu 18.04 on WSL
  • fish

install pyenv

$ git clone ~/.pyenv
$ echo 'set PATH $HOME/.pyenv/bin $PATH' >>  ~/.config/fish/
$ echo 'eval (pyenv init - | source)' >>  ~/.config/fish/
$ eval (pyenv init - | source)
$ which pyenv

install python3.7.0

  • インストールできるバージョンを確認
$ pyenv install --list
  • 現在時点での最新の3.7.0 をインストールしてみる
$ pyenv install -v 3.7.0
  • しばらく待った後以下のエラーで失敗
Traceback (most recent call last):
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/", line 85, in _run_code
    exec(code, run_globals)
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/ensurepip/", line 5, in <module>
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/ensurepip/", line 204, in _main
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/ensurepip/", line 117, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/ensurepip/", line 27, in _run_pip
    import pip._internal
  File "/tmp/tmpirqvyjxt/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 42, in <module>
  File "/tmp/tmpirqvyjxt/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 16, in <module>
  File "/tmp/tmpirqvyjxt/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 25, in <module>
  File "/tmp/tmpirqvyjxt/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/", line 39, in <module>
  File "/tmp/tmpirqvyjxt/pip-10.0.1-py2.py3-none-any.whl/pip/_internal/utils/", line 3, in <module>
  File "/tmp/python-build.20180910235918.12705/Python-3.7.0/Lib/ctypes/", line 7, in <module>
    from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Makefile:1122: recipe for target 'install' failed
make: *** [install] Error 1

BUILD FAILED (Ubuntu 18.04 using python-build 1.2.7-3-g5603eb51)
  • モジュールが足りないのでインストールする
$ sudo apt install libffi-dev
  • リトライ
$ pyenv install -v 3.7.0


Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
/tmp/python-build.20180911001219.25285 ~
Installed Python-3.7.0 to /home/ospear/.pyenv/versions/3.7.0
  • インストール成功
$ which python
$ pyenv global 3.7.0
$ python --version
Python 3.7.0

install pipenv

$ which pip
$ pip --version
pip 10.0.1 from /home/yourname/.pyenv/versions/3.7.0/lib/python3.7/site-packages/pip (python 3.7)
$ pip install --upgrade pip
$ pip --version
pip 18.0 from /home/yourname/.pyenv/versions/3.7.0/lib/python3.7/site-packages/pip (python 3.7)
$ pip install pipenv
$ which pipenv
$ pipenv --version
pipenv, version 2018.7.1


Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away