27
Software Carpentry Boot Camp Software Carpentry Boot Camp Python Python V0.1 dd 07-04-2015

Software Carpentry Boot Camp Python V0.1 dd 07-04-2015

Embed Size (px)

Citation preview

Software Carpentry Boot CampSoftware Carpentry Boot CampPythonPython

V0.1

dd 07-04-2015

Boot Camp IntroductionBoot Camp Introduction

Introductory session

•Install all necessary software http://www.strw.leidenuniv.nl/python/1ejaar/PythonBootCamp.ppt

•Get you at a basic levelhttp://www.strw.leidenuniv.nl/python/1ejaar/

or more in depthhttp://www.strw.leidenuniv.nl/python/1ejaar/

Boot Camp What SoftwareBoot Camp What Software

Required software•Python (2 or 3) https://www.python.org/downloads/

– Numpy http://www.scipy.org/scipylib/download.html – Scipy http://www.scipy.org/scipylib/download.html– Matplotlib http://matplotlib.org/users/installing.html– AstroPy (FITS) http://www.astropy.org/– h5py (HDF) http://docs.h5py.org/en/latest/build.html

•Cython http://docs.cython.org/src/quickstart/install.html•f2py (part of numpy)•Git http://git-scm.com/book/en/v2/Getting-Started-Installing-Git

Optional:•ipython http://ipython.org/install.html

Boot Camp InstallBoot Camp Install

Different Operating systemsThis document will help you out installing the required software for the Python Software Carpentry Boot Camp on the following operating systems:

MacOSLinux

FC Ubuntu

Windows

Boot Camp InstallBoot Camp Install

Python 2 or Python3python2 is legacy, python 3 is the present and future, but…Reason http://docs.python.org/py3k/whatsnew/3.0.html

• Language cleanup• Better unicode support strings• Several core aspects made more consistent• Class new-style

Why still use Python 2• Legacy

• All required packages are python 2 and 3 compatible• Many astronomical packages are python 2 ony

• Many OS-es still use version 2

Boot Camp Install MacOSBoot Camp Install MacOS

MacOS https://www.python.org/downloads/mac-osx/• If you have Yosemite (10.10.x):

• Need Python 2.7.9 (latest version)• install this next to the official OS related python

• Prerequisites:• gcc compiler (for Cython)• gfortran compiler (for f2py)

• Go to the AppStore, search Xcode and ‘Install App’, may take some time as size is 1Gb – use activity monitor to track progress…

$ python --versionPython 2.7.6

Boot Camp Install on MacOSBoot Camp Install on MacOS

• Go to the AppStore, search Xcode and ‘Install App’, may take some time as size is 1Gb – use activity monitor to track progress…– will install gcc, but we need a more recent version and

– still need to install gfortran

$ which gcc/usr/bin/gcc$ gcc –vConfigured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)Target: x86_64-apple-darwin14.1.0Thread model: posix

$ which gfortran

Boot Camp Install on MacOSBoot Camp Install on MacOS

• Go to http://hpc.sourceforge.net/ and download the appropriate version

• and install the newest version of gcc and gfortran

• which should now be in your path

gcc-5.0-bin.tar.gz, gfortran-5.0-bin.tar.gz (gfortran only), updated Nov 2014 (Yosemite).gcc-4.9-bin.tar.gz, gfortran-4.9-bin.tar.gz (gfortran only), updated Nov 2014 (Mavericks & Yosemite).gcc-4.8-bin.tar.gz, gfortran-4.8-bin.tar.gz (gfortran only), updated Oct 2013 (M. Lion & Mavericks).gcc-4.7-bin.tar.gz, gfortran-4.7-bin.tar.gz (gfortran only), updated July 2012 (Lion & M. Lion).

$ cd$ cd Downloads$ sudo tar –zxvf gcc-5.0-bin.tar.gz –C /$ sudo tar –zxvf gfortran-5.0-bin.tar.gz –C /

