The open-source Anaconda Distribution is the easiest way to perform Python/R data science and machine learning on Linux, Windows, and Mac OS X. With over 15 million users worldwide, it is the industry standard for developing, testing, and training on a single machine, enabling individual data scientists to. Quickly download 1,500+ Python/R data science packages. Python for Mac 2019 full offline installer setup for Mac Python for Mac is a dynamic object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days.
Confusion and errors from many alternatives and options
This tutorial describes the different options to install anduninstall Python within variouspackage 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.
Iâve pulled out the various incantations suggested by others on StackOverlowand 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.
There are two separate versions of Python: 2 and 3. some Python functions in one version do not work with commands in another version.
This has given rise to several versions of Python frameworks being maintained in parallel. For example, the web application development framework exists as 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.
pip (Python Installation Packager) is built on top of setuptools whichis 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.
MacOS does not come installed with a package manager for Python.
This complexity necessitates the packaging of whole virtual environments to isolatewithin 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 aseasy_install, virtualenv, and pipenv.
Itâs a âhot messâ.
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).
IPython (Jupyter) Notebook enables a ânotebookâ interface to re-run commands.See http://sjbyrnes.com/python/
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.
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)â.
Alternatively, use a package manager. CAUTION: MacPorts, Fink, and Homebrew do not coexist well on the same machine.
Use Docker
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)
Folders Python on CLI
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?
Print is different
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:
The response:
Hello world!
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:
Try this:
The response:
Floating point
In Python 2, type in the REPL:
The response is:
In Python3, type:
The response is:
Python programming code
Start a HTTP Server Using Python
A simple HTTP server service can be started with this Python 2 command:
python -m SimpleHTTPServer
For Python3:
python3 -m http.server
The response:
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
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:
Upgrade Python
Download Python installer
If you must do it the hard way, bareback, etc:
Upgrade pip and setuptoolsInstall 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
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.
Di
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)
source bin/activate
pip install -r /path/to/requirements.txt </strong>
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 #
Virtualenv and Docker
Remove hassles from managing per-project virtualenvs by using one of these, depending on the shell and operating system used:
PIP (Python Installation Packager)
As of Python 2.7.9 and Python 3.4.x, python.org installers for OS X install pip as wellfrom 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 fromhttp://www.activestate.com/activetcl/downloadsfile ActiveTcl8.6.3.1.298624-macosx10.5-i386-x86_64-threaded.dmg
After install, the ActiveTcl User Guide is popped up.
Jesse Noller notes inSo you want to use python on the Mac:
â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
The response:
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
The ability to work with either version 3 or 2.7 on the same machine is neededbecause, as this MacWorld articlepoints 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 usingvirtualenv (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.
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.
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/Downloadsclick âx86/amd64â next to VirtualBox 4.3.20 for OS X hoststo download VirtualBox-4.3.20.96.dmg (109 MB)Read the 368 page User Manual.
Install https://github.com/dotless-de/vagrant-vbguestto 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.
List commands:
vagrant
vagrant list-commands
Change directory to where you want to store the Vagrant project and run
vagrant init
The response:
A
Vagrantfile has been placed in this directory. You are nowready to vagrant up your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation onvagrantup.com for more information on using Vagrant.
ls
This shows Vagrantfile (with capital V).
https://www.vagrantup.com/downloads.html
https://vagrantcloud.com/boxes/searchlists boxes created by the community.
I am pulling the box from ATT M2X https://m2x.att.com/developer/sample-codeThis 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
bootstrap.bash
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
This advice from 2010.
### Path to executables #
The response I got is this:
/Users/mac/Library/Python/2.7/lib/python/site-packages
Alternately:
/Users/mac/.local/lib/python2.7/site-packages
Miniconda install
Below is a more âhands-onâ description than whatpydata.org andKyle Purdon offers.
Anaconda Install
This video by Corey Schafer explains it well.
Conda verson
See https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/
Update conda
.bash_profile config
TODO: Instructions for both Miniconda and conda.
The path to Python should be the first in PATH:
Scripting Python versions
TODO: Use a shim so that a script can display the version of Python it is using:
Some answers:
Per https://docs.python.org/3/library/sys.html#sys.hexversion
For a script to ensure that itâs running the version of Python intended:
Alternately:
Conda info
Conda pyenv
pyenv enables switch between multiple versions of Python on a single system (laptop).
Uninstall
PROTIP: Delete Conda one folder at a time (without the âyes parameter).
anaconda-clean
Files such as:
Install Python packages
From inside a conda environment:
OpenCV for computer vision
Follow the instructions below to install python2 + OpenCV in mac
In case of python3 + OpenCV follow
Conda vs Pip
Conda provides an alternative set of commandspopular for scientific (Machine Learning) computing.See http://conda.pydata.org/docs/_downloads/conda-cheatsheet.pdf
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
PyCharm IDE
https://discussions.udacity.com/t/referencing-pygame-from-pycharm-with-anaconda/223711/13
Turi (Dato) Python algorithms
GraphLab Create from Dato provides scalable âpre-implementedâ ML algorithms using Anaconda.Entire courses on its use is at
When the one-year free license is over, notescikit-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:
tweepy (http://www.tweepy.org)
csv (https://pypi.python.org/pypi/csv)
textblob (https://textblob.readthedocs.io/en/dev/)
keras (https://keras.io)
bokehFlaskipythonjupytermatplotlibnosenumpypandasPillowpymcrequestsscikit-imagescikit-learnscipyseabornstatsmodeltensorflowvirtualenvvirtualenvwrapper
OpenCV3Data 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.
http://stackoverflow.com/questions/509211/explain-pythons-slice-notation/
Conda
Conda is similar to virtualenv and pyenv, other popular environment managers.
https://virtualenv.pypa.io/en/stable/
https://github.com/yyuu/pyenv
https://www.continuum.io/downloads
conda install numpy pandas matplotlib
conda install jupyter notebook
Conda EnvironmentsAnaconda Download Mac Os Catalina
Read:
Anaconda Download Mac Os X
Where installed?Anaconda Download Mac Os
When Python is installed using pip, see where itâs installed:
The response on my system:
Miscellaneous
http://stackoverflow.com/questions/990754/how-to-leave-exit-deactivate-a-python-virtualenv?rq=1
https://gist.github.com/alyssaq/f60393545173379e0f3fdescribes install of https://bootstrap.pypa.io/get-pip.py
https://docs.python.org/3/library/2to3.html2to3 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/14209released 1/25/2017 by Michael Jenkinsmakes use of AWS Boto3 with Python2 to create S3 buckets, upload files, and delete S3 buckets incode examples as part of Linux Academyâs Red Hat Certified Specialist in Virtualization (EX318) Preparation video Course
More on OSX
This is one of a series on Mac OSX:
Please enable JavaScript to view the comments powered by Disqus.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |