Editing OSX set up Python (Anaconda)

From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
== 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 ===
<font size="+1">Try to download the installer from either of these places:</font>
* [https://repo.anaconda.com/archive/Anaconda3-2023.03-MacOSX-x86_64.pkg This file which contains Anaconda and Python 3.10 for MacOS for Intel-based Macs]
* [https://repo.anaconda.com/archive/Anaconda3-2023.03-MacOSX-arm64.pkg This file which contains Anaconda and Python 3.10 for MacOS for the newer M1 Macs]
=== Download option #2 ===
If option 1 above doesn't work for any reason, download the Python 3.10 option from [https://www.anaconda.com/distribution/#download-section Anaconda's website]. If necessary, scroll down to the "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 ===
*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.
* 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.]]
== Test your Python install ==
== Test your Python install ==
Lucky for us, OS X comes with Python installed! But we need to make sure we have an appropriate version of Python installed and make sure we can start a Terminal and run Python from the command line.


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.  
<ol>
<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 />
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


[[File:Macos-anaconda-navigator.png|200px]]
<pre>
python
</pre>


The navigator will start up and greet you with a list of installed and available tools:
and hit enter. You should see something like
<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>


[[File:Macos-anaconda-nav-hub.png|frameless|400px]]
* 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.
</li>
<li>To exit the Python prompt, type


[[File:Jupyternb launch.png|500px]]
<pre>
exit()
</pre>


Your default browser is where you'll be working with Jupyter Notebooks.
and press Enter. This will take you back to the OS X command prompt.</li>
</ol>


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


When you launched the notebook from Anaconda, you may have noticed a Terminal window popped up, like this:
You have tested your Python installation.


[[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.
== Download and install Anaconda ==


To close Anaconda, first go to your terminal, then, press "CONTROL+C" keys, you will see a new line on your terminal:
In order to be able to do all the exercises in the workshop without having to worry about installing special things later on, we're going to install a collection of extra Python libraries 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'''.


[[File:Shutdownline.png]]
To install Anaconda, you should:


Press "y" key, then press "RETURN" key. Now your Anaconda is closed :)
<!-- need to update. everything below this is the old Windows instructions -->
* Download and install [https://store.continuum.io/cshop/anaconda/ Anaconda]. Follow the link and click on the big blue <span style="background-color: #0000FF; color: #FFFFFF">Download Anaconda</span> button in the top right corner. The website will ask you for your email address when you log in. There's no reason to leave the checkbox marked saying that you want mail from Continuum.
* Use all of the defaults for installation, except make sure to '''check Make Anaconda the default Python'''.


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.  
'''Note''' This install will take just over 366MB for the 64-bit installer (which is most likely the version you'll be installing.)


== Test to make sure Python is working ==


<!--  
# Open a Command Prompt. You can do this by hitting WIN+R, and typing in <tt>cmd</tt>.
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.
#* This is called a "command line interface"---a way of interacting with your computer by typing.
# Test your Python install at the command prompt. Type <pre>python</pre> and hit enter. You should see something like
<pre>
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre>


[[File:Macos-anaconda-environments.png|frameless|400px]]
<ol start="3">
<li>
You just started Python! The <code>>>></code> indicates that you are at a new type of prompt: a Python prompt. The command prompt lets you navigate your computer and run programs, and the Python prompt lets you write and run Python code interactively.
</li>
<li>
To exit the Python prompt, type <pre>exit()</pre> and press Enter. This will take you back to the Windows command prompt.
</li>
</ol>


Enter into the window '''print("Hello, World!")'''. You should see the text '''"Hello, World!"''' echoed back at you.
== Success! ==
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]]
You have Python installed and configured.
 
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! ==


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


[[Category:CDSW]]
If you do not want to use the Anaconda installer, you can take a look at [[Windows set up Python|this page]]. However, set up will be significantly more difficult.
Please note that all contributions to CommunityData are considered to be released under the Attribution-Share Alike 3.0 Unported (see CommunityData:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)

Template used on this page: