This instructions will guide you to properly install PyEnv and PyEnv-VirtualEnv on macOS. PyEnv allows you to install and switch between multiple versions of Python. Combined with VirtualEnv you can manage Python environments from any of you installed Python versions. Then you can set any of your Python versions and enviroments easily and access them direclty (e.g., using Visual Studio Code).
This tutorial has four sections:
- Preparing the environment
- Installing PyEnv
- Installing PyEnv-VirtualEnv
- Testing the installation and getting used
This is a tool, developed by Apple, which install all the requierements and developer tools on mac. To install it, just open a new terminal window and run:
xcode-select --install
The a window pop-up to confirm the installation. It will take time to finish depending on your internet connection.
Visual Studio Code is a powerful code editor. I strongly suggest to use it, but you can omit this step if you want to use another one. Just enter to VSCode Download link and follow the installation.
Click on packages in the left side of VSCode and look for the following packages: - Python - Jupyter
- Note: both installations will install more dependecies
Homebrew is the easiest and most flexible way to install the UNIX tools Apple didn’t include with macOS. You can check the installation directly on Homebrew webpage or just run the following line on terminal.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Now we will use the recently installed homebrew, which comes with the brew command. In this case just run the following two commands one by one.
brew update
brew install pyenv
Run the following commands one by one:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
brew install xz
Run on a terminal:
brew install pyenv-virtualenv
Finally restart your computer.
(I need to check if you will need an extra step)
The following line will be installing Python3.11.5
pyenv install 3.11.5
The following line will create a test env using 3.11.5
pyenv virtualenv 3.11.5 test
pyenv shell test
pyenv versions
Can you send me an screenshot here (of your terminal)