The Hitchhiker's Guide to Python

Total Page:16

File Type:pdf, Size:1020Kb

The Hitchhiker's Guide to Python The H i t c h h i k e r ’s Guide to P y t h o n BEST PRACTICES FOR DEVELOPMENT Kenneth Reitz & Tanya Schlusser The Hitchhiker’s Guide to Python Best Practices for Development Kenneth Reitz and Tanya Schlusser Beijing Boston Farnham Sebastopol Tokyo The Hitchhiker’s Guide to Python by Kenneth Reitz and Tanya Schlusser Copyright © 2016 Kenneth Reitz, Tanya Schlusser. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected]. Editor: Dawn Schanafelt Indexer: WordCo Indexing Services, Inc. Production Editor: Nicole Shelby, Nicholas Adams Interior Designer: David Futato Copyeditor: Jasmine Kwityn Cover Designer: Randy Comer Proofreader: Amanda Kersey Illustrator: Rebecca Demarest September 2016: First Edition Revision History for the First Edition 2016-08-26: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491933176 for release details. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. The Hitchhiker’s Guide to Python, the cover image, and related trade dress are trademarks of O’Reilly Media, Inc. While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-491-93317-6 [LSI] Dedicated to you Table of Contents Preface. xi Part I. Getting Started 1. Picking an Interpreter. 3 The State of Python 2 Versus Python 3 3 Recommendations 4 So…3? 4 Implementations 5 CPython 5 Stackless 5 PyPy 6 Jython 6 IronPython 6 PythonNet 6 Skulpt 7 MicroPython 7 2. Properly Installing Python. 9 Installing Python on Mac OS X 9 Setuptools and pip 11 virtualenv 11 Installing Python on Linux 12 Setuptools and pip 12 Development Tools 13 virtualenv 14 Installing Python on Windows 15 v Setuptools and pip 17 virtualenv 18 Commercial Python Redistributions 18 3. Your Development Environment. 21 Text Editors 22 Sublime Text 23 Vim 23 Emacs 25 TextMate 26 Atom 26 Code 27 IDEs 27 PyCharm/IntelliJ IDEA 29 Aptana Studio 3/Eclipse + LiClipse + PyDev 29 WingIDE 30 Spyder 30 NINJA-IDE 30 Komodo IDE 31 Eric (the Eric Python IDE) 31 Visual Studio 32 Enhanced Interactive Tools 32 IDLE 32 IPython 33 bpython 33 Isolation Tools 33 Virtual Environments 34 pyenv 36 Autoenv 36 virtualenvwrapper 37 Buildout 38 Conda 38 Docker 39 Part II. Getting Down to Business 4. Writing Great Code. 43 Code Style 43 PEP 8 44 PEP 20 (a.k.a. The Zen of Python) 45 General Advice 46 vi | Table of Contents Conventions 52 Idioms 54 Common Gotchas 58 Structuring Your Project 61 Modules 61 Packages 65 Object-Oriented Programming 66 Decorators 67 Dynamic Typing 68 Mutable and Immutable Types 69 Vendorizing Dependencies 71 Testing Your Code 72 Testing Basics 74 Examples 76 Other Popular Tools 80 Documentation 82 Project Documentation 82 Project Publication 83 Docstring Versus Block Comments 84 Logging 84 Logging in a Library 85 Logging in an Application 86 Choosing a License 88 Upstream Licenses 88 Options 88 Licensing Resources 90 5. Reading Great Code. 91 Common Features 92 HowDoI 93 Reading a Single-File Script 93 Structure Examples from HowDoI 96 Style Examples from HowDoI 97 Diamond 99 Reading a Larger Application 100 Structure Examples from Diamond 105 Style Examples from Diamond 109 Tablib 112 Reading a Small Library 112 Structure Examples from Tablib 116 Style Examples from Tablib 124 Requests 126 Table of Contents | vii Reading a Larger Library 126 Structure Examples from Requests 130 Style Examples from Requests 135 Werkzeug 140 Reading Code in a Toolkit 141 Style Examples from Werkzeug 148 Structure Examples from Werkzeug 149 Flask 155 Reading Code in a Framework 156 Style Examples from Flask 162 Structure Examples from Flask 163 6. Shipping Great Code. 167 Useful Vocabulary and Concepts 168 Packaging Your Code 169 Conda 169 PyPI 170 Freezing Your Code 172 PyInstaller 174 cx_Freeze 176 py2app 177 py2exe 178 bbFreeze 178 Packaging for Linux-Built Distributions 179 Executable ZIP Files 180 Part III. Scenario Guide 7. User Interaction. 185 Jupyter Notebooks 185 Command-Line Applications 186 GUI Applications 194 Widget Libraries 194 Game Development 200 Web Applications 200 Web Frameworks/Microframeworks 201 Web Template Engines 204 Web Deployment 209 8. Code Management and Improvement. 213 Continuous Integration 213 viii | Table of Contents System Administration 214 Server Automation 216 System and Task Monitoring 220 Speed 223 Interfacing with C/C++/FORTRAN Libraries 232 9. Software Interfaces. 237 Web Clients 238 Web APIs 238 Data Serialization 243 Distributed Systems 246 Networking 246 Cryptography 251 10. Data Manipulation. 259 Scientific Applications 260 Text Manipulation and Text Mining 264 String Tools in Python’s Standard Library 264 Image Manipulation 267 11. Data Persistence. 271 Structured Files 271 Database Libraries 272 A. Additional Notes. 287 Index. 295 Table of Contents | ix Preface Python is big. Really big. You just won’t believe how vastly hugely mind-bogglingly big it is. This guide is not intended to teach you the Python language (we cite lots of great resources that do that) but is rather an (opinionated) insider’s guide to our communi‐ ty’s favorite tools and best practices. The primary audience is new to mid-level Python programmers who are interested in contributing to open source or in begin‐ ning a career or starting a company using Python, although casual Python users should also find Part I and Chapter 5 helpful. The first part will help you choose the text editor or interactive development environ‐ ment that fits your situation (for example, those using Java frequently may prefer Eclipse with a Python plug-in) and surveys options for other interpreters that may meet needs you don’t yet know Python could address (e.g., there’s a MicroPython implementation based around the ARM Cortex-M4 chip). The second section dem‐ onstrates Pythonic style by highlighting exemplary code in the open source commu‐ nity that will hopefully encourage more in-depth reading and experimentation with open source code. The final section briefly surveys the vast galaxy of libraries most commonly used in the Python community—providing an idea of the scope of what Python can do right now. All of the royalties from the print version of this book will be directly donated to the Django Girls, a giddily joyous global organization dedicated to organizing free Django and Python workshops, creating open-sourced online tutorials, and curating amazing first experiences with technology. Those who wish to contribute to the online version can read more about how to do it at our website. xi Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program ele‐ ments such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter‐ mined by context. This element signifies a tip or suggestion. This element signifies a general note. This element indicates a warning or caution. Safari® Books Online Safari Books Online is an on-demand digital library that deliv‐ ers expert content in both book and video form from the world’s leading authors in technology and business. xii | Preface Technology professionals, software developers, web designers, and business and crea‐ tive professionals use Safari Books Online as their primary resource for research, problem solving, learning, and certification training. Safari Books Online offers a range of plans and pricing for enterprise, government, education, and individuals. Members have access to thousands of books, training videos, and prepublication manuscripts in one fully searchable database from publishers like O’Reilly Media, Prentice Hall Professional, Addison-Wesley Professional, Microsoft Press, Sams, Que, Peachpit Press, Focal Press, Cisco Press, John Wiley & Sons, Syngress, Morgan Kauf‐ mann, IBM Redbooks, Packt, Adobe Press, FT Press, Apress, Manning, New Riders, McGraw-Hill, Jones & Bartlett, Course Technology, and hundreds more. For more information about Safari Books Online, please visit us online. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at http://bit.ly/the-hitchhikers-guide-to-python. To comment or ask technical questions about this book, send email to bookques‐ [email protected]. For more information about our books, courses, conferences, and news, see our web‐ site at http://www.oreilly.com. Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Preface | xiii Acknowledgments Welcome, friends, to The Hitchhiker’s Guide to Python.
Recommended publications
  • Ironpython in Action
    IronPytho IN ACTION Michael J. Foord Christian Muirhead FOREWORD BY JIM HUGUNIN MANNING IronPython in Action Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> IronPython in Action MICHAEL J. FOORD CHRISTIAN MUIRHEAD MANNING Greenwich (74° w. long.) Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. Sound View Court 3B fax: (609) 877-8256 Greenwich, CT 06830 email: [email protected] ©2009 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15% recycled and processed without the use of elemental chlorine.
    [Show full text]
  • SPLLIFT — Statically Analyzing Software Product Lines in Minutes Instead of Years
    SPLLIFT — Statically Analyzing Software Product Lines in Minutes Instead of Years Eric Bodden1 Tarsis´ Toledoˆ 3 Marcio´ Ribeiro3;4 Claus Brabrand2 Paulo Borba3 Mira Mezini1 1 EC SPRIDE, Technische Universitat¨ Darmstadt, Darmstadt, Germany 2 IT University of Copenhagen, Copenhagen, Denmark 3 Federal University of Pernambuco, Recife, Brazil 4 Federal University of Alagoas, Maceio,´ Brazil [email protected], ftwt, [email protected], [email protected], [email protected], [email protected] Abstract A software product line (SPL) encodes a potentially large variety v o i d main () { of software products as variants of some common code base. Up i n t x = secret(); i n t y = 0; until now, re-using traditional static analyses for SPLs was virtu- # i f d e f F ally intractable, as it required programmers to generate and analyze x = 0; all products individually. In this work, however, we show how an # e n d i f important class of existing inter-procedural static analyses can be # i f d e f G transparently lifted to SPLs. Without requiring programmers to y = foo (x); LIFT # e n d i f v o i d main () { change a single line of code, our approach SPL automatically i n t x = secret(); converts any analysis formulated for traditional programs within the print (y); } i n t y = 0; popular IFDS framework for inter-procedural, finite, distributive, y = foo (x); subset problems to an SPL-aware analysis formulated in the IDE i n t foo ( i n t p) { print (y); framework, a well-known extension to IFDS.
    [Show full text]
  • Python on Gpus (Work in Progress!)
    Python on GPUs (work in progress!) Laurie Stephey GPUs for Science Day, July 3, 2019 Rollin Thomas, NERSC Lawrence Berkeley National Laboratory Python is friendly and popular Screenshots from: https://www.tiobe.com/tiobe-index/ So you want to run Python on a GPU? You have some Python code you like. Can you just run it on a GPU? import numpy as np from scipy import special import gpu ? Unfortunately no. What are your options? Right now, there is no “right” answer ● CuPy ● Numba ● pyCUDA (https://mathema.tician.de/software/pycuda/) ● pyOpenCL (https://mathema.tician.de/software/pyopencl/) ● Rewrite kernels in C, Fortran, CUDA... DESI: Our case study Now Perlmutter 2020 Goal: High quality output spectra Spectral Extraction CuPy (https://cupy.chainer.org/) ● Developed by Chainer, supported in RAPIDS ● Meant to be a drop-in replacement for NumPy ● Some, but not all, NumPy coverage import numpy as np import cupy as cp cpu_ans = np.abs(data) #same thing on gpu gpu_data = cp.asarray(data) gpu_temp = cp.abs(gpu_data) gpu_ans = cp.asnumpy(gpu_temp) Screenshot from: https://docs-cupy.chainer.org/en/stable/reference/comparison.html eigh in CuPy ● Important function for DESI ● Compared CuPy eigh on Cori Volta GPU to Cori Haswell and Cori KNL ● Tried “divide-and-conquer” approach on both CPU and GPU (1, 2, 5, 10 divisions) ● Volta wins only at very large matrix sizes ● Major pro: eigh really easy to use in CuPy! legval in CuPy ● Easy to convert from NumPy arrays to CuPy arrays ● This function is ~150x slower than the cpu version! ● This implies there
    [Show full text]
  • The Essentials of Stackless Python Tuesday, 10 July 2007 10:00 (30 Minutes)
    EuroPython 2007 Contribution ID: 62 Type: not specified The Essentials of Stackless Python Tuesday, 10 July 2007 10:00 (30 minutes) This is a re-worked, actualized and improved version of my talk at PyCon 2007. Repeating the abstract: As a surprise for people who think they know Stackless, we present the new Stackless implementation For PyPy, which has led to a significant amount of new insight about parallel programming and its possible implementations. We will isolate the known Stackless as a special case of a general concept. This is a Stackless, not a PyPy talk. But the insights presented here would not exist without PyPy’s existance. Summary Stackless has been around for a long time now. After several versions with different goals in mind, the basic concepts of channels and tasklets turned out to be useful abstractions, and since many versions, Stackless is only ported from version to version, without fundamental changes to the principles. As some spin-off, Armin Rigo invented Greenlets at a Stackless sprint. They are some kind of coroutines and a bit of special semantics. The major benefit is that Greenlets can runon unmodified CPython. In parallel to that, the PyPy project is in its fourth year now, and one of its goals was Stackless integration as an option. And of course, Stackless has been integrated into PyPy in a very nice and elegant way, much nicer than expected. During the design of the Stackless extension to PyPy, it turned out, that tasklets, greenlets and coroutines are not that different in principle, and it was possible to base all known parallel paradigms on one simple coroutine layout, which is as minimalistic as possible.
    [Show full text]
  • Introduction Shrinkage Factor Reference
    Comparison study for implementation efficiency of CUDA GPU parallel computation with the fast iterative shrinkage-thresholding algorithm Younsang Cho, Donghyeon Yu Department of Statistics, Inha university 4. TensorFlow functions in Python (TF-F) Introduction There are some functions executed on GPU in TensorFlow. So, we implemented our algorithm • Parallel computation using graphics processing units (GPUs) gets much attention and is just using that functions. efficient for single-instruction multiple-data (SIMD) processing. 5. Neural network with TensorFlow in Python (TF-NN) • Theoretical computation capacity of the GPU device has been growing fast and is much higher Neural network model is flexible, and the LASSO problem can be represented as a simple than that of the CPU nowadays (Figure 1). neural network with an ℓ1-regularized loss function • There are several platforms for conducting parallel computation on GPUs using compute 6. Using dynamic link library in Python (P-DLL) unified device architecture (CUDA) developed by NVIDIA. (Python, PyCUDA, Tensorflow, etc. ) As mentioned before, we can load DLL files, which are written in CUDA C, using "ctypes.CDLL" • However, it is unclear what platform is the most efficient for CUDA. that is a built-in function in Python. 7. Using dynamic link library in R (R-DLL) We can also load DLL files, which are written in CUDA C, using "dyn.load" in R. FISTA (Fast Iterative Shrinkage-Thresholding Algorithm) We consider FISTA (Beck and Teboulle, 2009) with backtracking as the following: " Step 0. Take �! > 0, some � > 1, and �! ∈ ℝ . Set �# = �!, �# = 1. %! Step k. � ≥ 1 Find the smallest nonnegative integers �$ such that with �g = � �$&# � �(' �$ ≤ �(' �(' �$ , �$ .
    [Show full text]
  • Vxworks Third Party Software Notices
    Wind River® VxWorks® 7 Third Party License Notices This document contains third party intellectual property (IP) notices for the BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY Wind River® VxWorks® 7 distribution. Certain licenses and license notices THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, may appear in other parts of the product distribution in accordance with the OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN license requirements. ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Trademarks All company, product and service names used in this software are for ACPICA identification purposes only. Version: 20170303 Component(s): Runtime Wind River and VxWorks are registered trademarks of Wind River Systems. Description: Provides code to implement ACPI specification in VxWorks. UNIX is a registered trademark of The Open Group. IBM and Bluemix are registered trademarks of the IBM Corporation. NOTICES: All other third-party trademarks are the property of their respective owners. 1. Copyright Notice Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp. All rights reserved. Third Party Notices 2. License 2.1. This is your license from Intel Corp. under its intellectual property rights. You may have additional license terms from the party that provided you this software, covering your right to use that party's intellectual property rights. 64-Bit Dynamic Linker Version: 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a copy Component(s): Runtime of the source code appearing in this file ("Covered Code") an irrevocable, Description: The dynamic linker is used to load shared libraries.
    [Show full text]
  • Simple Plotter Documentation Release 0.0.0
    simple_plotter Documentation Release 0.0.0 Thies Hecker Mar 30, 2020 Contents: 1 Getting started 3 1.1 Desktop..................................................3 1.2 Android..................................................3 1.3 Configuration options..........................................4 1.4 Requirements...............................................4 1.5 Source code...............................................4 2 User guide 7 2.1 Overview.................................................7 2.2 Defining an equation...........................................7 2.3 Creating a plot..............................................8 2.4 Adjust the plot appearance........................................8 2.5 Constants.................................................9 2.6 Plotting curve sets............................................ 10 2.7 Plot labels................................................ 11 2.8 Load, save and export.......................................... 12 2.9 Advanced usage............................................. 12 3 Licenses 17 3.1 simple-plotter............................................... 17 3.2 simple-plotter-qt............................................. 18 3.3 simple-plotter4a............................................. 18 3.4 simple-plotter4a binary releases (Android)............................... 18 4 Contributing 43 4.1 Concept.................................................. 43 4.2 Package versions............................................. 43 4.3 Building conda packages........................................
    [Show full text]
  • Implementation of Calfem for Python
    IMPLEMENTATION OF CALFEM FOR PYTHON ANDREAS OTTOSSON Structural Master’s Dissertation Mechanics Detta är en tom sida! Department of Construction Sciences Structural Mechanics ISRN LUTVDG/TVSM--10/5167--SE (1-47) ISSN 0281-6679 IMPLEMENTATION OF CALFEM FOR PYTHON Master’s Dissertation by ANDREAS OTTOSSON Supervisors: Jonas Lindemann, PhD, Div. of Structural Mechanics Examiner: Ola Dahlblom, Professor, Div. of Structural Mechanics Copyright © 2010 by Structural Mechanics, LTH, Sweden. Printed by Wallin & Dalholm Digital AB, Lund, Sweden, August, 2010 (Pl). For information, address: Division of Structural Mechanics, LTH, Lund University, Box 118, SE-221 00 Lund, Sweden. Homepage: http://www.byggmek.lth.se Detta är en tom sida! Preface The work presented in this masters’s thesis was carried out during the period June 2009 to August 2010 at the Division of Structural Mechanics at the Faculty of Engineering, Lund University, Sweden. I would like to thank the staff of the Department of Structural Mechanics, es- pecially my supervisor Jonas Lindemann, for help during this work. I would also like to thank my Jennie, and both our families, for their support throughout my education. Lund, August 2010 Andreas Ottosson i Contents 1 Introduction 1 1.1Background.............................. 1 1.2WhyCALFEMforPython?..................... 1 1.3 Objective ............................... 1 2MATLAB 3 2.1Background.............................. 3 2.2 Objects ................................ 3 3 Python and NumPy 5 3.1Python................................ 5 3.1.1 Background.......................... 5 3.1.2 Influences ........................... 5 3.1.3 Objects ............................ 6 3.2NumPy................................ 6 3.2.1 Objects ............................ 7 3.2.2 Commonmatrixoperations................. 8 4 Integrated Development Environments 11 4.1MATLAB............................... 11 4.2PythonIDLE............................. 12 4.3IPython...............................
    [Show full text]
  • Eric Franklin Enslen
    Eric Franklin Enslen email:[email protected]!403 Terra Drive phone:!(302) 827-ERIC (827-3742)!Newark, DE website:! www.cis.udel.edu/~enslen!19702 Education: Bachelor of Science in Computer and Information Sciences University of Delaware, Newark, DE!May 2011 Major GPA: 3.847/4.0 Academic Experience: CIS Study Abroad, London, UK!Summer 2008 Visited research labs at University College London, King"s College, and Brunel University, as well as IBM"s Hursley Park, and studied Software Testing and Tools for the Software Life Cycle Relevant Courses: Computer Ethics, Digital Intellectual Property, Computer Graphics, and Computational Photography Academic Honors: Alumni Enrichment Award, University of Delaware Alumni Association, Newark, DE!May 2009 Travel fund to present a first-author paper at the the 6th Working Conference on Mining Software Repositories (MSR), collocated with the 2009 International Conference on Software Engineering (ICSE) Hatem M. Khalil Memorial Award, College of Arts and Sciences, University of Delaware, Newark, DE!May 2009 Awarded to a CIS major in recognition of outstanding achievement in software engineering, selected by CIS faculty Deanʼs List, University of Delaware, Newark, DE!Fall 2007, Spring 2008, Fall 2008 and Fall 2009 Research Experience: Undergraduate Research, University of Delaware, Newark, DE!January 2009 - Present Developing, implementing, evaluating and documenting an algorithm to split Java identifiers into their component words in order to improve natural-language-based software maintenance tools. Co-advisors: Lori Pollock, K. Vijay-Shanker Research Publications: Eric Enslen, Emily Hill, Lori Pollock, K. Vijay-Shanker. “Mining Source Code to Automatically Split Identifiers for Software Analysis.” 6th Working Conference on Mining Software Repositories, May 2009.
    [Show full text]
  • Python Programming
    Python Programming Wikibooks.org June 22, 2012 On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An URI to this license is given in the list of figures on page 149. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 143. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 153, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of figures on page 149. This PDF was generated by the LATEX typesetting software. The LATEX source code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the PDF file, we recommend the use of http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting Save Attachment. After extracting it from the PDF file you have to rename it to source.7z. To uncompress the resulting archive we recommend the use of http://www.7-zip.org/.
    [Show full text]
  • Xcode Package from App Store
    KH Computational Physics- 2016 Introduction Setting up your computing environment Installation • MAC or Linux are the preferred operating system in this course on scientific computing. • Windows can be used, but the most important programs must be installed – python : There is a nice package ”Enthought Python Distribution” http://www.enthought.com/products/edudownload.php – C++ and Fortran compiler – BLAS&LAPACK for linear algebra – plotting program such as gnuplot Kristjan Haule, 2016 –1– KH Computational Physics- 2016 Introduction Software for this course: Essentials: • Python, and its packages in particular numpy, scipy, matplotlib • C++ compiler such as gcc • Text editor for coding (for example Emacs, Aquamacs, Enthought’s IDLE) • make to execute makefiles Highly Recommended: • Fortran compiler, such as gfortran or intel fortran • BLAS& LAPACK library for linear algebra (most likely provided by vendor) • open mp enabled fortran and C++ compiler Useful: • gnuplot for fast plotting. • gsl (Gnu scientific library) for implementation of various scientific algorithms. Kristjan Haule, 2016 –2– KH Computational Physics- 2016 Introduction Installation on MAC • Install Xcode package from App Store. • Install ‘‘Command Line Tools’’ from Apple’s software site. For Mavericks and lafter, open Xcode program, and choose from the menu Xcode -> Open Developer Tool -> More Developer Tools... You will be linked to the Apple page that allows you to access downloads for Xcode. You wil have to register as a developer (free). Search for the Xcode Command Line Tools in the search box in the upper left. Download and install the correct version of the Command Line Tools, for example for OS ”El Capitan” and Xcode 7.2, Kristjan Haule, 2016 –3– KH Computational Physics- 2016 Introduction you need Command Line Tools OS X 10.11 for Xcode 7.2 Apple’s Xcode contains many libraries and compilers for Mac systems.
    [Show full text]
  • How to Access Python for Doing Scientific Computing
    How to access Python for doing scientific computing1 Hans Petter Langtangen1,2 1Center for Biomedical Computing, Simula Research Laboratory 2Department of Informatics, University of Oslo Mar 23, 2015 A comprehensive eco system for scientific computing with Python used to be quite a challenge to install on a computer, especially for newcomers. This problem is more or less solved today. There are several options for getting easy access to Python and the most important packages for scientific computations, so the biggest issue for a newcomer is to make a proper choice. An overview of the possibilities together with my own recommendations appears next. Contents 1 Required software2 2 Installing software on your laptop: Mac OS X and Windows3 3 Anaconda and Spyder4 3.1 Spyder on Mac............................4 3.2 Installation of additional packages.................5 3.3 Installing SciTools on Mac......................5 3.4 Installing SciTools on Windows...................5 4 VMWare Fusion virtual machine5 4.1 Installing Ubuntu...........................6 4.2 Installing software on Ubuntu....................7 4.3 File sharing..............................7 5 Dual boot on Windows8 6 Vagrant virtual machine9 1The material in this document is taken from a chapter in the book A Primer on Scientific Programming with Python, 4th edition, by the same author, published by Springer, 2014. 7 How to write and run a Python program9 7.1 The need for a text editor......................9 7.2 Spyder................................. 10 7.3 Text editors.............................. 10 7.4 Terminal windows.......................... 11 7.5 Using a plain text editor and a terminal window......... 12 8 The SageMathCloud and Wakari web services 12 8.1 Basic intro to SageMathCloud...................
    [Show full text]