Try

Or browse

    macOSPython

    Managing Python on macOS Big Sur

    Managing Python on macOS Big Sur

    Upgrade Python on macOS Big Sur using pyenv. Install Python 3.9.1 and update pip for smoother management.

    Suggest editsRSSFollow on Google

    When Apple releases a new version of macOS it always takes a few months for everything to catchup, following my last blog post where I mentioned that I was having problems installing Python on macOS Big Sur↗which meant that my preferred method of installing and managing Python using pyenv, which is documented in this blog post↗, didn’t work out of the box - and the workarounds suggested workarounds on GitHub made my shell really slow.

    Luckily, I noticed that there was an update to both Python↗ andpyenv when I ran brew update today so decided to give pyenv another try, and it worked as expected.

    First I manually installed some prerequisites suggested on various GitHub issues, just to be on the safe side:

    Install some prerequisites
    ``` terminfo
    brew install zlib sqlite bzip2 libiconv libzip
    Next up you can either install or upgrade to the latest version of `pyenv`, which during writing is `1.2.22`:
    ```bash frame="terminal" title="Install pyenv"
    ``` terminfo
    brew install pyenv
    If like me, you need to upgrade, then you can run:
    ```bash frame="terminal" title="Upgrade pyenv"
    ``` terminfo
    brew upgrade pyenv
    Once the latest version `pyenv` has been installed, run the following commands to install the latest stable version of Python, which is currently 3.9.1:
    ```bash frame="terminal" title="Install Python 3.9.1 using pyenv"
    ``` terminfo
    pyenv install 3.9.1
    pyenv global 3.9.1
    pyenv version
    Once installed, run the following command to make sure that the `pyenv` managed version of Python is picked up:
    <InfoCallout title="Info">
    **Update: 11/06/2021;** the command below has been updated to include a change to how the "pyenv init" command works.
    </InfoCallout>
    ```bash frame="terminal" title="Make sure the pyenv version is used"
    ``` terminfo
    echo -e $'if command -v pyenv 1>/dev/null 2>&1; then\\n export PYENV_ROOT="$HOME/.pyenv"\\n export PATH="$PYENV_ROOT/bin:$PATH"\\n eval "$(pyenv init --path)"\\n eval "$(pyenv init -)"\\nfi' >> ~/.zshrc
    Open a new shell and run:
    ```bash frame="terminal" title="Check the python version"
    ``` terminfo
    python --version
    which python
    This should return something like the following:
    ```bash frame="terminal" title="Output of the commands"
    $ python --version
    Python 3.9.1
    $ which python
    /Users/russ.mckendrick/.pyenv/shims/python

    The final step is to make sure that pip is up-to-date, to do this run:

    Update pip
    ``` terminfo
    pip install --upgrade pip
    This fixed a few issues I had when I ran:
    ```bash frame="terminal" title="Install Ansible"
    ``` terminfo
    pip install --user ansible
    Which meant that I didn't need to use [my custom container anymore](/2020/12/28/ansible-azure-and-macos-big-sur/).
    Share

    Related terms: Command-Line InterfaceCondaDotfilesFLUXHosts FileOllama

    Comments