5. Using Python on a Mac¶
Python on a Mac running macOS is in principle very similar to Python on any other Unix platform, but there are a number of additional features such as the IDE and the Package Manager that are worth pointing out.
5.1. Getting and Installing MacPython¶
macOS used to come with Python 2.7 pre-installed between versions 10.8 and 12.3. You are invited to install the most recent version of Python 3 from the Python website (https://www.python.org). A current “universal binary” build of Python, which runs natively on the Mac’s new Intel and legacy PPC CPU’s, is available there.
What you get after installing is a number of things:
A Python 3.12 folder in your Applications folder. In here you find IDLE, the development environment that is a standard part of official Python distributions; and PythonLauncher, which handles double-clicking Python scripts from the Finder.
A framework /Library/Frameworks/Python.framework , which includes the Python executable and libraries. The installer adds this location to your shell path. To uninstall MacPython, you can simply remove these three things. A symlink to the Python executable is placed in /usr/local/bin/.
The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python , respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
IDLE includes a help menu that allows you to access Python documentation. If you are completely new to Python you should start reading the tutorial introduction in that document.
If you are familiar with Python on other Unix platforms you should read the section on running Python scripts from the Unix shell.
5.1.1. How to run a Python script¶
Your best way to get started with Python on macOS is through the IDLE integrated development environment, see section The IDE and use the Help menu when the IDE is running.
If you want to run Python scripts from the Terminal window command line or from the Finder you first need an editor to create your script. macOS comes with a number of standard Unix command line editors, vim and emacs among them. If you want a more Mac-like editor, BBEdit or TextWrangler from Bare Bones Software (see http://www.barebones.com/products/bbedit/index.html) are good choices, as is TextMate (see https://macromates.com/). Other editors include Gvim (https://macvim.org/macvim/) and Aquamacs (http://aquamacs.org/).
To run your script from the Terminal window you must make sure that /usr/local/bin is in your shell search path.
To run your script from the Finder you have two options:
Drag it to PythonLauncher
Select PythonLauncher as the default application to open your script (or any .py script) through the finder Info window and double-click it. PythonLauncher has various preferences to control how your script is launched. Option-dragging allows you to change these for one invocation, or use its Preferences menu to change things globally.
5.1.2. Running scripts with a GUI¶
With older versions of Python, there is one macOS quirk that you need to be aware of: programs that talk to the Aqua window manager (in other words, anything that has a GUI) need to be run in a special way. Use pythonw instead of python to start such scripts.
With Python 3.9, you can use either python or pythonw.
5.1.3. Configuration¶
Python on macOS honors all standard Unix environment variables such as PYTHONPATH , but setting these variables for programs started from the Finder is non-standard as the Finder does not read your .profile or .cshrc at startup. You need to create a file
/.MacOSX/environment.plist . See Apple’s Technical Document QA1067 for details.
For more information on installation Python packages in MacPython, see section Installing Additional Python Packages .
5.2. The IDE¶
MacPython ships with the standard IDLE development environment. A good introduction to using IDLE can be found at http://www.hashcollision.org/hkn/python/idle_intro/index.html.
5.3. Installing Additional Python Packages¶
There are several methods to install additional Python packages:
Packages can be installed via the standard Python distutils mode ( python setup.py install ).
Many packages can also be installed via the setuptools extension or pip wrapper, see https://pip.pypa.io/.
5.4. GUI Programming on the Mac¶
There are several options for building GUI applications on the Mac with Python.
PyObjC is a Python binding to Apple’s Objective-C/Cocoa framework, which is the foundation of most modern Mac development. Information on PyObjC is available from https://pypi.org/project/pyobjc/.
The standard Python GUI toolkit is tkinter , based on the cross-platform Tk toolkit (https://www.tcl.tk). An Aqua-native version of Tk is bundled with OS X by Apple, and the latest version can be downloaded and installed from https://www.activestate.com; it can also be built from source.
wxPython is another popular cross-platform GUI toolkit that runs natively on macOS. Packages and documentation are available from https://www.wxpython.org.
PyQt is another popular cross-platform GUI toolkit that runs natively on macOS. More information can be found at https://riverbankcomputing.com/software/pyqt/intro.
5.5. Distributing Python Applications on the Mac¶
The standard tool for deploying standalone Python applications on the Mac is py2app. More information on installing and using py2app can be found at https://pypi.org/project/py2app/.
5.6. Other Resources¶
The MacPython mailing list is an excellent support resource for Python users and developers on the Mac:
Python Install (Conda Anaconda Miniconda Pip) on MacOS
This tutorial describes the different options to install and uninstall Python within various package managers (which helps you find and install Python packages).
Here I’m taking a “deep dive” approach because I haven’t seen one on the internet.
NOTE: Content here are my personal opinions, and not intended to represent any employer (past or present). “PROTIP:” here highlight information I haven’t seen elsewhere on the internet because it is hard-won, little-know but significant facts based on my personal research and experience.
I’ve pulled out the various incantations suggested by others on StackOverlow and put them here in context.
TL;DR Summary — It’s a mess

The version of Python that comes with Apple MacOS is obsolete and needs to be updated along with Apple XCode CLI for the MacOS version you’re using.
This has given rise to several versions of Python frameworks being maintained in parallel. For example, the web application development framework for Python exists as both Django 1.3 and Django 1.0.
Adding to the confusion is that various methods of installing Python are incompatible with each other. This has given rise to the need for package managers such as pip (Python Installation Packager) that enable one to switch among different versions of Python installed.
MacOS does not come installed with a package manager for Python until pip.
pip (Python Installation Packager) is built on top of setuptools which is what downloads and installs Python packages from the PyPI (Python Package Index) library online at https://pypi.org.
Setuptools itself is installed using easy_install.
This complexity necessitates the packaging of whole virtual environments to isolate within a folder (directory) everything (all dependencies) that each Python project (application) needs to run. This means duplicated files for each Python application, which consume more disk space.
An additional complication is that there are several alternative virtual environment packagers such as easy_install, virtualenv, and pipenv.
-
(Python Installation Packager) is a package manager.
Virtualenv (venv) is an environment manager for Python.
Conda does both, and is language agnostic (not just for Python).
easy_install is an environment manager.
Python
Despite all this hassle around versioning, Python is the preferred language of Artificial Intelligence and Machine Learning at the forefront of computer science innovation today. The heavy use of math in AI and ML by TensorFlow means it’s best to install Anaconda and use conda commands (instead of Miniconda or pip with virtualenv).
PROTIP: PIP install is troublesome, often because they are more recent than those in Conda.
Python Install Options
There is what can be a confusing conflict of choice here for installing Python and its package manager.
-
Even though that’s the method described in various (obsolete) websites and books, NOT recommended is the manual approach of download Python installer from python.org: https://www.python.org/downloads/mac-osx
easy_install is an environment manager. One writes: “Avoid easy_install or pip to install a Python package that needs a library used by non Python programs, such as Qt bindings (PySide)” or Django*.
PROTIP: If you must use easy_install, delete it after.
Install using Homebrew, then add homebrew science for scientific work (according to this).
MacPorts is an alternative to Homebrew some claim is more compatible with other Linux. However, not all packages are available in MacPorts.
Use Docker
From Dockerhub account “python” get a Docker image on your machine containing Python3 running within Alpine Linux OS:
Build a container containing a small python environment:
Execute the container:
Use the container
Stop the Docker instance:
Obsolete Python comes with MacOS
Ever since the Mavericks version of Mac OSX, Python 2 comes installed on MacOS machines.
(Use the index at the right if you want to jump ahead)
Open a Terminal shell window and issue command:
The response, for example:
CAUTION: The sub-version of Python that comes installed with MacOS may be obsolete and needs to be upgraded. But keep to version 2, not version 3 of Python.
Find where Python2 is installed:
You may also see the following if you’ve installed a shim to enable switching of Python versions:
Folders Python on CLI
List your present working directory:
We next use a Python interactive command to obtain this again.
Open a Python command-line prompt:
python
The response shows that version 2 comes with MacOS:
The response on a new El Capitan machine:
>>> is the Python interpreter prompt.
Don’t enter or copy >>> when typing or copying Python commands.
Current Working Directory
Display Python’s current working directory:
In the response, the “mac” user name is substituted with your user name:
The above should be the same as the path obtained from pwd before entering Python.
>>> import os, sys
>>> os.path.dirname(os.path.abspath(sys.argv[0]))
The response is your home folder (substitue “mac” with your user name):
Exit Python
Exit the Python interpreter by typing the exit function (with the parentheses symbols):
The exit() commmand works the same for both Python 2 and Python 3.
Using Python 3
After installing Python3, obtain the Python 3 command line with:
python3
The response I got:
Python 3 vs. 2
Since 2018, many say “all new Python code should be written for version 3. There are so many new features in Python 3 that it doesn’t make much sense to stick with Python 2 unless you’re working with old code.”
Most new features introduced with Python 3 are not backwards compatible with version 2.
Where are Python executables?
Python3 is installed in a different folder than Python 2.
Get the location where Python is installed:
which python
which python3
- Python v2 is installed in /usr/bin/python
- Python v3 is installed in /usr/local/bin/python3
If you get /Users/user/.pyenv/shims/python3
Let’s see what’s there:
The result shows a link to where Homebrew stores:
Python command for Python3
Some prefer to If you want If you tried to commit suicide like the above, the work-around is an alias, which the operating system resolves before going down PATH.
To use Python3 as the default version for the python command, set in you Mac’s
Print is different in Python3
For the most part, Python 2 code works with Python 3.
Where Python 2 code fails most often is the print statement. Printing in Python 2 is done like so:
If you input the above in Python 3, the response is:
SyntaxError: Missing parentheses in call to ‘print’
This is because Python 3 uses a function:
So in Python 2.6+, use the future module to back-port:
Floating point
In Python 2, type in the REPL:
The response is:
In Python3, type:
The response is:
Python programming code
Download or view a Python program:
By convention, Python programming source files have a file suffix of .py regardless of the version. This is because, unlike on Windows, Linux looks at the first line of script files to identify what program is used to run the file.
The “shebang” first line in Python 2 programs start with:
This is an absolute file system path because the executor doesn’t look on the $PATH for the program defined in
The “shebang” first line in Python 3 programs start with:
env is an executable file from virtualenv.
Start a HTTP Server Using Python
A simple HTTP server service can be started with this Python 2 command:
python -m SimpleHTTPServer
python3 -m http.server
CAUTION: Hitting Ctrl-C on a Mac, does not shutdown the server gracefully, and the binded address will still be in use.
TODO: Add port designation in command line.
File handling using Pathlib
To create a new folder using Python3: TODO:
To create a new file using Python3, import the pathlib module’s Path object:
Don’t Uninstall Default Python on macs
The version of Python that comes with Mac OSX should not be removed because some Apple system software have hard-coded references to it.
In this bad advice to harm yourself:
Elevated privilages (sudo) are necessary to remove Python from your Mac
Remove symbolic links pointing to the python version:
Remove references to deleted paths in PATH environment variable within shell profile files.
Depending on which shell you use, any of the following files may have been modified:
List symbolic links pointing to the python version:
On El Capitan, this should display: a sym link such as:
Or if instead you followed some bad advice and see something like this:
List symbolic links pointing to the python version:
The “../../” means that it’s above your HOME folder, in the root of the Mac OS.
So let’s go there:
There are the executables “python” and “python2.7” plus others.
Run the generic python generically:
The response is a newer Python:
List symbolic links pointing to the Python version:
Upgrade Python
Install XCode CLI.
Download Python installer
If you must do it the hard way, bareback, etc:
Click the Latest link at the top or a
specific “Mac OS X 64-bit installer” for macOS 10,9+.
| File | Date | Download |
|---|---|---|
| python-2.7.15-macosx10.9.pkg | 2018-05-01 | 22.7 MB |
| python-2.7.12-macosx10.6.pkg | 2016-06-25 | 21.3 MB |
| python-2.7.11-macosx10.6.pkg | 2015-12-05 | 21.1 MB |
| python-2.7.10-macosx10.6.pkg | 2015-05-23 | 21.1 MB |
| python-2.7.09-macosx10.6.pkg | 2014-12-10 | 21.0 MB |
| python-2.7.08-macosx10.6.pkg | 2014-07-02 | 19.4 MB |
| python-2.7.07-macosx10.6.pkg | 2014-05-31 | 19.4 MB |
| python-2.7.06-macosx10.6.pkg | 2013-11-10 | 19.2 MB |
This table shows the growth in download size over time, an analysis unique to this page.
Upgrade pip and setuptools
Many disagree with https://techworm.net/programming/install-pip-python-mac-windows-linux/ which recommends use of easy_install
https://packaging.python.org/discussions/pip-vs-easy-install/ which is part of setuptools.
https://en.wikipedia.org/wiki/Setuptools#EasyInstall easy_install in not a full fledged package installer like pip is.
kinda like a disgraced parent.
Install pip homebrew without setuptools
Instead of following instructions such as this with:
pip install -U pip setuptools
BTW, on Windows it’s:
python -m pip install -U pip setuptools
On Ubuntu 17.04+ Linux:
On previous Ubuntu versions, see https://launchpad.net/
Conda installs outside the standard structure, so
this warning appears (which can be safely ignored):
QUESTION: Is there a way to suppress these messages?
Requirements.txt
In a GitHub repo cloned locally, if you see a file Requirements.txt, it is likely a list of Python packages needed by the application:
Notice each specific version is specified.
In a Terminal shell window, change the directory to where app resides.
Just for laughs:
pip install
The use of the word “requirement” in this message is partly why lists of Python package dependencies are in a requirements.txt file.
Get a Python 2.7 installed. For example, at:
Verify the sym link:
/.bash_shell to add a shell alias:
Verify the version.
The response should be the newer sub-version:
Virtual Environments
Examples of instructions for installing a requirements.txt file are typically preceded by a source bin/activate command which executes the activate script in the project’s bin folder.
An activate script is placed in each virtual environment established to store different sets of dependencies required by different projects in separate isolated locaations.
This solves the «Project X depends on version 1.x but, Project Y needs 4.x» dilemma, and keeps your global site-packages directory clean and manageable.
Before the pip install command: Automatically download the packages listed (after you manually change the /path/to)
This downloads dependencies from PyPI (the Python Package Index), a public repository of software for the Python programming language at https://pypi.python.org/pypi.
However, adding the “—no-index” option would not use it.
NOTE: pip compiles everything from source if a “wheel” is not available for it. Wheels are a pre-built distribution format that provides faster installation compared to Source Distributions (sdist), especially when a project contains compiled (C language) extensions.
pip install --use-wheel package
pip scikit-learn
In a Terminal on any folder, globally install dependencies libraries:
pip install -U scikit-learn
Edit the Python script to add at the top:
pip iPython Jupyter
iPython is the kernel of Jupyter.
pip install ipython
Virtualenv and Docker
PROTIP: Don’t pip install anything beyond virtualenv into its global site-packages outside of virtualenv.
Install both virtualenv and system isolation (they are not mutually exclusive):
Isolate your application server’s OS from its host using Docker/lxc/jails/zones/kvm/VMware/… to one container/vm per application.
inside of them also do isolate your Python environment using virtualenv from unexpected surprises in the system site-packages.
Remove hassles from managing per-project virtualenvs by using one of these, depending on the shell and operating system used:
- virtualenvwrapper
- virtualenvwrapper-win on MS Windows
PIP (Python Installation Packager)
As of Python 2.7.9 and Python 3.4.x, python.org installers for OS X install pip as well from Activestate.com and download ActivePython. It’s a simple install that gives you both Python and pip.
According to https://www.python.org/download/mac/tcltk/, download from http://www.activestate.com/activetcl/downloads file ActiveTcl8.6.3.1.298624-macosx10.5-i386-x86_64-threaded.dmg
After install, the ActiveTcl User Guide is popped up.
“Now, some people may recommend you install Macports or Fink: these are both “sorta” package managers for OS/X, and while I do have Macports installed, I do not use it for Python work. I prefer compilation and self management.”
Easy_install
Others use easy_install (with setuptools) to install packages from the web.
sudo easy_install pip
Virtual pip environments
The best way to have painless and reproducible deployments is to package whole virtual environments of the application you want to deploy including all dependencies but without configuration.
In the world of Python, an environment is a folder (directory) containing everything that a Python project (application) needs to run in an organised, isolated fashion.
When it is initiated, it automatically comes with its own Python interpreter
- a copy of the one used to create it — alongside its very own pip.
The ability to work with either version 3 or 2.7 on the same machine is needed because, as this MacWorld article points out, Mac Mavericks and Yosemite are installed with Python 2.7, cannot run python3 scripts.
You can work on a Python project which requires Django 1.3
while also maintaining a project which requires Django 1.0.
It’s done by creating isolated Python environments using virtualenv (Virtual python environment builder).
sudo pip install virtualenv
As the reponse requests, activate:
source /usr/local/opt/autoenv/activate.sh
This does not issue a response.
Instead of «venv», substitute your project name to to create:
cd my_project_folder
virtualenv venv
Exclude the virtual environment folder from source control by adding it to the git ignore list.
QUESTION: How to fix this? This occurs when virtualenv was installed with easy_install (or “python setup.py install”)
List all virtual environments:
lsvirtualenv
To use a particular Python interpreter:
virtualenv -p /usr/bin/python2.7 venv
Activate your project:
The name of the current virtual environment should now appear on the left of the prompt (e.g. (venv)Your-Computer:your_project UserName$).
From now on, any package that you install using pip will be placed in the venv folder, isolated from the global Python installation.
autoenv
To automatically activate an environment when you cd into it:
brew install autoenv
Install packages as usual, for example:
pip install request
When you are done working in the virtual environment for the moment:
The above puts you back to the system’s default Python interpreter with all its installed libraries.
To delete a virtual environment, delete its folder. In this case, it would be:
To keep your environment consistent,
the current state of the environment packages:
pip freeze > requirements.txt
This creates (or overwrites) a requirements.txt file containing a simple list of all the packages in the current environment and their respective versions. This file would make it easier to re-create the environment and to install the same packages using the same versions:
pip install -r requirements.txt
This ensures consistency across installations, deployments, and developers.
As noted in http://docs.python-guide.org/en/latest/dev/virtualenvs/ this create a folder in the current directory containing the Python executable files, and a copy of the pip library which you can use to install other packages. The name of the virtual environment (in this case, it was venv) can be anything; omitting the name will place the files in the current directory instead.
Open an internet browser to https://www.python.org/downloads/ and download file python-3.4.2-macosx10.6.pkg.
See http://docs.python-guide.org/en/latest/dev/virtualenvs/ https://www.digitalocean.com/community/tutorials/common-python-tools-using-virtualenv-installing-with-pip-and-managing-packages
To list what packages have been installed:
Look for packages by keyword:
pip search django
Use pip to install Tensorflow
As Siraj shows in his video, on a Mac Terminal, define an environment variable that points to the download URL:
(This is for Python 3 on a Mac.)
Install it using PIP and the variable:
Vagrant
This explanation forks another.
Setup a provider VM solution to store the image (like VMware, AWS, Hyper-V). https://www.virtualbox.org/wiki/Downloads click “x86/amd64” next to VirtualBox 4.3.20 for OS X hosts to download VirtualBox-4.3.20.96.dmg (109 MB) Read the 368 page User Manual.
Install https://github.com/dotless-de/vagrant-vbguest to keep VirtualBox guest additions up to date. http://schof.org/2014/03/31/working-around-virtualbox-bug-12879/
In the Finder, in the Applications folder, drag and drop it onto your Dock for quicker use later. Double-click on VirtualBox for the VirtualBox Manager.
Download the 224.3 MB vagrant_1.7.1.dmg
The binary gets installed in the Applications folder with a link to the /usr/bin so it is added to the shell path.
vagrant
vagrant list-commands
Change directory to where you want to store the Vagrant project and run
A Vagrantfile has been placed in this directory. You are now ready to vagrant up your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on vagrantup.com for more information on using Vagrant.
This shows Vagrantfile (with capital V).
I am pulling the box from ATT M2X https://m2x.att.com/developer/sample-code This Repo provides a Vagrant virtual machine that contains several demo applications (Ruby and Python) that report data to AT&T M2X. https://github.com/attm2x/m2x-demo-vagrant
git clone https://github.com/attm2x/m2x-demo-vagrant.git
vagrant box add chef/centos-6.5
User data for Vagrant is filed in the directory from which vagrant was used and is stored in an invisible directory .vagrant.d
Python 2 executables
Path to executables
To see what MacOS
which python
If you have MiniConda installed:
If you have Anaconda installed and your user is “mac”:
If you are inside a conda activated environment:
For a list of what Python executes:
The response begins with this:
Type python
Find where you are picking up Python from?
type python
If Python was installed:
python is hashed (/usr/bin/python)
Alternately, if Conda was installed:
python is hashed (/Users/mac/miniconda3/bin/python)
Open a Terminal shell window and issue command:
The response is its version. My Mac Yosemite default of Python shows this:
With Miniconda installed on El Capitan, it’s this instead:
The response I got is this:
Miniconda install
Below is a more “hands-on” description than what pydata.org and Kyle Purdon offers.
/Downloads
wget https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
Select version to download. For Python 2.7:
| Version | File | Size |
|---|---|---|
| Python 2.7 | miniconda3-latest-MacOSX-x86_64.sh | 20.3 MB |
| Python 3.5 | Miniconda3-latest-MacOSX-x86_64.sh | 23.4 MB |
NOTE: Python3 is not backward compatible with Version 2.
Notice the “.sh” means these are shell scripts.
Open a Terminal shell window to navigate to your Downloads folder and run the Python 2.7 script:
/Downloads
bash miniconda3-latest-MacOSX-x86_64.sh -b
PROTIP: The “-b” option specifies unattended with defaults.
“ERROR: File or directory already exists:” appears if miniconda was already installed.
Anaconda Install
This video by Corey Schafer explains it well.
QUESTION: Is there a brew anaconda?
Click to download the “command-line installer”.
In a (bash) Terminal:
Type yes and press Enter.
Anaconda3 will now be installed into this location: /Users/mac/anaconda3
Or specify a different location below
Wait for it to come back to you.
Conda verson
For the version of conda installed, specify the upper-case V:
conda -V
conda --version
The response is like:
Update conda
To update miniconda’s version, use the conda command line installed above:
conda update conda
The response is a list of packages to be updated if you agree:
Press “y” to proceed. A sample response:
After install, close and then re-open the terminal window so the changes can take effect.
For a list of packages installed locally (in the currently active environment):
conda list
The “py36_1” in the list are pip installed.
.bash_profile config
TODO: Instructions for both Miniconda and conda.
The path to Python should be the first in PATH:
Open a text editor to
/.bash_profile and add:
export PATH=”
/miniconda3/bin:$PATH”
export PYTHON_PATH=
When you’re done:
Activate the shell file :
Troubleshoot brew install
Scripting Python versions
TODO: Use a shim so that a script can display the version of Python it is using:
For a script to ensure that it’s running the version of Python intended:
Conda info
conda info
Conda environments
Get a list of Conda environments (from any folder) using the -e flag:
conda info -e
Alternately, if you like typing long options:
The response are like this:
Create a Conda environment named py2 using Python 2.7:
Press y to go ahead.
Add python packages, such as TensorFlow:
Activate to use the environment:
When done using TensorFlow, deactivate the environment:
Conda pyenv
pyenv enables switch between multiple versions of Python on a single system (laptop).
Create two “named” Conda environments (one with Python2 and the other with Python3):
Set one of these as my default by adding to my terminal startup file
Typically I only use these “named python” environments to run a Python REPL or do general Python tasks. I’ll create another conda environment named specifically for each real project I work on.
Uninstall
PROTIP: Delete Conda one folder at a time (without the –yes parameter).
Install Python packages
From inside a conda environment:
pip install numpy
Instead of downloading http://www.scipy.org/scipylib/download.html# linear algebra, standard distributions, signal processing, data IO
pip install scipy
pip install sklearn
pip install pandas
Other Python packages:
- xlwings interfaces with Microsoft Excel spreadsheets
- pygame develops GUI
OpenCV for computer vision
Follow the instructions below to install python2 + OpenCV in mac
In case of python3 + OpenCV follow
Conda vs Pip
Conda handles library dependencies outside of the Python packages as well as Python packages themselves.
Conda installs from binary, meaning that someone (e.g., Continuum) has already done the hard work of compiling the package, making installation easier, and faster.
Conda requires at least three commands: skeleton, build, install, and possibly more.
This table lists the difference in commands between Conda and pip, a summary of the more detailed table is at https://conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands
| Task | Conda package and environment manager command | Pip package manager command | Virtualenv environment manager command |
|---|---|---|---|
| Install a package | conda install $PACKAGE_NAME | pip install $PACKAGE_NAME | - |
| Update a package | conda update --name $ENVIRONMENT_NAME $PACKAGE_NAME | pip install --upgrade $PACKAGE_NAME | - |
| Update package manager | conda update conda | Linux/OSX: pip install -U pip Win: python -m pip install -U pip | - |
| Uninstall a package | conda remove --name $ENVIRONMENT_NAME $PACKAGE_NAME | pip uninstall $PACKAGE_NAME | - |
| Create an environment | conda create --name $ENVIRONMENT_NAME python | - | cd $ENV_BASE_DIR; virtualenv $ENVIRONMENT_NAME |
| Activate an environment | source activate $ENVIRONMENT_NAME | - | source $ENV_BASE_DIR/$ENVIRONMENT_NAME /bin/activate |
| Deactivate an environment | source deactivate | - | deactivate |
| Search available packages | conda search $SEARCH_TERM | pip search $SEARCH_TERM | - |
| Install package from specific source | conda install --channel $URL $PACKAGE_NAME | pip install --index-url $URL $PACKAGE_NAME | - |
| List installed packages | conda list --name $ENVIRONMENT_NAME | pip list | - |
| Create requirements file | conda list --export | pip freeze | - |
| List all environments | conda info --envs | - | Install virtualenv wrapper , then lsvirtualenv |
| Install other package manager | conda install pip | pip install conda | - |
| Install Python | conda install python=x.x | - | - |
| Update Python | conda update python * | - | - |
PyCharm IDE
$195/year PyCharm is purpose-built by Jetbrains.com for Python coding:
Install using Homebrew:
To run Terraform from IDE and autocompletion, rename refactoring, etc.
Configure in Settings -> Tools -> Terraform
Explicitly add Terraform run configurations
Run Terraform from IDE File context menu -> Run…
Alternately, click green ‘run’ next to resources
Turi (Dato) Python algorithms
GraphLab Create from Dato provides scalable “pre-implemented” ML algorithms using Anaconda. Entire courses on its use is at
- https://www.coursera.org/learn/ml-foundations
- https://www.turi.com/learn/userguide/
- https://www.turi.com/products/create/docs/
- https://github.com/learnml/machine-learning-specialization
- https://www.coursera.org/learn/ml-clustering-and-retrieval/supplement/iF7Ji/software-tools-you-ll-need-for-this-course
When the one-year free license is over, note scikit-learn also uses Python with Anaconda.
Python libraries
For matrix operations, use the Numpy open-source Python library for fast performance with data that fits in memory. Quickstart.
In a requirements.txt file:
bokeh Flask ipython jupyter matplotlib nose numpy pandas Pillow pymc requests scikit-image scikit-learn scipy seaborn statsmodel tensorflow virtualenv virtualenvwrapper
OpenCV3
Data Manipulation
SFrame is an open-source, highly-scalable Python library for data manipulation. Unlike Pandas, SFrame is not limited to datasets which can fit in memory, so it can deal with large datasets, even on a laptop.
Conda
Conda is similar to virtualenv and pyenv, other popular environment managers.
conda install numpy pandas matplotlib
conda install jupyter notebook
List the packages installed, with its version number and what version of Python:
Conda Environments
Create new environment for Python, specifying packages needed:
conda create -n my_env python=3 numpy pandas
Enter an environment on Mac:
source activate my_env
When you’re in the environment, the environment’s name appears in the prompt:
Leave the environment
On Windows, it’s just deactivate.
Get back in again.
Create an environment file by piping the output from an export:
conda env export > some_env.yaml
When sharing your code on GitHub, it’s good practice to make an environment file and include it in the repository. This will make it easier for people to install all the dependencies for your code. I also usually include a pip requirements.txt file using pip freeze (learn more here) for people not using conda.
Load an environment metadata file:
conda env create -f some_env.yaml
List environments created on your machine:
Remove an environment:
conda env remove -n some_env
Where installed?
When Python is installed using pip, see where it’s installed:
The response on my system:
Miscellaneous
https://gist.github.com/alyssaq/f60393545173379e0f3f describes install of https://bootstrap.pypa.io/get-pip.py
https://docs.python.org/3/library/2to3.html 2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code.
References
https://joernhees.de/blog/2014/02/25/scientific-python-on-mac-os-x-10-9-with-homebrew/ recommends several pip libraries
https://linuxacademy.com/cp/socialize/index/type/community_post/id/14209 released 1/25/2017 by Michael Jenkins makes use of AWS Boto3 with Python2 to create S3 buckets, upload files, and delete S3 buckets in code examples as part of Linux Academy’s Red Hat Certified Specialist in Virtualization (EX318) Preparation video Course
Sikuli Python
To use SikuliX from real Python via py4j
Get support on the Python:
Download the Jython interpreter for Python scripting (the default) jython-standalone-2.7.1.jar
Как установить python на mac
Для создания программ на Python нам потребуется интерпретатор. Для его установки перейдем на страницу https://www.python.org/downloads/ и найдем ссылку на загрузку последней версии языка:

Если текущая ОС - Mac OS, то по адресу https://www.python.org/downloads/ будет предложено загрузить графический установщик для MacOS. Загрузим, запустим его и выполним пошаговую установку:

Для обращения к интерпретатору Python на MacOS применяется команда python3 . Напримерб после установки интерпретатора проверим его версию командой

Первая программа
Сначала определим где-нибудь на жестком диске для скриптов папку python . А в этой папке создадим новый текстовый файл, который назовем hello.py . По умолчанию файлы с кодом на языке Python, как правило, имеют расширение py .
Откроем этот файл в любом текстовом редакторе и добавим в него следующий код:

Скрипт состоит из двух строк. Первая строка с помощью функции input() ожидает ввода пользователем своего имени. Введенное имя затем попадает в переменную name .
Вторая строка с помощью функции print() выводит приветствие вместе с введенным именем.
Теперь запустим командную строку/терминал и с помощью команды cd перейдем к папке, где находится файл с исходным кодом hello.py (например, в моем случае это папка "/Users/eugene/Documents/python").
Далее для выполнения скрипта hello.py передадим его интерпретатору python:
В итоге программа выведет приглашение к вводу имени, а затем приветствие.
How to install Python on your Mac

Having spent some years coding applications for macOS, we’ve created a tool that everybody can use. The all-round problem fixer for Mac.

So here’s a tip for you: Download CleanMyMac to quickly solve some of the issues mentioned in this article. But to help you do it all by yourself, we’ve gathered our best ideas and solutions below.
Features described in this article refer to the MacPaw site version of CleanMyMac X.
The Python programming language is widely used for everything from scraping data to building websites, and it was once pre-installed on macOS. Apple stopped including a Python install with macOS when it released Catalina and so now, if you want to use Python on your Mac, you will need to install it yourself. What’s more, you’ll need an application with which to edit and test Python code.
In this article, you’ll learn how to install Python on your Mac (along with a source-code editor) and how to write or test Python code on your Mac via a web browser.
How to check if Python is already installed on your Mac
If your macOS is older than Catalina, you might have Python already installed on your Mac. Here’s how to check with Terminal:
- Go to Applications > Utilities > Terminal.
- Type: python --version
- Press Return
- If Python is installed, you will see a message telling you which version.
- If it’s not installed, you will see ‘command not found: python’

When you install Python and VS Code on your Mac, they will request access to protected folders on your Mac, like Documents. And when you use Google Colab, it will store cookies and other data on your machine. Consequently, once you’ve given them permission it becomes difficult to control secure access to folders, cameras, or microphones.
To deal with all that (plus removing data history, downloads, and autofill from Safari, Chrome, and Firefox), use the Privacy module in CleanMyMac X. It allows you to effortlessly manage permissions for all apps and remove the web browser data from your Mac. Download CleanMyMac X for free here.
How to install Python on your Mac
To install Python on your Mac, you’ll first need to download the official installer.
- In a web browser, go to: https://www.python.org/downloads/
- You will automatically be taken to the download page, where you’ll see ‘Download the latest version for macOS’. Click the Download Python button.
- When the download is complete, download the installer package to launch it.
- When it opens, click Continue and follow the on-screen instructions.
- When the installation is finished, you will see a Python directory in your Applications folder.
To make sure the installation went well…
- Open that folder and double-click IDLE to check it is installed correctly.
- When it opens, you’ll see a command line interface. Type the following command to check everything is working: print (‘Hello world’)
- If you see ‘Hello World’ beneath the command, it is installed properly.
How to install a source-code editor for Python on your Mac
You could start coding in Python from the command line or using a source code editor, which is much easier. With this editor, you’ll be able to use syntax highlighting, code folding, and intelligent code completion features.
Now there are several source-code editors for Mac. One of the best is Microsoft’s Visual Studio Code (VS Code), which by the way, is totally free for Mac.

How to install VS Code on your Mac
- Click here to go to the download page on Microsoft’s website.
- Click ‘Download Mac Universal’.
- When the download is complete, VS Code will extract itself from the zip archive. If it doesn’t, double-click the zip file.
- Drag VS Code to your Applications folder.
How to set up VS Code to code in Python
Before you can use VS Code to write Python, you need to create a script and install a Python extension. Here’s how to do that:
- Launch VS Code from your Applications folder.
- Choose New File in the Get Started window.
- Type the name of the file in the text box at the top of the window and give it the extension .py.
- Click ‘New file’ under the text box, and choose where to save it. Then click Create File.
- You can now click the default Python extension by clicking Install at the bottom of the window. VS Code will install the Python extension, and you can then start writing your Python script.
How to write a Python script in VS Code
- Click on the tab for the file you have just created.
- Type the following code: print (“Hello, world!”)
- Click the play button at the top right of the VS Code window.
- You will see the result of the script, the words ‘Hello, world!’ printed in the Terminal in the bottom section of the VS Code window.
How to code Python on your Mac without installing it
If you want to experiment with Python on your Mac without installing it, or you want to be able to access your work on different computers, you can use Google’s Colab to write Python scripts. All you need is a web browser and a Google account.
- In a web browser (Chrome works best), go to colab.research.google.com
- If you’re not already signed in with your Google account, sign in.
- In the Table of Contents section in the sidebar, click Getting Started. All the information you need to get started using Colab is on that page, including links to videos and documentation to help you.
How to write a Python script in Colab

To start writing a Python script in Colab, we first need to create a new notebook.
- Click File in the Colab window and choose New Notebook.
- Click on ‘Untitled’ at the top of the window and type a new name for the notebook.
- Click in the input box and type the lines of code below, pressing Return at the end of each line
name = input(“What’s your name? “)
print(“Hello <>!\nCongratulations on writing your first Colab python script”.format(name)) - Click the play button at the start of the script.
- You should see the words ‘What’s your name?’ and a text box.
- Type your name in the text box and press Return.
Because Apple no longer includes Python in the newest macOS, installing Python on Mac or writing scripts became more complicated. However, if you follow the steps above, you can install it yourself and start writing your first script. Or, use Google Colab as an alternative to bypass the installation altogether. Good luck!