Python is my first programming 'crush' since high school until college forced me to love PHP. Now I want to look back at Python and see the growth since then. The first obvious thing to do is installing the python interpreter on my (windows) machine. But I've heard of a tool that can switch between python versions. This mechanism is useful if something unexpected happened to like the installed version is too recent but we also need it for creating new fresh projects. The case for NodeJS technology is Node Version Manager (NVM) and I think Pyenv is the equivalent tool for Python. So let's try it instead of installing a normal python interpreter.
When installing any programs on a Windows machine, using Chocolatey should be the best choice. Make you already installed Chocolatey in your machine. If not, then see the official instruction to install chocolatey. As instructed in the installation guide, we can install Pyenv using Chocolatey by opening PowerShell terminal with Administrator mode and execute the command:
choco install pyenv-win
If you are running Windows 10 1905 or newer, you might need to disable the built-in Python launcher via Start > "Manage App Execution Aliases" and disabling the "App Installer" aliases for Python.
After it successfully installed, try to close the PowerShell terminal and open it again with normal mode. Try to execute
pyenv --version to check the installation.
If you see the pyenv version outputted, then it was OK. If not, try to manually configure the PATH by following the instruction.
These are what makes it works in my machine:
To check any available version that can be installed, execute the command:
pyenv install --list
You should see the list of versions that can be installed. In my case, the
3.8.3 was the latest, and let's install it by command:
pyenv install 3.8.3
Installing this will output the progress in the CLI and open up an installer GUI. Follow and finish the installation.
To make sure the version was installed, check it with:
If it was there, then we can use it as a global and local interpreter by executing these:
pyenv global 3.8.3
pyenv local 3.8.3
The important thing after we change the version and setting the global and local interpreter, we have to execute this inside your home directory:
Then when you execute
python in CLI, you should be inside the python shell already.
Adding another version is exactly doing the previous steps but with the different versions. Try to install the other version using
pyenv install <version>, then set global and local using
pyenv global <version> and
pyenv local <version>, don't forget to
pyenv rehash to apply the change.
The title might confuse you, but here is my case: I have installed
3.8.3 and installed
pipenv on it with version
2020.8.*, but when I installed and switch to python
3.6.3 along with installing
pipenv with a newer version
pipenv executable still use the
2020.8.&. This was caused by the path value for executable python still use the version
So, you can tackle this problem by manually set to use Python36.
Have fun exploring Pyenv.