Installing Python

Installing Python

Python Installation and Usage Guide August 20, 2018 Contents 1 Overview 2 2 Windows 10 3 2.1 Installing Python . 3 2.2 Using Python . 4 2.2.1 Writing Code . 4 2.2.2 Using the PowerShell . 5 2.3 Optional: Choosing and Customizing a Text Editor . 7 2.4 Optional: Linux Subsystem on Windows . 8 2.5 Optional: Installing and Using Spyder . 9 2.6 Other Options ........................... 9 3 Linux (Ubuntu) 9 4 Mac OSX 10 5 Running in a lab/classroom 11 6 ALL OS - Installing Packages - VERY IMPORTANT 11 6.1 On Linux . 11 6.2 Installing a package (DO BEFORE HW 1) . 12 1 1 Overview Welcome to Mathematical Physics! To get started we will get setup and com- fortable using Python. Python is widely used and because of this, we should have little to no problem running it in the lab and on our own machines. There are sections in this document for Windows 10, Mac OSX, and Linux (Ubuntu) installation and usage instructions - as well as how to run our pro- grams on campus machines with what is already installed. Some optional details are included in the Windows section which you may find fit your work flow or are easier to use. (The text editor section actually can apply to all OSes). We want everyone to build comfort with using a terminal. While there are lots of IDEs (pretty and easy to use development environments) out there, a goal of this course is to become comfortable in the terminal environment. IDEs will not always be available, and in a lot of applications running from the terminal is much preferred (it's faster, and everyone has a terminal). For example, if you need to use a supercomputer to run a complex simulation you wrote, you're gonna be running it on a Linux terminal. This guide will however include instructions for installing an IDE called Spy- der. If you prefer to work with this that is ok, provided you can operate the terminal still. Keep in mind we will be running from the terminal in lecture examples. We will use Python 3, don't use a Python 2 installation as some things may not work in the future. They may still work, but better to be proactive against issues. The specific version (3.5.6 or 3.7 or 3.X etc) shouldn't matter. Knock on wood 2 2 Windows 10 2.1 Installing Python This is actually somewhat kind of pretty easy in Windows (most things are not when it comes to installing languages/packages that you could do super easily in Linux). Start by going here: https://www.python.org/downloads/ Click the download button for the most current version. Once the download finishes run the installer. IMPORTANT: Don't just automatically click through this first screen. First take note of the install location it is suggesting. Take note of this, it may or may not be needed later. Second, check the box to add Python 3.7 to PATH. This allows your terminal to know where all the stuff to run Python is. Now you can click Install now. The installation should finish quickly and you can close the installer. 3 2.2 Using Python 2.2.1 Writing Code The application you use to write code has very few limitations. You can use something as basic as notepad (not the best), fully customizable text editors, Integrated Development Environments, or you can go old school and edit in terminal with VIM or eMacs. This is really up to you. The lab machines all have the text editor Atom available. Install what you like on your personal machine - see suggestions below. Let's test your Python installation in a quick and easy way. Open Notepad or Atom if you have it already and copy the following line: print("Hello, world!") Save the file as helloWorld.py in a folder you have for this class, we'll run it next. NOTE: If you use Notepad for this, be sure to check that it saves with the .py file extension - it might default to a text file and save it as hello.py.txt which will not work. 4 2.2.2 Using the PowerShell Open the start menu and type powershell. Open up the Windows Pow- erShell (and maybe pin it to your start menu or taskbar). This termi- nal is much better than the windows Command Line you may have seen. Many of the commands are the same as on a Linux terminal - cd ls mkdir .... If you're not comfortable navigating your files in the PowerShell, check out this guide https://programminghistorian.org/en/lessons/intro- to-powershell#navigation, or come get help if you still have trouble. Navigate the PowerShell using the cd command to where you saved hello.py. If you type ls you should see it in the list of files at your current location. If it's there then enter python hello.py If it worked, you should see your greeting to the world. This is the stereo- typical thing to do when starting programming (See: https://www.reddit. com/r/comics/comments/64sybe/hello_world_oc/) In this case you won't need the file path you copied from the installer. 5 If this doesn't work you might need to put Python in your path manually. Go to the start menu, type powershell and open the Windows PowerShell. Copy the following command, and replace <LOCATION> with the install loca- tion you copied from the installer (get rid of the angle brackets too - NOT the quotes!). [Environment]::SetEnvironmentVariable("Path", "$env:Path;<LOCATION>") For example, on my machine this looked like: [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:nUsersnDanielnAppData nLocalnProgramsnPythonnPython37-32n") BE CAREFUL. Messing this up could cause some serious issues on your machine. These are your computer's environment variables, the bits of data that it uses constantly to connect things together. Note that the Python37-32 portion should have been in the location from the installer. If not, simply add this. This name may change based on the version, so if this still doesn't work, check the topmost Python folder and 6 choose the highest numbered folder. You can check to make sure this folder contains a python.exe file. If you're still having trouble, send me an email at [email protected] or come to office hours. If you need to run code ASAP look at the option to install Spyder below. 2.3 Optional: Choosing and Customizing a Text Edi- tor Notepad++ - A barebones but still useful editor, Notepad++ handles some syntax highlighting and an autocomplete that really just remembers words you have already typed (i.e. no handy function usage info like in Atom with autocomplete packages. Atom - This is my personal favorite, but for good reason. Atom is completely open source, meaning it is excessively customizable and many developers cre- ate add on packages for it. In it's base form it is good too. I recommend starting by choosing a theme, and I highly recommend a dark theme - it's eas- ier on the eyes, it's easier to read, and the syntax highlighting shows up a bit better. (See: https://www.reddit.com/r/ProgrammerHumor/comments/ 920x95/boo/). I recommend starting here, and once you get comfortable add some packages. Starter packages I suggest for Atom are minimap, highlight-selected, and todo-show. These packages will hopefully be ready on the lab machines. Note that there are packages in Atom for practically every language too! To install packages check the settings page. For Python specifically: When you get comfortable programming, you may want an autocomplete or function lookup type tool. In Atom you can install autocomplete-python and Kite together to get suggestions based on yours and others' common functions. It is also able to remember your custom functions and inputs/outputs. Note that Kite is a subscription service but has a free version. Atom Themes - Set a theme for Atom if you want to change it up from 7 the default. Go to File →Settings →Themes. I'm a personal fan of the One Dark UI theme and the Atom Dark syntax theme. Do what you like, but remember darker is easier on the eyes (especially your "old" TA's eyeballs). Other Editors: Sublime Text is another very popular and customizable editor that is widely used by programmers. There are also other options - try Googling around for text editors for programmers or maybe even Python specifically. This is all your preference, coding should feel comfortable. 2.4 Optional: Linux Subsystem on Windows Another thing you can do that can be quite powerful for future use or gaining experience right now is to install the Linux subsystem on Windows. This lets you run a Linux terminal on your Windows machine without having to use dual booting or a virtual machine. This is a really cool feature as you can access all of your files through the Linux terminal and run them in that environment. For example in my workflow I use Atom to write code which is saved in my regular Documents folder. Then in the Linux terminal I just navigate to it and can run it from there. This is a good idea because it lets you gain experience with using Linux (a really really valuable skill), but also because it is so much easier to install various packages and features in Linux than on Windows. We'll see this more later, but for now if you want to try it, go for it.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us