Overview
Pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
Steps
- Update brew
Terminalbrew update
- Install zlib sqlite xz installed on your machine
Terminalbrew install zlib sqlite xz
- Brew install Pyenv
Terminalbrew install pyenv
- Restart the terminal for changes to take effect or run
exec "$SHELL"
Terminalexec "$SHELL"
- Add exports to the current terminal window
The zlib compression algorithm and the SQLite database are dependencies for pyenv and often cause build problems when not configured correctly. Add these exports to your current terminal window to ensure the installation completes:
Terminalexport LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib"export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include"
- Check out some available versions of python > 3.9.*
Terminalpyenv install --list | grep 3.9.
- Install python 3.9.4
It will take some time to finish the installation.
Terminalpyenv install 3.9.4
- Make 3.9.4 as global python version
Terminalpyenv global 3.9.4
- Check the version
Terminalpyenv version
You should see 3.9.4 (set by /Users/youngjaelim/.pyenv/version)
.
- Configure
.zshrc
```bash echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init --path)" eval "$(pyenv init -)"\nfi' >> ~/.zshrc ```The power of pyenv comes from its control over our shell's path. In order for it to work correctly, we need to add the following to our configuration file (.zshrc for me, possibly .bash_profile for you)
- Check to make sure .zshrc updated
Terminalcat ~/.zshrc
- Restart the terminal for changes to take effect or run exec "$SHELL".
Terminalexec "$SHELL"
- Check python version
Terminalpython -V
- Upgrade the pip and setuptools packages
To avoid the persistent warning about upgrading the pip package, it would be best if you upgrade the pip package.
Terminalpip install -U pip setuptoolspip list
Comments