How to Download Python 3.6 on Mac Updated

How to Download Python 3.6 on Mac

How to Install Python 3 on Mac – Brew Install Update Tutorial

MacOS comes with Python pre-installed. But information technology'due south Python Version two.7, which is now deprecated (abased by the Python developer customs).

The unabridged Python community has now moved on to using Python three.x (the current version as of writing this is three.9). And Python 4.10 will be out before long, but it will exist completely backward compatible.

If yous endeavor to run Python from your MacOS last, you'll even meet this warning:

freecodecamp_-_freecodecamp_MacBook-Pro_-___-_-zsh_-_84-24-1
Alert: Python 2.vii is not recommended. This version is included in macOS for compatibility with legacy software. Time to come versions of macOS will non include Python 2.7. Instead, it is recommended that yous transition to using 'python3' from within Terminal.

Until Apple decides to set Python 3.x, as the default you're going to have to install it yourself.

A Single Command to Run Python three

For some of yous reading this, this command may be enough. You can run Python 3 using this control (with the 3 at the end).

                python3              

If that's all you came for, no worries. Accept a fun day and happy coding.

But if you lot want a proper Python version control system to keep track of diverse versions – and have fine-grain command over which version you use – this tutorial will bear witness you exactly how to attain this.

Megaman-810x600
Past the mode, if y'all're wondering why I keep referring to Python three.x – the x is a stand-in for sub-versions (or bespeak releases as developers call them.) This means any version of Python 3.

How to Install Homebrew on Mac

First you need to install Homebrew, a powerful parcel director for Mac.

Open up your last. You can do this past using MacOS spotlight (command+infinite) and typing "concluding".

Now that you're in a command line, you can install the latest version of Homebrew past running this command:

                /bin/fustigate -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/Head/install.sh)"              

Your terminal volition ask for Super User-level access. Yous will need to type your countersign to run this command. This is the aforementioned password you lot type when yous log into your Mac. Type information technology and hit enter.

freecodecamp_-__bin_bash_-c__-__bin_bash_-_sudo_-_bash_-c____bin_bash_012set_-u_012_012abort___-_012__printf___s_n_______012__exit_1_012-_012_012if___-z___-BASH_VERSION_--_____then_012__abort__Bash_is_required_to_interpret_this_script___012
A screenshot of my heavily customized terminal. Your terminal will probably look different from this.

Homebrew will ask you lot to confirm you want to install the following. Yous have to press enter to proceed. (Or press any other key if you go cold anxiety.)

freecodecamp_-__bin_bash_-c__-__bin_bash_-_bash_-c____bin_bash_012set_-u_012_012abort___-_012__printf___s_n_______012__exit_1_012-_012_012if___-z___-BASH_VERSION_--_____then_012__abort__Bash_is_required_to_interpret_this_script___012fi_012_

How to Install pyenv to Manage Your Python Versions

Now permit'due south take a moment to install PyEnv. This library volition assistance you switch betwixt dissimilar versions of Python (in example you need to run Python ii.10 for some reason, and in anticipation of Python 4.0 coming).

Run this command:

                mash install pyenv              
freecodecamp_-_freecodecamp_MacBook-Pro_-___-_-zsh_-_90-24
PyEnv installing

Now you can install the latest version of Python.

How to Use pyenv to Install Python or Update Your Python Version

Now y'all but need to run the post-obit command:

                pyenv install 3.nine.2                              

Annotation that you can substitute 3.ix.2 for whatever the latest version of Python is. For example, once Python iv.0.0 comes out, y'all tin run this:

                pyenv install 4.0.0              

Troubleshooting pyenv Installation

If you lot encounter an error that "C compiler cannot create executables" then the simplest way to solve this is to reinstall Apple'due south Xcode.

Xcode is a tool created by Apple that includes all the C libraries and other tools that Python uses when it runs on MacOS. Xcode is a whopping eleven gigabytes, but y'all'll desire to be up-to-date. You may desire to run this while you lot're sleeping.

You tin can get the latest version of Apple'southward Xcode here. I had to do this after upgrading to MacOS Big Sur, but one time I did, all the following commands worked fine. Merely re-run the higher up pyenv install 3.9.ii and information technology should now work.

How to Set up Upward Your MacOS PATH for pyenv (Bash or ZSH)

Start y'all need to update your Unix path to pave a way for PyEnv to be able to interact with your system.

This is a long explanation of how PATH works in MacOS (and Unix), straight from the pyenv GitHub repo.

When you run a control like python or pip, your operating system searches through a list of directories to find an executable file with that name. This list of directories lives in an environment variable called PATH, with each directory in the list separated past a colon:
                /usr/local/bin:/usr/bin:/bin                              
Directories in PATH are searched from left to correct, and so a matching executable in a directory at the beginning of the list takes precedence over some other one at the end. In this case, the /usr/local/bin directory will be searched get-go, so /usr/bin, and so /bin.

And here is their explanation of what a Shim is. I'grand quoting them at length again considering I actually can't explain this improve myself.

pyenv works by inserting a directory of shims at the forepart of your PATH:
                $(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin                              
Through a process chosen rehashing, pyenv maintains shims in that directory to match every Python command across every installed version of Python—python, pip, and then on.
Shims are lightweight executables that simply pass your command along to pyenv.

Hither'due south how to update your .bash_profile in Bash (which is installed in MacOS past default):

                echo 'consign PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile              

Or if you've installed ZSH (or OhMyZSH) like I have, yous'll desire to edit the .zshrc file instead:

                repeat 'export PYENV_ROOT="$Dwelling/.pyenv"' >> ~/.zshrc echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc              

Then y'all desire to add PyEnv Init to your terminal. Run this command if you're using Fustigate (again, this is the default with MacOS):

                repeat -eastward 'if command -v pyenv one>/dev/cipher ii>&i; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile                              

Or run this command if you're using ZSH:

                echo -e 'if command -v pyenv one>/dev/nothing 2>&1; then\north  eval "$(pyenv init --path)"\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc              

Now reset your terminal by running this command:

                reset              

How to Prepare a Version of Python to Global Default (Bash or ZSH)

You lot can fix the latest version of Python to be global, pregnant it will exist the default version of Python MacOS uses when you run Python applications.

Run this command:

                pyenv global 3.9.two              

Again, you can supercede iii.9.2 with whatever the latest version is.

Now you can verify that this worked by checking the global version of Python:

                pyenv versions              

You should see this output:

freecodecamp_-_freecodecamp_MacBook-Pro_-_-zsh_-_84-24
The * means that version is now the global default

The Concluding Step: Shut Your Terminal and Restart it

Once you've restarted your terminal, you lot run the python command and yous'll launch the new version of Python instead of the old one.

freecodecamp_-_python_-_python_-_python_-_119-36
Yay. Python 3.9.ii and no deprecation warnings

Congratulations. Thank you for reading this, and happy coding.



Larn to code for free. freeCodeCamp's open source curriculum has helped more than than 40,000 people go jobs equally developers. Get started

How to Download Python 3.6 on Mac

Posted by: kershawbefornes.blogspot.com

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel