[python] How to downgrade python from 3.7 to 3.6

pyenv can be used in Linux/MacOS for python version management. pyenv-win is the fork of pyenv which can be used on Windows.

Installation

MacOS

Tested on Mac Catalina

  1. Install pyenv.

    brew install pyenv
    
  2. Add following to your shell config file:

    • .bashrc/.bash_profile - For Bash
    • .zshrc - For Zsh
    export PYENV_ROOT="$HOME/.pyenv"
    export PATH="$PYENV_ROOT/bin:$PATH"
    eval "$(pyenv init -)"
    
  3. Restart your shell. Start a new shell or run exec "$SHELL" in your current shell.

Linux / Windows on Linux Subsystem

Tested on Arch Linux

  1. Install pyenv on your system.

    curl https://pyenv.run | bash
    
  2. Follow same steps as in Step 2 and 3 of MacOS installation.

Windows

  1. Install pyenv-win on Windows.

    In Powershell

    pip install pyenv-win --target "$HOME\.pyenv"
    

    In cmd.exe

    pip install pyenv-win --target "%USERPROFILE%\.pyenv"
    
  2. Setup the environment variables using Powershell/Terminal.

    [System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
    [System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
    [System.Environment]::SetEnvironmentVariable('path', $HOME + "\.pyenv\pyenv-win\bin;" + $HOME + "\.pyenv\pyenv-win\shims;" + $env:Path,"User")
    
  3. Close and re-open your terminal. Run pyenv --version on the terminal.

    a. If the return value is the installed version of pyenv, then continue below. b. If you receive a command not found error, ensure the environment variables are properly set via the GUI: This PC ? Properties ? Advanced system settings ? Advanced ? Environment Variables... ? PATH c. If you receive a command not found error and you are using Visual Studio Code or another IDE with a built in terminal, restart it and try again.

  4. Run pyenv rehash from the home directory.

Usage

Check installed python versions

pyenv versions

Example

$ pyenv versions
* system (set by /home/souser/.pyenv/version)
  3.6.9

Installed a specific python version

pyenv install <version-number>

Uninstall an installed python version

pyenv uninstall <version-number>

Set a python version as system-wide python version

pyenv global <version-number> # <version-number> is the name assigned to your python in output of `pyenv versions`

Example

$ python --version
Python 3.9.1
$ pyenv global 3.6.9
$ python --version
Python 3.6.9
Set a python version for a directory and all it's sub-directories
pyenv local <version-number> # <version-number> is the name assigned to your python in output of `pyenv versions`

Example

~/tmp/temp$ python --version
Python 3.9.1
~/tmp/temp$ pyenv local 3.6.9
~/tmp/temp$ python --version
Python 3.6.9

For more details, you can check the Github repos : pyenv and pyenv-win.