OSX set up Python (Anaconda): Difference between revisions

From CommunityData
(update Anaconda install instructions)
(38 intermediate revisions by 9 users not shown)
Line 1: Line 1:
== Download and install Anaconda ==
== Download and install Python ==


If you use a Mac, you already have Python installed on your computer. However, in order to be able to do all the exercises and participate in the afternoon breakout sessions, we recommend that you also install a collection of Python add-ons called '''[https://store.continuum.io/cshop/anaconda/ Anaconda]'''. Anaconda includes many useful packages that allow you to perform more powerful data analysis and visualization with Python. Although the collection includes all free software, it is put together by a commercial company called '''Continuum Analytics'''.
We're going to be installing Python using a software collection that includes Python. The collection is called '''Anaconda'''. Anaconda includes the Python programming language and a bunch of different pieces of software that are useful for data science and analysis. Although the collection includes all free software, it is put together by a commercial company called '''Continuum Analytics'''.


To install Anaconda, you should:
'''Note:''' Even if you already have a version of Python on your computer, we suggest you follow these instructions and download Anaconda. This will help ensure that you can follow along during our in-class activities, and will make it easier for mentors to help you if you get stuck on something.


# Download and install [http://continuum.io/downloads Anaconda]. Follow [http://continuum.io/downloads this link] to the Anaconda website and click on the button that says ''Download OSX -- 64-Bit Python 2.7 Graphical Installer.''  
=== Download option #1 ===
# Download the file to your Desktop or Downloads folder.  
 
# Once the (~275 MB) installer package is downloaded, double click the .pkg file and follow the instructions on the screen. Install Anaconda in your home folder.
<font size="+1">Try to download the installer from [https://communitydata.science/~mako/Anaconda3-2019.10-MacOSX-x86_64.pkg this file which contains Anaconda and Python 3.7 for MacOS].</font>
 
=== Download option #2 ===
If option 1 above doesn't work for any reason, download the Python 3.7 option from [https://www.anaconda.com/distribution/#download-section Anaconda's website]. If necessary, scroll down to the "Anaconda 2019.10 for macOS Installer" section.
 
=== Installation ===
 
{{Notice|If you are on MacOS 10.15 (Catalina), '''you must follow an additional step''' which is noted below. If you don't, Anaconda won't work quite right! }}
 
To install Anaconda, simply open the package and follow the prompts. You may be asked to enter your password by Package Installer.
 
<gallery>
file:Macos-anaconda-37.png|Make sure you download the version for Python3|alt=Dialog box confirming that the downloaded file is called "Anaconda3-2019-MacOSX-x86_64.pkg
file:Macos-anaconda-hello.png|Opening the file with Package Installer will guide you through the setup process|alt=Package Installer window greeting the user
file:Macos-anaconda-auth.png|You may be prompted for your password|alt=Package Installer prompting the user for a password
File:Macos-anaconda-installing.png|Package Installer will install Anaconda3|alt=Package installer showing progress through the installation
</gallery>


=== Install notes ===
=== Install notes ===
*The website may ask you for your email address at some point during the install process. If so, there is no reason to leave the checkbox marked saying that you want mail from Continuum.
 
*This install will take approximately 890MB for the 64-bit installer (which is most likely the version you'll be installing.) If you do not have this much space on your computer, you cannot install Anaconda, but you can still run Python--skip to the section below!
*If you get stuck during the install process, ask a neighbor or raise your hand for help. [http://docs.continuum.io/anaconda/install.html#mac-install These instructions] may also be helpful.  
*If you get stuck during the install process, ask a mentor for help. [http://docs.continuum.io/anaconda/install.html#mac-install These instructions] may also be helpful.  
 
*Anaconda may leave a shortcut called "Launcher" on your desktop. You can delete this link: we won't be using it in the workshop.  
* At the end of the installer, you may be prompted if you'd like to send the installation package to the trash. Doing so won't damage the installation and will free up ~600MB of disk space on your computer.
 
[[File:Macos-anaconda-self-delete.png|thumb|none|200px|Prompt from Package Installer asking if it is OK to trash the installation package.]]
 
=== Special Steps for people using Mac OS 10.15 ===
 
If you are using MacOS 10.15 (Catalina) or above, you will need to configure the system to recognize Anaconda. You can find out which version of MacOS you have: you can click the Apple menu icon at the top left corner of your screen and then select the “About This Mac” command.
 
If the version number says '''10.15 or higher''' it means you have a pretty new computer (congratulations on that). It also means that you will need to have to do an additional step. It might be a good idea to raise your hand and ask a mentor for help with this part.
 
To do so, open Terminal.app (either using Command-space or opening '''Applications > Utilities > Terminal.app''' and entering the following:
 
<nowiki>./opt/anaconda3/bin/conda init zsh
</nowiki>
 
You should end up with something like this:
 
[[file:Macos-conda-zsh.png|thumb|none|alt=A terminal window showing the result of configuring Conda and MacOS Catalina.]]
 
Once you're done, you can quit Terminal (either with Command-Q or the menu option '''Terminal > Quit Terminal''').


== Test your Python install ==
== Test your Python install ==
Now that you have installed everything you need, we will make sure we can start a [https://en.wikipedia.org/wiki/Terminal_(OS_X) Terminal] and run Python from the command line.


<ol>
To use Anaconda on MacOS, you will primarily use the Anaconda Navigator; It lets you manage the installed python tools, create custom setups, and launch tools like Jupyter.
<li>Start up a Terminal. You can find the Terminal application through Spotlight, or navigate to Applications/Utilities/Terminal.<br />
 
The easiest way to launch the Anaconda Navigator is from inside the Applications folder:


<br />
[[File:Macos-anaconda-navigator.png|200px]]
This Terminal contains something called a command prompt. This command prompt is another way of navigating your computer and running programs -- just textually instead of graphically. We are going to be running Python and Python scripts from this command prompt.
</li>
<li>Test your Python install at the command prompt. Type


<pre>
The navigator will start up and greet you with a list of installed and available tools:
python
</pre>


and hit enter. You should see something like
[[File:Macos-anaconda-nav-hub.png|frameless|400px]]
<pre>
Python 2.7.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre>


* You just started Python! The <code>>>></code> indicates that you are at a new type of prompt -- a Python prompt. The command prompt let's you navigate your computer and run programs, and the Python prompt lets you write and run Python code interactively.<br />
One of the options (it's the middle option in the screenshot) should be called "Jupyter Notebook". Click that to open Jupyter Notebook! After a few seconds, you'll see a new tab open in your default browser. It will look something like this:


* If the Python version number (2.7.1 in the example above) is not a number between 2.4 and 2.7 (ignoring the number after the second dot), tell a staff member.
[[File:Jupyternb launch.png|500px]]
</li>
<li>To exit the Python prompt, type


<pre>
Your default browser is where you'll be working with Jupyter Notebooks.
exit()
</pre>


and press Enter. This will take you back to the OS X command prompt.</li>
If for some reason you '''don't''' see something in your browser, let a mentor know.
</ol>
 
