All the needed dependencies for setting up your Mac, Linux, or Windows machine for these tutorials.
The installation will depend on your operating system, but overall, you will need:
Macs come with Python pre-installed. To double-check, open up the Terminal application (Applications → Utilities → Terminal like so), then type python
:
1 2 3 4 5 | $ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
|
This is the Python shell. To close out, press CTRL
+D
, or type exit()
.
Python.org has a good Python on the Mac page if the above does not work for you.
You will need to install git on your machine through their download page. You can then follow the Save your Progress page to set it up.
For Mac OS X 10.9 and higher (Mavericks and later): Within your terminal, run xcode-select --install
. A pop-up will ask you to install command line developer tools.
For Mac OS X 10.8 and lower (Mountain Lion and earlier), you will need to download the Command Line Tools from Apple here. A (free) developer’s account is required. Search for your OS version (which can be found by clicking on the Apple in the top left of your menu bar, and selecting “About this Mac”) and select “Command Line Tools for XCode”.
This gives you the GCC or the GNU Compiler Collection. To test installation, within the Terminal application, type gcc
and you should get the following:
1 2 | $ gcc
i686-apple-darwin11-llvm-gcc-4.2: no input files
|
pip, stands for “python install python”, is a tool for installing and managing Python packages. Within your Terminal application, use the following commands (ignore the leading $
as that is your terminal prompt) for downloading & installing. It may prompt you for your computer login password.
1 2 3 4 | $ curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | sudo python
$ pip --version
pip 1.5.6 from /Users/lynn/.virtualenvs/gui/lib/python2.7/site-packages (python 2.7)
$ sudo pip install --upgrade setuptools
|
virtualenv creates isolated environments for each of your Python projects. It helps to solve version & dependency problems with multple Python installations and/or multiple versions of different Python packages. We’ll use pip
to install it:
1 | $ sudo pip install virtualenv
|
virtualenvwrapper is a great (but not required) tool for using virtualenv by simplifying the commands that virtualenv needs. We’ll use pip
again to install it:
zsh
instead of bash
(the default), then replace all instances below of ~/.bash_profile
with ~/.zshrc
1 2 3 4 5 6 | $ sudo pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ echo 'export WORKON_HOME=~/Envs' >> ~/.bash_profile
$ echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
|
Linux come with Python pre-installed. To double-check, open up the Terminal application, then type python
:
1 2 3 4 5 | $ python
Python 2.7.3 (default, Aug 9 2012, 17:23:57)
[GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
|
This is the Python shell. To close out, press CTRL
+D
, or type exit()
.
You will need to install git either from commands below or through their download page. You can then follow the Save your Progress page to set it up.
sudo yum install git
sudo apt-get install git
A C compiler, either GCC or clang, is needed because the numpy
library we are using has some C extensions, which will need to be compiled.
To test if you have either GCC or clang, type $ gcc
or $ clang
into your terminal. If you get an error that says “command not found” then follow the install instructions:
sudo yum groupinstall "Developer Tools"
sudo yum install python-devel
sudo apt-get update
first.sudo apt-get install build-essential python-dev libxml2-dev libxslt-dev
pip, stands for “python install python”, is a tool for installing and managing Python packages. Within your Terminal application, use the following commands (ignore the leading $
as that is your terminal prompt) for downloading & installing. It may prompt you for your computer login password.
1 2 3 4 | $ curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | sudo python
$ pip --version
pip 1.5.6 from /Users/lynn/.virtualenvs/gui/lib/python2.7/site-packages (python 2.7)
$ sudo pip install --upgrade setuptools
|
virtualenv creates isolated environments for each of your Python projects. It helps to solve version & dependency problems with multple Python installations and/or multiple versions of different Python packages. We’ll use pip
to install it:
1 | $ sudo pip install virtualenv
|
virtualenvwrapper is a great (but not required) tool for using virtualenv by simplifying the commands that virtualenv needs. We’ll use pip
again to install it.
zsh
instead of bash
(the default), then replace all instances below of ~/.bash_profile
with ~/.zshrc
For Fedora/RHEL/CentOS:
1 2 3 4 5 6 | $ sudo pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ echo 'export WORKON_HOME=~/Envs' >> ~/.bash_profile
$ echo 'source /usr/local/bin/virtualenvwrapper.sh' >> ~/.bash_profile
$ mkdir -p $WORKON_HOME
$ source ~/.bash_profile
|
For Debian/Ubuntu:
1 2 3 4 5 6 | $ sudo pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ echo 'export WORKON_HOME=~/Envs' >> ~/.bash_profile
$ echo 'source /etc/bash_completion.d/virtualenvwrapper' >> ~/.bash_profile
$ mkdir -p $WORKON_HOME
$ source ~/.bash_profile
|
powershell
, right click on the Windows Powershell tile bar and select ‘Run as Administrator’.powershell
into the Search field directly above the Start menu button, right click on Powershell in the search results above the Search field, select “Run as Administrator”.powershell
, right click on the Windows Powershell tile bar and select “Run as Administrator”.powershell
into the Search field directly above the Start menu button, and right click on “powershell” in the search results above the Search field, and select “Run as Administrator”.At this C:\>
prompt that appears, test your Python install by typing python
and hitting enter
. You should see something like
1 2 3 | Python 2.7.3 (r271:86832,...) on win32
Type "help", "copyright", "credits" or "license" for more information
>>>
|
You just started Python! The >>>
indicates that you are at a new type of prompt – a Python prompt. The Powershell prompt lets you navigate your computer and run programs, and the Python prompt lets you write and run Python code interactively.
To exit the Python prompt, type quit()
and press Enter. This will take you back to the Windows command prompt (the C:\>
you saw earlier).
If you do not see the above specified return message, put Python on the PATH:
Edit the Path
Within “System variables", scroll down and find the one labeled “Path”. Click the “Edit…” button.
In the “Variable value” box, scroll to the end. Add the following text, and hit OK. Make sure to include the semicolon at the start!
;c:\python27\;c:\python27\scripts;c:\python27\tools\scripts
If within “System variables” you do not find “Path”, click on New. It will bring up a dialog box, type in “Path” in the first section, and then in the second section labelled “Variable value”, type in the following text and hit “OK”.
;c:\python27\;c:\python27\scripts;c:\python27\tools\scripts
Hit “OK” to close out the system properties window.
Test your change:
python
into the Powershell prompt to start Python>>>
prompt.quit()
and hitting enter. Now you’re back at the Powershell prompt (PS C:\>
).Success! You have installed Python!
;C:\Program Files\Git\bin
to the end of PATH in “System Variables” (see above Python Installation instructions). Make sure to click in the box to unhighlight before adding this new text.git --version
into the Powershell prompt.Set-ExecutionPolicy RemoteSigned
type and hit enter. When you see the Execution Policy Change prompt, type in Y
and hit enter.git is ready to go!
ez_setup.py
to run it:
ez_setup
as the filename, make sure it’s saved as a .py
file, and click “Save”.ez_setup
file by typing the following and hitting enter python ~\Desktop\ez_setup.py
get_pip
as the filename, ensure it’s being saved as a .py
file and click “Save”.python ~\desktop\get_pip.py
pip install virtualenv
pip install virtualenvwrapper-powershell
mkdir ~/.virtualenvs
Directory: C:\Users
.Import-Module virtualenvwrapper
Get-Command *virtualenv*
Success! You have installed Virtualenvwrapper!
Now let’s test our installation and get familiar with creating & using virtual environments, let’s return to our terminal:
1 2 3 4 5 6 7 8 9 10 11 | $ mkvirtualenv TestEnv
Installing
distribute..........................................
....................................................
....................................................
...............................done.
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/predeactivate
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/postdeactivate
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/preactivate
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/lynnroot/Envs/TestEnv/bin/get_env_details
|
Now that you made a virtual environment called TestEnv
, you should see (TestEnv)
before your prompt:
1 | (TestEnv) $
|
Let’s play around with commands for virtualenv:
1 2 3 4 5 6 | # deactivate the TestEnv
(TestEnv) $ deactivate
$
# reactivate the TestEnv
$ workon TestEnv
(TestEnv) $
|
Next, we’ll practice installing a package into the virtualenv:
1 2 3 4 5 6 7 8 9 10 11 | # install the Django package in your TestEnv environment
(TestEnv) $ pip install django
Downloading/unpacking django
Downloading Django-1.1.1.tar.gz (5.6Mb): 5.6Mb downloaded
Running setup.py egg_info for package django
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.6/django-admin.py from 644 to 755
changing mode of /Users/lynnroot/Envs/TestEnv/bin/django-admin.py to 755
Successfully installed django
(TestEnv) $
|
1 2 3 4 5 6 7 8 9 10 | # test the installation of Django
(TestEnv) $ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> exit()
# deactivate the TestEnv virtual environment
(TestEnv) $ deactivate
$
|
1 2 3 4 5 6 7 8 9 10 11 12 | # try to import Django again
# we should get an error because we deactivated the virtualenv
$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>> exit()
$
|
1 2 3 4 5 6 7 8 9 10 11 | # reactivate the TestEnv virtual environment
$ workon TestEnv
(TestEnv) $
# try again to import Django
(TestEnv) $ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> exit()
(TestEnv) $
|
1 2 3 4 | # see what libraries are installed in the TestEnv virtual environment:
(TestEnv) $ pip freeze
django==1.5
(TestEnv) $
|
Here’s a run-down of useful commands for pip, virtualenv & virtualenvwrapper.
mkvirtualenv [ENV_NAME]
– creates and activates a fresh virtual environmentworkon [ENV_NAME]
– activates an already-created virtual environmentdeactivate
– deactivates the virtual environment that is currently activepip install [PACKAGE_NAME]
installs a package into the virtualenvpip freeze
lists the packages that is installed & accessible within the virtualenv1 2 3 4 5 6 7 8 9 10 11 | C:\> mkvirtualenv TestEnv
Installing
distribute..........................................
....................................................
....................................................
...............................done.
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/predeactivate
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/postdeactivate
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/preactivate
virtualenvwrapper.user_scripts Creating /Users/lynnroot/Envs/TestEnv/bin/postactivate
virtualenvwrapper.user_scripts creating /Users/lynnroot/Envs/TestEnv/bin/get_env_details
|
Now that you made a virtual environment called TestEnv
, you should see (TestEnv)
before your prompt:
1 | (TestEnv) C:\>
|
Let’s play around with commands for virtualenv:
1 2 3 4 5 6 | # deactivate the TestEnv
(TestEnv) C:\> deactivate
C:\>
# reactivate the TestEnv
C:\> workon TestEnv
(TestEnv) C:\>
|
Next, we’ll practice installing a package into the virtualenv:
1 2 3 4 5 6 7 8 9 10 11 | # install the Django package in your TestEnv environment
(TestEnv) C:\> pip install django
Downloading/unpacking django
Downloading Django-1.1.1.tar.gz (5.6Mb): 5.6Mb downloaded
Running setup.py egg_info for package django
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.6/django-admin.py from 644 to 755
changing mode of /Users/lynnroot/Envs/TestEnv/bin/django-admin.py to 755
Successfully installed django
(TestEnv) C:\>
|
1 2 3 4 5 6 7 8 9 10 | # test the installation of Django
(TestEnv) C:\> python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> quit()
# deactivate the TestEnv virtual environment
(TestEnv) C:\> deactivate
C:\>
|
1 2 3 4 5 6 7 8 9 10 11 12 | # try to import Django again
# we should get an error because we deactivated the virtualenv
C:\> python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>> quit()
C:\>
|
1 2 3 4 5 6 7 8 9 10 11 | # reactivate the TestEnv virtual environment
C:\> workon TestEnv
(TestEnv) C:\>
# try again to import Django
(TestEnv) C:\> python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> quit()
(TestEnv) C:\>
|
1 2 3 4 | # see what libraries are installed in the TestEnv virtual environment:
(TestEnv) C:\> pip freeze
django==1.5
(TestEnv) C:\>
|
For Powershell:
pwd
: Get and display the current locationcd <path>
: Move to a different directory/locationcd ..
: Move to the parent locationls <path>
:List all objects in that directoryls
:List all objects in current directorymkdir
: create a new directoryWithin your terminal:
To get to your “Home” directory:
1 | $ cd
|
To create a new Projects
folder and move to that directory. You can name it whatever you want, just remember what you named it, and where it is:
1 2 | $ mkdir Projects
$ cd Projects
|
Clone the New Coder project into the directory you’re currently in, which is Projects
(unless you named it something else):
1 | $ git clone https://github.com/econchick/new-coder.git
|
When you clone a repo with the above command, git creates a directory. Here, git created the new-coder
directory within our Projects
directory. If you were to open up your file browser (e.g. Finder in Mac), the file hierarchy would look like the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 | .
└── Projects/
└── new-coder/
├── AUTHORS.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── apis/ # sample code for tutorial #2
├── dataviz/ # sample code for tutorial #1
├── gui/ # sample code for tutorial #5
├── network/ # sample code for tutorial #4
├── scrape/ # sample code for tutorial #3
└── website/ # files that make newcoder.io
|
When you work through each project, make a new directory within Projects
to keep your code away from the sample code. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | .
└── Projects/
└── new-coder/
# <-- snip -->
├── apis/ # sample code for tutorial #2
├── apis_workspace/ # your code for tutorial #2
├── dataviz/ # sample code for tutorial #1
├── dataviz_workspace/ # your code for tutorial #1
├── gui/ # sample code for tutorial #5
├── gui_workspace/ # your code for tutorial #5
├── network/ # sample code for tutorial #4
├── network_workspace/ # your code for tutorial #4
├── scrape/ # sample code for tutorial #3
├── scrape_workspace/ # your code for tutorial #3
└── website/ # files that make newcoder.io
|
You’re good to go with your setup! Go start on dataviz!