How to Download Python 3.6 Mac
MacOS comes with Python pre-installed. But it'southward Python Version ii.7, which is now deprecated (abandoned by the Python developer community).
The unabridged Python customs has now moved on to using Python iii.x (the current version every bit of writing this is 3.9). And Python 4.ten will be out soon, but it will be completely backward compatible.
If y'all try to run Python from your MacOS terminal, you'll even see this alarm:
Until Apple decides to prepare Python 3.10, as the default you're going to have to install information technology yourself.
A Single Command to Run Python 3
For some of you lot reading this, this command may be enough. You tin run Python 3 using this command (with the 3 at the finish).
python3 If that'south all you came for, no worries. Have a fun twenty-four hours and happy coding.
But if you lot want a proper Python version command arrangement to proceed track of diverse versions – and have fine-grain control over which version you use – this tutorial will evidence you exactly how to accomplish this.
How to Install Homebrew on Mac
Starting time you need to install Homebrew, a powerful package managing director for Mac.
Open up your concluding. You tin do this past using MacOS spotlight (command+space) and typing "terminal".
At present that you're in a command line, you tin can install the latest version of Homebrew by running this control:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/Head/install.sh)" Your concluding will ask for Super User-level admission. You lot volition need to blazon your password to run this command. This is the same password you type when you lot log into your Mac. Type it and striking enter.
Homebrew volition enquire y'all to confirm you want to install the post-obit. You lot take to printing enter to continue. (Or press any other key if you get cold feet.)
How to Install pyenv to Manage Your Python Versions
At present let's take a moment to install PyEnv. This library will aid yous switch between unlike versions of Python (in case you need to run Python 2.ten for some reason, and in anticipation of Python 4.0 coming).
Run this control:
brew install pyenv
Now you can install the latest version of Python.
How to Apply pyenv to Install Python or Update Your Python Version
Now yous but need to run the following command:
pyenv install 3.9.2 Notation that y'all can substitute three.9.ii for whatever the latest version of Python is. For example, once Python 4.0.0 comes out, you can run this:
pyenv install 4.0.0 Troubleshooting pyenv Installation
If you encounter an fault that "C compiler cannot create executables" then the simplest way to solve this is to reinstall Apple's Xcode.
Xcode is a tool created past Apple that includes all the C libraries and other tools that Python uses when it runs on MacOS. Xcode is a whopping 11 gigabytes, only you'll want to be up-to-appointment. You may want to run this while you're sleeping.
You tin can become the latest version of Apple tree'due south Xcode hither. I had to do this later upgrading to MacOS Big Sur, only once I did, all the following commands worked fine. Just re-run the to a higher place pyenv install 3.ix.two and it should at present piece of work.
How to Ready Your MacOS PATH for pyenv (Bash or ZSH)
First you need to update your Unix path to pave a mode for PyEnv to be able to interact with your organisation.
This is a long explanation of how PATH works in MacOS (and Unix), straight from the pyenv GitHub repo.
When you lot run a command similarpythonorpip, your operating organization searches through a listing of directories to find an executable file with that name. This list of directories lives in an environs variable chosenPATH, with each directory in the listing separated past a colon:
/usr/local/bin:/usr/bin:/bin Directories inPATHare searched from left to right, and so a matching executable in a directory at the offset of the list takes precedence over another i at the end. In this example, the/usr/local/bindirectory volition be searched first, then/usr/bin, then/bin.
And hither is their explanation of what a Shim is. I'thousand quoting them at length over again considering I actually tin can't explain this ameliorate 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 called rehashing, pyenv maintains shims in that directory to match every Python control across every installed version of Python—python,pip, and then on.
Shims are lightweight executables that simply pass your command along to pyenv.
Here's how to update your .bash_profile in Bash (which is installed in MacOS by default):
echo 'export PYENV_ROOT="$Habitation/.pyenv"' >> ~/.bash_profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile Or if y'all've installed ZSH (or OhMyZSH) similar I accept, you'll want to edit the .zshrc file instead:
repeat 'export PYENV_ROOT="$Dwelling house/.pyenv"' >> ~/.zshrc repeat 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc Then you desire to add PyEnv Init to your final. Run this command if y'all're using Fustigate (again, this is the default with MacOS):
echo -due east 'if command -v pyenv i>/dev/null 2>&i; then\northward eval "$(pyenv init -)"\nfi' >> ~/.bash_profile Or run this command if you lot're using ZSH:
echo -due east 'if command -v pyenv ane>/dev/null two>&ane; then\n eval "$(pyenv init --path)"\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc Now reset your last past running this command:
reset How to Set a Version of Python to Global Default (Bash or ZSH)
You can set the latest version of Python to be global, meaning information technology will be the default version of Python MacOS uses when you run Python applications.
Run this control:
pyenv global 3.9.two Again, yous tin can replace 3.9.two with whatever the latest version is.
Now you can verify that this worked past checking the global version of Python:
pyenv versions You should see this output:
The Final Footstep: Close Your Last and Restart it
Once you've restarted your last, you run the python command and you'll launch the new version of Python instead of the former i.
Congratulations. Thank you for reading this, and happy coding.
Larn to code for free. freeCodeCamp'southward open source curriculum has helped more than than 40,000 people get jobs equally developers. Go started
How to Download Python 3.6 Mac
Posted by: gutierrezgairciand.blogspot.com

0 Komentar
إرسال تعليق