Undoubtedly the hardest part in beginning a journey is taking the first step. So lets take it together to make it a little easier!
By the end of this article you will understand how to setup a python environment in Anaconda (pt.1) and Atom (pt.2). Please note this article is suited for data professionals looking to use python primarily as an analytical tool. If you're seeking to use python as a part of a server stack configuration there is likely a better article to get you started elsewhere. Let's get started!
Check to ensure python is installed properly
Before attaining a text editor or setting up a development environment, it is first important to understand if your system has a distribution of python installed. The base distribution provides the system underpinning needed to run scripts or other applications. Follow the steps below by operating system to evaluate the version of your current python distribution in the command prompt or terminal. For the latest python distribution check out python.org.
Please note that as you check specific versions, many systems have pre-installed versions of python 2.7.x and 3.x. The reason for this is that python syntax and features operate with some fundamental differences depending on version.
If your machine does not have a distribution installed, I suggest following the steps outlined in Part 1 of this article because Anaconda installs the latest version of python (2.7.x or 3.x) as a part of the base installation. Alternatively, you can download the distribution directly from python here.
Where a missing python version could become problematic is when using a development environment directly through a text editor like Atom.
Mac OS / Linux
mycomputer$ python --version
mycomputer> python --version
Part 1) Setting Up a Python Environment using Anaconda
Anaconda is a powerful open source distribution of python with integrated package management (condas) and a host of embedded tools (sypder, jupyter, etc.) to get your data science / analytics journey started. Anaconda is particularly useful in the analytics stage of the data problem solving cycle because of the powerful visualization tools available to help understand your data. Follow the steps below to get started. Note that if your machine is lacking the proper python version, Anacondas will update it for you as a part of the installation!
Step 1) Download the Installation
Go to Anaconda Webpage and navigate to 'download.' Select the version you desire and the operating system. If you're puzzled by what version to use, I think that Sebastian Raschka says it best in his key differences post by saying "just go with the version your favorite tutorial was written in, and check out the differences later on." I am going to select python 3.x because that is what I am most familiar with along with the Linux OS (I am using Ubuntu).
Step 2) Run the Installation
The means of running the installation will depend on the type of operating system you have. For Mac and Windows you can simply open the installer and an executable file will take care of the installation. For Linux users you will need to navigate to the directory you've downloaded the installer and run the command below in the terminal. For details on installation steps consult the very detailed Anaconda Documentation.
mycomputer$ cd downloadDirectory mycomputer:~/downloadDirectory$ bash anacondaDownloadFile.ssh
Step 3) Run Anaconda-Navigator
Anaconda-Navigator is the springboard for action in your python journey. It allows you to communicate with conda to run applications in a more user friendly way. For Windows and Mac users, simply click on the Anaconda's application Window to boot up the application. You can also boot the navigator up using the terminal or command prompt using the command below.
Congratulations! You now can get started on your python journey. Start crunching numbers, reading tutorials, or watching the abundant number of videos on youtube. If you're feeling particularly generous, you could even use some of the tutorials I have on the site!
Step 4) Register with Anaconda
Registering with Anaconda is certainly optional. However, by registering you get access to the free Anaconda Cloud to store your projects, notebooks, or development environments. I have yet to work with this in depth, however, the cloud based storage option could be very helpful for users less familiar with more widespread version control tools like git, which is also available for use within the condas shell.
Part 2) Setting Up a Python Environment in Atom
Atom is a open source text editor with a wide variety of extensibility for different package integrations to make your life easier. Aside from basic functionality like syntax highlighting and dynamic encoding selections, Atom also has an ecosystem of free packages that allow you to literally run the script you're creating within the text editor window. Additionally, Atom has an out of the box version control integrations with github to visualize your branches and projects outside of the terminal. This can come in handy for users newer to version control who are looking to develop good habits for maintaining and managing code.
Within this tutorial I am going to show you how to set up a python development environment using Atom with the Hydrogen package. Prior to following the steps below, please ensure your system has a version of python installed. I've outlined some simple ways to check at the beginning of this article.
Step 1) Download Atom
Visit atom.io and download the distribution that is aligned with your operating system.
Step 2) Install Atom
Follow the installer downloaded from the site. Upon installation Atom will automatically launch on your machine with a 'Welcome Guide' tab. Within the Welcome Guide tab navigate to the icon 'Install a Package' and select 'Open Installer.' At this point a settings tab will open with a search box for specific packages.
Step 3) Install the Hydrogen package
Using the search box enter 'hydrogen' Upon searching for script you will see a tile appear for the package. Within the tile click install to automatically initiate installation. Upon the completion of both installations, restart Atom.
Step 4) Test your install and start using Hydrogen!
After restarting Atom create a new tab. You will observe no significant changes to what you observed before. However, Atom is now equipped with a powerful tool that allows you to run code on a line by line or entire script basis using Hydrogen.
To ensure Hydrogen installed properly navigate to 'Packages' in the utility pane. From there you should see 'Hydrogen' in the drop down list. Navigate to the selection to observe the key features now available for use. In my work I find the 'Run Cell and Move Down' particularly useful because it allows you to debug your code on a line by line basis prior to finalizing a script for greater use.
Navigate back to the tab you just opened and copy and paste the hello world python code below into the tab and save the file as 'hello-world.py'.
After saving the file, Atom will automatically detect the file as a python file and adjust your file type and syntax highlighting accordingly.
Within the file navigate to your first line of code and press shift-enter or shift-return for mac users. At this time you should see the image shown in figure 1.
Figure 1. Image of what a successful use of Hydrogen looks like!
As figure 1 shows, Hydrogen will execute your code line by line, similar to a Jupyter notebook launched from the Anaconda Navigator. Aside from viewing printouts, Hydrogen will visually render dataframes, charts, and crosstabs directly from the text editor!
As I previously mentioned, this is very useful for debugging long scripts of code or doing adhoc analysis. To learn more about all the exciting features Hydrogen has to offer visit the documentation page here.
Congratulations, you now have a usable python development environment set up inside Atom!
As you can likely imagine using the Anaconda Navigator or Hydrogen in Atom are not the only two ways for you to create your own python workflow. However, in my data pursuits I've found both these options ideal for a wide range of use cases. If you have another workflow that you find useful, please leave a comment below!
Until next time,