$ which gcc/usr/local/bin/gcc$ which gfortran/usr/local/bin/gfortran

Boot Camp Install MacOSBoot Camp Install MacOS

MacOS https://www.python.org/downloads/mac-osx/• If you have Yosemite (10.10.x):

• Need Python 2.7.9 (latest version)• install this next to the official OS related python

• Download the appropriate install package• and run the installer

$ python --versionPython 2.7.6

$ which python/usr/local/bin/python$ python –versionPython 2.7.9

Boot Camp Install MacOSBoot Camp Install MacOS

Additional packages• use the pip utility for this

• load numpy

• load scipy

• load matplotlib

$ which pip/usr/local/bin/pip

$ sudo pip install matplotlib...

$ sudo pip install numpy...

$ sudo pip install scipy...

Boot Camp Install MacOSBoot Camp Install MacOS

• load astropy

• load h5py, as you can seen, this automatically installs Cython as well

$ pip matplotlib...

$ sudo pip install astropy...

$ sudo pip install h5pyDownloading/unpacking h5py Downloading h5py-2.4.0-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.3MB): 4.3MB downloadedDownloading/unpacking Cython>=0.17 (from h5py) Downloading Cython-0.22-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.7MB): 3.7MB downloadedRequirement already satisfied (use --upgrade to upgrade): numpy>=1.6.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy-1.9.2-py2.7-macosx-10.6-intel.egg (from h5py)Installing collected packages: h5py, CythonSuccessfully installed h5py CythonCleaning up...

Boot Camp Install MacOSBoot Camp Install MacOS

GIT http://git-scm.com/download/mac• download of the .dmg should start automatically• Double click the package and then double click the installer

• iPython install

$ which git/usr/bin/git

$ sudo pip install “ipython[notebook]”...

$ cd /usr/local/bin$ sudo ln –s ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/ipython

$ which ipython/usr/local/bin/ipython

Boot Camp Install LinuxBoot Camp Install Linux

Linux https://www.python.org/downloads/source/• You can install a fresh version of python:

• Need Python 2.7.9 (latest version)• install this next to the official OS related python

• Prerequisites:• gcc compiler (for Cython)• gfortran compiler (for f2py)

$ python --versionPython 2.7.8

Boot Camp Install on LinuxBoot Camp Install on Linux

• Check version of gcc and gfortran in OS

– still need to install gfortran

$ which gcc/usr/bin/gcc$ gcc –vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linuxThread model: posixgcc version 4.9.2 20150212 (Red Hat 4.9.2-6) (GCC)

$ which gfortran/usr/bin/gfortran$ Using built-in specs.COLLECT_GCC=gfortranCOLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapperTarget: x86_64-redhat-linuxConfigured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.9.2-20150212/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linuxThread model: posixgcc version 4.9.2 20150212 (Red Hat 4.9.2-6) (GCC)

Boot Camp Install on LinuxBoot Camp Install on Linux

• Install gcc and gfortran in OS

$ which gcc $ sudo yum groupinstall "Development Tools and Libraries" # Fedora Core...

$ sudo apt-get install buildessentials # Ubuntu...

$ which gfortran

$ sudo yum install gcc-gfortran # Fedora Core...

$ sudo apt-get install gfortran # Ubuntu

Boot Camp Install LinuxBoot Camp Install Linux

• Need Python 2.7.9 (latest version)• install this next to the official OS related python

• Download the source code

$ python --versionPython 2.7.6

$ cd /data2$ wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgzConnecting to www.python.org (www.python.org)|23.235.43.223|:443... connected.HTTP request sent, awaiting response... 200 OKLength: 16657930 (16M) [application/octet-stream]Saving to: âPython-2.7.9.tgzâ

Python-2.7.9.tgz 100%[===========================================================>] 15.89M 46.5MB/s in 0.3s

2015-04-06 15:08:19 (46.5 MB/s) - Python-2.7.9.tgz saved [16657930/16657930]