When you launched the notebook from Anaconda, you may have noticed a Terminal window popped up, like this:
 
[[File:Terminal.png|500px]]
 
You can hide it, but do not close it during the whole time when you are using the Jupyter Notebook. If you close it, your Jupyter Notebook will be closed automatically.
 
To close Anaconda, first go to your terminal, then, press "CONTROL+C" keys, you will see a new line on your terminal:
 
[[File:Shutdownline.png]]
 
Press "y" key, then press "RETURN" key. Now your Anaconda is closed :)
 
Now Anaconda is not running on your terminal. You can press the "x" on the upper left corner of your terminal window to close the terminal as well.
 
 
<!--
From the left hand side, choose '''Environments''', then choose the small "play" button. A menu will appear; choose the option 'Open with Python'. This will open an interactive Python window that we're going to use to test Python out with.
 
[[File:Macos-anaconda-environments.png|frameless|400px]]
 
Enter into the window '''print("Hello, World!")'''. You should see the text '''"Hello, World!"''' echoed back at you.  
Enter into the window '''<tt>exit()</tt>''' and you'll shut down the Python session and get a helpful '''<tt>[Process Completed]</tt>''' from the terminal, telling you your session is over.
 
[[File:Macos-conda-python-hello.png|frameless|400px]]
 
Press '''Command-Q''' or choose '''Terminal > Quit Terminal''' from the menu to close Terminal.
 
-->  
 
Success! You've gotten Anaconda and Python working on your Mac!


== Success! ==
== Success! ==


You have tested your Python installation.
You have installed and configured Python. You can move on to the [[CDSW/Day_0_setup_and_tutorial|next step]].
 
[[Category:CDSW]]

Revision as of 03:08, 18 January 2020

Download and install Python

We're going to be installing Python using a software collection that includes Python. The collection is called Anaconda. Anaconda includes the Python programming language and a bunch of different pieces of software that are useful for data science and analysis. Although the collection includes all free software, it is put together by a commercial company called Continuum Analytics.

Note: Even if you already have a version of Python on your computer, we suggest you follow these instructions and download Anaconda. This will help ensure that you can follow along during our in-class activities, and will make it easier for mentors to help you if you get stuck on something.

Download option #1

Try to download the installer from this file which contains Anaconda and Python 3.7 for MacOS.

Download option #2

If option 1 above doesn't work for any reason, download the Python 3.7 option from Anaconda's website. If necessary, scroll down to the "Anaconda 2019.10 for macOS Installer" section.

Installation

Cmbox notice.png If you are on MacOS 10.15 (Catalina), you must follow an additional step which is noted below. If you don't, Anaconda won't work quite right!

To install Anaconda, simply open the package and follow the prompts. You may be asked to enter your password by Package Installer.

Install notes

  • If you get stuck during the install process, ask a neighbor or raise your hand for help. These instructions may also be helpful.
  • At the end of the installer, you may be prompted if you'd like to send the installation package to the trash. Doing so won't damage the installation and will free up ~600MB of disk space on your computer.
Prompt from Package Installer asking if it is OK to trash the installation package.

Special Steps for people using Mac OS 10.15

If you are using MacOS 10.15 (Catalina) or above, you will need to configure the system to recognize Anaconda. You can find out which version of MacOS you have: you can click the Apple menu icon at the top left corner of your screen and then select the “About This Mac” command.

If the version number says 10.15 or higher it means you have a pretty new computer (congratulations on that). It also means that you will need to have to do an additional step. It might be a good idea to raise your hand and ask a mentor for help with this part.

To do so, open Terminal.app (either using Command-space or opening Applications > Utilities > Terminal.app and entering the following:

./opt/anaconda3/bin/conda init zsh

You should end up with something like this:

A terminal window showing the result of configuring Conda and MacOS Catalina.

Once you're done, you can quit Terminal (either with Command-Q or the menu option Terminal > Quit Terminal).

Test your Python install

To use Anaconda on MacOS, you will primarily use the Anaconda Navigator; It lets you manage the installed python tools, create custom setups, and launch tools like Jupyter.

The easiest way to launch the Anaconda Navigator is from inside the Applications folder:

Macos-anaconda-navigator.png

The navigator will start up and greet you with a list of installed and available tools:

Macos-anaconda-nav-hub.png

One of the options (it's the middle option in the screenshot) should be called "Jupyter Notebook". Click that to open Jupyter Notebook! After a few seconds, you'll see a new tab open in your default browser. It will look something like this:

Jupyternb launch.png

Your default browser is where you'll be working with Jupyter Notebooks.

If for some reason you don't see something in your browser, let a mentor know.

When you launched the notebook from Anaconda, you may have noticed a Terminal window popped up, like this:

Terminal.png

You can hide it, but do not close it during the whole time when you are using the Jupyter Notebook. If you close it, your Jupyter Notebook will be closed automatically.

To close Anaconda, first go to your terminal, then, press "CONTROL+C" keys, you will see a new line on your terminal:

Shutdownline.png

Press "y" key, then press "RETURN" key. Now your Anaconda is closed :)

Now Anaconda is not running on your terminal. You can press the "x" on the upper left corner of your terminal window to close the terminal as well.


Success! You've gotten Anaconda and Python working on your Mac!

Success!

You have installed and configured Python. You can move on to the next step.