CME 193 - Introduction to Scientific PythonGetting startedGetting started with Python can be a little confusing, hopefully this webpage helps to get you going. RequirementsThere are two components to running Python (locally).
Another option is to run Python in the cloud (see below) Installing PythonIn this clase, we will be using Python 2. The following two methods are preferred for installing Python. Note that even though Macs come with Python, it is still recommended to install Python using either Anaconda or Homebrew. AnacondaOne convenient method to set up your Python environment is using a free, pre-packaged distribution, such as Anaconda (Click the big bright blue button on the top right). This has the advantage that many relevant packages come pre-installed, possibly saving you some headaches later on. It also includes pip, the Python package manager. Note that while Anaconda also comes with the Anaconda launcher and a bunch of other tools, you should not be using any of these for this course. We only use Anaconda for the convenience of installation of Python and the main packages, not the other stuff that comes with it as well. Homebrew (Mac only)If you want a bit more control over your Python distribution, then using Homebrew to install Python is useful. It also installs the package manager pip for you, which is very useful. However, it does not come with additional modules, such as numpy or scipy, though they can be installed easily using pip. A short tutorial can be found here. EditorTo write code, you need an editor. While there are many options, old and new, Sublime Text is one you can't go wrong with. Note you can use it for free. A script is a simple file with text, such as hello.py
a = 'Hello,' b = 'world!' print a + ' ' + b which you can save to your filesystem using the editor. Running codeNow that you know how to write Python scripts, it's time to learn how to run them using Python. MacOpen the terminal, for example by searching for terminal using the spotlight search function. To open the interpreter, simply enter python. To run a script, navigate to the folder that contains your script. Then simply run python script.py, given that script.py is the name of your script. Online, you can find some good resources that introduce the terminal, such as
WindowsOpen the command prompt by searching for cmd in the Start menu. This is the Windows version of the terminal. To open the interpreter, similar to the Mac terminal, we simply run python. To run a script, navigate to the folder that contains your script, and then run python script.py, given that script.py is the file name. Also for Windows, there are some good resources about the command prompt PipTo install new modules, make sure you have pip installed. It comes with both Anaconda and Homebrew, so if you have used either of them, you are good. Otherwise, it is also rather straightforward to install pip: See the documentation. Then, open the terminal / command prompt, and run pip install module, where module is the name of the module. Note that you cannot run this from inside the Python interpreter. Python in the cloudWhen you have trouble getting Python up and running, or if you have Windows and would like to use a Unix environment, then there is an alternative: using your browser. There are several possibilities, but to be on the same page, I suggest you use Cloud 9. Cloud 9 will host your development environment on the cloud for free. Please create an account at c9.io if you are not able to run Python locally, so you can at least get started. |