Once you have decided that Python is an awesome language to learnand you have heard all about the the cool featuresawaiting you, you are determined to install the latest versions on your laptop so that you can startdeveloping.
Mac comes with Python 2.7 pre-installed, but some newer AI libraries prefer you use Python 3+. Here's how to configure your Mac so that you can easily install any version of Python. If you're a Ruby developer, you'll likely understand the power behind Ruby Version Manager or rbenv. The version of Python that ships with OS X is great for learning, but it’s not good for development. The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version. With these different applications, it is often necessary to install a specific version of python so that the libraries used can work correctly. So we will see how to determine the version of python installed on the OS. To get the python version, we need access to a terminal. To do this here is how to do it on each operating system. Show activity on this post. Changing the default python executable's version system-wide could break some applications that depend on python2. However, you can alias the commands in most shells, Since the default shells in macOS (bash in 10.14 and below; zsh in 10.15) share a similar syntax. You could put alias python='python3' in your /.profile, and then source /.profile in your /.bashprofile and/or your.
If you have both Python2 and Python3 installed on your Mac, you can use. Python -version to check the version of Python2,. Python3 -version to check the version of Python3. However, if only Python3 is installed, then your system might use python instead of python3 for Python3. In this case, you can just use. Python -version.
- What’s New In Python 3.6 - December 23, 2016
- What’s New In Python 3.5 - September 13, 2015
- What’s New In Python 3.4 - March 16, 2014
- What’s New In Python 3.3 - September 29, 2012
- What’s New In Python 3.2 - February 20, 2011
- What’s New In Python 3.1 - June 27, 2009
- What’s New In Python 3.0 - December 3, 2008
- What’s New In Python 2.7 - July 3, 2010
- What’s New In Python 2.6 - October 1, 2008
You may be a little concerned about the differences between Python 2 and Python 3, so you wantto make sure that you have the latest versions of each available. This will enable you to switchbetween them easily and work on porting Python 2 programs to Python 3.
OS vendor Python versions lag behind the latest available and can only be updated by installing amajor patch or bolting-on an additional Python installation:
OS Version | System Python Version |
---|---|
OSX 10.13 | 2.7.10 |
OSX 10.12 | 2.7.10 |
OSX 10.11 | 2.7.10 |
Ubuntu 16.04 LTS Xenial Xerus | 2.7.11 |
Ubuntu 14.04 LTS Trusty Tahr | 2.7.5 |
Ubuntu 12.04 LTS Precise Pangolin | 2.7.3 |
Python 3 Mac
One way to work around this issue is to use
pyenv
to install theversions of Python you want to use. This tool provides a simplified build environment for installingthe Pythons you want, while providing a set of shell script shims that makes it easy to switch betweenthem. This tool was inspired by and forked from rbenv
andruby-build
.Install Python with pyenv¶
- Start a Terminal session.
- Install Homebrew and Xcode Command Line Tools.
- Install
pyenv
. - If you already have
pyenv
installed, you can upgrade it to gain access to the latest Pythonversions. Thepyenv
tool is updated periodically with new formulas for the latest releases. - Add configuration to your
.bash_profile
to initializepyenv
every time you start a newTerminal. ThePYENV_ROOT
, which is where Python versions and packages will be installed,defaults to$HOME/.pyenv
. - Load your
.bash_profile
configuration changes. - Mkv converter mac freeware. List the available Python versions. Notice that you have access to several differentdistributions: python.org (plain version numbers), anaconda, ironpython, jython, miniconda,pypy and stackless. We will install the standard Python versions released bypython.org, otherwise known as CPython, because theinterpreter is written in C.
- If you are running OSX 10.13, you will need to set the following environment variables, when youinstall new Python versions. See #988 for more details.
- Install Python versions.
- List the available Python versions.
- Activate a Python version and verify that it is available.
- Activate another Python version and verify that it is available.
- If desired, activate multiple Python versions and verify that they are available.PEP 394 -- The 'python' Command on Unix-Like Systemsexplains conventions for naming
python
binaries. - Create new directories for Python projects, add
pyenv local
version files and verify the Pythonversions. Yourpython
version will automatically switch when you change into these directories.
Useful Python Packages¶
This is a small collecton of useful packages that will help get you started doing useful thingswith Python.
Install flake8, which is a static analyzer that enforcesgood Python coding style and alerts you to coding mistakes. Now that you have Python installed,you can use the
pip
command to install any additional modules that you want to use. You willneed to install modules separately for each version of Python you are actively using.Install advanced Python Read-Eval-Print-Loop (REPL) packages, which will make it easier to explorePython code, because they grant access to tab completion and fancy editing capabilities. The
ipython
tool is a command line REPL, which can be exited with ctrl-d
. Jupyter Notebook is a browser-basedREPL that operates on individual cells of code. The IPython Interactive Computingwebsite has more information on these tools.Install Requests: HTTP for Humans, which makes it easyto consume HTTP services. See GitHub's REST API v3 documentationfor more details on endpoints that are avaialble.
Install Flask: A Python Microframework, which can be used to quickly buildsmall websites that automate everyday tasks.
If you need Python package isolation on a per-project basis, because you have conflicting setsof packages specified for different projects, you can use virtualenvto set up separate environments. The
virtualenv
tool establishes a clean room Python installation,either based upon the current version of Python in use, or a version specified on the command line.If you have multiple Python versions activated in pyenv
, you can use virtualenv
to switch betweenthem easily.Automated Testing with Python¶
While working on Python programs, you may be interested in automating testing. The most commonchoice for implementing this is tox, which willallow you to run tests with multiple different versions of Python, if needed.
Python 3.8 Mac
Python Packaging¶
After completing a Python program or two, you will be interested in learning how to distribute themeffectively. The Python Packaging User Guide has some good adviceon this topic.