hakopako

Full-stack Engineer's blog

How to use pyenv with cygwin - windows

日本語 | English

On Linux or MacOS, we can install and set up pyenv with prepared commands such as "brew". However, Windows doesn't go that way. The reason is that python-build doesn't work on windows. We can use pyenv with cygwin by doing that process ($ pyenv install X.X.X ) manually.

install pyenv

Clone github repository, and set PATH.

# Cygwin
$ cd  
$ git clone https://github.com/pyenv/pyenv.git .pyenv     
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> .profile  
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> .profile  
$ echo -e 'eval "$(pyenv init -)"' >> .profile  
$ source .profile
$ pyenv versions
* system (set by /home/XXXXXXXXX/.python-version)

This error might occur.

/path/to/.pyenv/bin/pyenv: line 1: ../libexec/pyenv: No such file or directory

This is because of "Failed to create symbolic link". So just do it manually like below.

$ cd
$ touch /bin/readlink  
$ rm -rf ~/.pyenv/bin/pyenv   
$ ln -s ~/.pyenv/libexec/pyenv ~/.pyenv/bin/pyenv  

Check if pyenv works.

$ pyenv versions
* system (set by /home/XXXXXXXXX/.python-version)

pyenv install X.X.X

As I mentioned earlier, python-build doesn't work on windows. Do that process manually (I couldn't find any other good way...).

Version 2.X

  • Download Python Installer from official page.
    Windows x86-64 MSI installer: https://www.python.org/downloads/release/python-2712/
  • Launch the installer and set the install path to pyenv directory.
    PATH: /path/to/.pyenv/versions/2.7.12
  • Probably creating a symbolic link is failed. Do it manually like below.
$ cd .pyenv/versions/2.7.12
$ mkdir bin && cd bin
$ ln -s ../python.exe python

Check the behavior.

$ cd
$ pyenv local 2.7.12
$ pyenv versions
  system
* 2.7.12 (set by /home/XXXXXXXXX/.python-version)
$ python -V
Python 2.7.12

Version 3.X

Version 3.X is also able to be installed with the installer from official page as same as version 2.X. However, as for version 3.X, here is another solution.

"Embeddable file" is distributed officially. Therefore, what we do is decompress the file and put it to pyenv directory.

  • Download embeddable zip file
    Windows x86-64 embeddable zip file: https://www.python.org/downloads/release/python-362/
  • Decompress the file and put it to pyenv directory.
    PATH: /path/to/.pyenv/versions/3.6.2
  • Probably creating a symbolic link is failed. Do it manually like below.
$ cd .pyenv/versions
$ mv /path/to/python-3.6.2-embed-amd64 3.6.2
$ mkdir 3.6.2/bin && cd 3.6.2/bin
$ ln -s ../python.exe python

Check the behavior.

$ cd
$ pyenv local 3.6.2
$ pyenv versions
  system
  2.7.12
* 3.6.2 (set by /home/XXXXXXXXX/.python-version)
$ python -V
Python 3.6.2

 

That is all.