Boot Camp Install on LinuxBoot Camp Install on Linux

• unpack and install in alternative directory

and set your environment to use this version:

$ tar xzvf Python-2.7.9.tgz... $ cd Python-2.7.9$ ./configure --prefix=/net/bree/data2/mypython/...$ make...$ make install...

$ vi mypython.cshsetenv PYTHONPATH /net/bree/data2/mypython/site-packagessetenv PATH "/net/bree/data2/mypython/bin/":"$PATH"

$ source mypython.csh$ which python/net/bree/data2/mypython/bin/python

Boot Camp Install on LinuxBoot Camp Install on Linux

• add python tools

and also install pip:

# Let's download the installation file using wget:wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz

# Extract the files from the archive:tar -xvf setuptools-1.4.2.tar.gz

# Enter the extracted directory:cd setuptools-1.4.2

# Install setuptools using the Python we've installed (2.7.9)python setup.py install

$ curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py |python -...

Boot Camp Install LinuxBoot Camp Install Linux

Additional packages• use the pip utility for this, note to get your personal one!

• load numpy

• load scipy

• load matplotlib

$ which pip/net/bree/data2/mypython/bin/pip

$ pip install matplotlib...

$ pip install numpy...

$ pip install scipy...

Boot Camp Install LinuxBoot Camp Install Linux

• load astropy

• load h5py, as you can seen, this automatically installs Cython as well

$ pip matplotlib...

$ pip install astropy...

$ sudo pip install h5pyDownloading/unpacking h5py Downloading h5py-2.4.0-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.3MB): 4.3MB downloadedDownloading/unpacking Cython>=0.17 (from h5py) Downloading Cython-0.22-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.7MB): 3.7MB downloadedRequirement already satisfied (use --upgrade to upgrade): numpy>=1.6.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy-1.9.2-py2.7-macosx-10.6-intel.egg (from h5py)Installing collected packages: h5py, CythonSuccessfully installed h5py CythonCleaning up...

Boot Camp Install LinuxBoot Camp Install Linux

GIT, with root access install

Download http://git-scm.com/download/

$ sudo yum install git # Fedora Core$ sudo apt-get install git # Ubuntu

$ whcih git/usr/bin/git

$ wget https://www.kernel.org/pub/software/scm/git/git-2.3.5.tar.gz...$ tar zxvf git-2.3.5.tar.gz...$cd git-2.3.5$ ./configure –prefix=/nen/bree/data2/mypython...$ make...$ make install...

Boot Camp Install LinuxBoot Camp Install Linux

• iPython install

$ pip install “ipython[notebook]”...

$ cd /usr/local/bin$ sudo ln –s ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/ipython

$ which ipython/usr/local/bin/ipython

Boot Camp Install WindowsBoot Camp Install Windows

Windows – By default Windows does not have python installed– so get the Windows x86-64 MSI installer

• Prerequisites:– Also windows does not have any compilers installed either– gcc compiler (for Cython)– gfortran compiler (for f2py)

Boot Camp Install WindowsBoot Camp Install Windows

We wil make use of Anaconda installer as this allows easy installation pypi based packages

Go to http://continuum.io/downloads– and download the Windos 4-Bit Python 2.7 Graphical Installer

Boot Camp Install WindowsBoot Camp Install Windows

$ which pip/usr/local/bin/pip

$ sudo pip install numpy...

NumPySciPyPandasPyTablesh5py

MatplotlibIPythonSpyderQt/PySideVTK

NumexprAstropyCythonLLVM, LLVMpyNumba

Scikit-learnScikit-imageNLTKNetworkXMayaVi

Featured Packages

Boot Camp Install WindowsBoot Camp Install Windows

GIT http://git-scm.com/download/win• download of the .exe should start automatically• Double click the installer and follow the instructions (allow use from Windows command line)

Data processing exampleData processing example

End