|
| 1 | +# Ways of installing Python |
| 2 | + |
| 3 | +I find myself having to go over methods of installing Python over and over, so I'm going to document as many as I can in this notebook. Each installation method should be in a separate section so instructors can link to whichever one you are supposed to you. However, if you are on your own, I'll try to provide some guidance. |
| 4 | + |
| 5 | +## The hedges |
| 6 | + |
| 7 | +This is not going to attempt to be a corpus of every possible method, tool, or program, so there will be omissions some purposeful some becuase I don't know about it. I'm going to focus in the tools that I usually mention to my students first, and may add some in later. Reminder here that I teach beginners, so I'm sticking very general and not going into advanced tools that these systems might provide. |
| 8 | + |
| 9 | +Any commentary I provide is also biased toward the academic/research envirionment and not meant to speak toward full development shops. They have their own needs and can speak for themselves. |
| 10 | + |
| 11 | +## There is no right answer |
| 12 | + |
| 13 | +Unless you're being told to use something specific by an instructor or boss, then there is no one right answer for which tool to use. Try a bunch out and go with the one that you like the most. Also remember that it is normal for experienced users to have multiple tools that we utilize to match the task. Your multiple tools should fall along a use spectrum from experimental, to light weight, to heavy development. |
| 14 | + |
| 15 | +# Basic installation framework |
| 16 | + |
| 17 | +At a very high level, you're going to have to install two things to work with Python: Python itself and a tool for interacting with Python. There are some built in methods of interacting with Python, and they'll work in a pinch, but most people will choose to use additional tools as their primary form of writing in Python. |
| 18 | + |
| 19 | +## Step 1: Install Python itself |
| 20 | + |
| 21 | +I'm going to keep this simple: unless you're being told otherwise, just use Anaconda with the most recept version of Python (e.g. avoid the 2.x versions). |
| 22 | + |
| 23 | +1. Go here: https://www.continuum.io/downloads |
| 24 | +2. Download the visual installer for Python 3.6 (or above). |
| 25 | +3. Wait, because this is a giant download |
| 26 | +4. Install like a normal application thing. |
| 27 | +5. Restart your computer |
| 28 | +6. Test your install with Appendix 1. |
| 29 | +7. Once your installation is done and tested, install your IDEs of choice. |
| 30 | + |
| 31 | +Anaconda provides an installation of Python in your system, but you don't usually directly interact with Anaconda to write Python. You will use specific editor tools to write Python, and those tools are connected (in a variety of ways) to your installation of Python. Thus, those tools will launch Python and execute the code. So the installation of Anaconda is necessary, even if it doesn't look like you'll be using it. |
| 32 | + |
| 33 | +You'll start interacting with Anaconda more directly once you need to start doing more advanced envirionment managment, and is the subject for many tutorials and documentation that is not necesary to repeat here. |
| 34 | + |
| 35 | +## Step 2: Pick an IDE and install it |
| 36 | + |
| 37 | +Refer to the Grand Trio of Tools section to decide on which might work the best. |
| 38 | + |
| 39 | +# IDNGAF and don't want to read all this crap |
| 40 | + |
| 41 | +Don't worry, I feel you. |
| 42 | + |
| 43 | +1. Be sure to install anaconda (see Step 1 and Appendix 1 for testing). |
| 44 | +2. Just download PyCharm Education edition (see Appendix 2 for connecting it to anaconda). |
| 45 | +3. You might want to read my notes on Spyder and Jupyter Notebooks if you're in the data game. |
| 46 | +4. Happy coding 😎 |
| 47 | + |
| 48 | +# The Grand Trio of Tools |
| 49 | + |
| 50 | +This is at least how I like to think about it, and you're welcome to disagree. I usually recommend having three levels tools in mind for use: |
| 51 | + |
| 52 | +1. The "heavy" tool, an [IDE](https://en.wikipedia.org/wiki/Integrated_development_environment) that you like and can help you keep track of things in a large project. This may start as your sole tool as you're learning Python and can use the help of an IDE and then you start incorporating other tools as you get more advanced skills. |
| 53 | +2. The light weight tool, which is likely just an advanced plain text editor rather than a full IDE. This tool is good for short/simple programs, or for code you need to have running for days on end (e.g. web scraping or large processing tools). |
| 54 | +3. An interactive tool for experimentation, exploration, testing proof of concepts, etc. |
| 55 | + |
| 56 | +I encourage you to have a combination of 1 & 3 or 2 & 3 depending on your preferences. Some full IDEs also have interactive Python tools built in, so a single program might satisfy 1 & 3. I will provide recommendations for each category. |
| 57 | + |
| 58 | +For example, my personal trio is: |
| 59 | + |
| 60 | +1. I actually have two: |
| 61 | + * PyCharm education edition for large processing scripts and instruction |
| 62 | + * Jupyter Notebooks for data exploration/munging |
| 63 | +2. Sublime Text Editor |
| 64 | + * For large webscraping projects to run for ages or when I'm writing a one-off tool. |
| 65 | +3. IPython |
| 66 | + * Interactive console that I will use in conjunction with 1 or 2 to experiment or check how data types interact. |
| 67 | + |
| 68 | +## Heavy editors |
| 69 | + |
| 70 | +**Don't forget that you'll also want to install Python via anaconda before installing an IDE!** |
| 71 | + |
| 72 | +There are many full IDEs for Python, so if you care about a specific feature to be present in an IDE, I suggest you search for that feature among lists of IDEs. I aim to keep this list short becuase when you're a beginner long lists can be difficult to navigate. |
| 73 | + |
| 74 | +Summary: |
| 75 | + |
| 76 | +1. Are you doing scientific python? |
| 77 | + * Yes: Spyder or Jupyter Notebooks (try both see which works the best for your projects) |
| 78 | +2. Are you doing data anlysis/science and want the pandas things to be pretty? |
| 79 | + * Yes: Jupyter Notebooks |
| 80 | +3. Are you just getting started with programming? |
| 81 | + * Yes: likely PyCharm Edu or Wing 101 will suit you the best, presuming that you're using traditional educational materials. You might want to do Jupyter Notebooks if you're going down the data analysis track. |
| 82 | + |
| 83 | +### PyCharm |
| 84 | + |
| 85 | +Links: https://www.jetbrains.com/pycharm/ |
| 86 | + |
| 87 | +I usually have my students use PyCharm Education edition because it: |
| 88 | + |
| 89 | +* has a cleaner interface |
| 90 | +* less noisy with warning, style prompts, etc. |
| 91 | +* as a nice big green button for running scripts |
| 92 | +* still capable of connecting to anaconda environments |
| 93 | + |
| 94 | +* Pros |
| 95 | + * Several free versions |
| 96 | + * Can be connected to anaconda environments |
| 97 | + * Good hooks to version control |
| 98 | + * Has a built in IPython interactive console |
| 99 | + * Project oriented enforced file structure |
| 100 | + * has a lot of pro tools as you move up to more complex tasks |
| 101 | + * Looks the same for mac/windows (as an instructor, this pleases me) |
| 102 | + * Looks like a normal application that you double click to open |
| 103 | +* Cons |
| 104 | + * Sometimes too many style warnings, etc. |
| 105 | + * Complex setup windows |
| 106 | + * Project oriented enforced file structure (yup, repeating this as it might annoy some people, or be too much for quick/small scripts) |
| 107 | + |
| 108 | +### Spyder |
| 109 | + |
| 110 | +Links: http://pythonhosted.org/spyder/ |
| 111 | + |
| 112 | +This is not an evironment I've used much, but some people really like it. This is an IDE designed for scientific computing, and will feel very similar to RStudio or Matlab. |
| 113 | + |
| 114 | +* Pros |
| 115 | + * Free and comes as part of the anaconda installation |
| 116 | + * Variable view can be great for beginners |
| 117 | + * Has console and scripting view in a single display |
| 118 | + * Works very nicely with plots/data viz |
| 119 | + * Will feel very comfortable to an R or Matlab switcher |
| 120 | +* Cons |
| 121 | + * Can be resource intesnsive, so not great for smaller computers |
| 122 | + * Requires command line to launch, which not all users will have permissions to do |
| 123 | + * Interface might be cluttered to some newcomers |
| 124 | + * Not as many syntax error warnings as PyCharm |
| 125 | + |
| 126 | +### Jupyter Notebooks |
| 127 | + |
| 128 | +Some will argue that this isn't a 'real' IDE, and my response to that is "I don't care." I don't need to repeat any of the glory of Jupyter Notebooks for data analyis, and there are other great tutorials worth spending time with if you like this. |
| 129 | + |
| 130 | +* Pros: |
| 131 | + * Interactive exploration |
| 132 | + * Many tools automatically display nicer in the notebook envirionment |
| 133 | + * Heavily used and the standard tool in some scientific/data communities. |
| 134 | + * Easily sharable analytics |
| 135 | + * Inline data viz |
| 136 | + * Has nice presentation tools |
| 137 | + * You can store markdown content to capture narrative, documentation, etc. all in one document |
| 138 | +* Cons: |
| 139 | + * Best for solo work, shared editing not awesome yet |
| 140 | + * Not quite plain text (it's giant json), so you have to interact with it rendered in a web browser |
| 141 | + * there are ways to export it out to HTML for easy sharing, but that's static and not interactive |
| 142 | + * The cell interaction can be confusing to some beginners and allows for accidental non-linear traps if y ou aren't prepared |
| 143 | + |
| 144 | +### Others I haven't used |
| 145 | + |
| 146 | +Not to just dump a bunch of links in here, but that's exactly what I'm about to do. |
| 147 | + |
| 148 | +* Eclipse has Python plugins |
| 149 | +* Wingware (http://www.wingware.com/) |
| 150 | + * They also have Wing 101 for beginners, which is a minimal editor for beginners: http://www.wingware.com/downloads/wingide-101 |
| 151 | + |
| 152 | +## |
| 153 | + |
| 154 | + |
| 155 | +# Appendix 1: Testing your Python installation |
| 156 | + |
| 157 | +1. Be sure to have restarted your computer. |
| 158 | +2. Open your command line/prompt. |
| 159 | + * Windows users: open up your Command Prompt application (in your system search bar, type in 'cmd' and an application will open up. YouTube has videos explaining this more if you need it. |
| 160 | + * Mac users: open your Terminal application. Either search via spotlight for 'terminal' or open it from Applications -> Utilities -> Terminal. |
| 161 | +3. Within your command line application, type in ‘python’ (without quotes) and press return. * Windows users: you should not get an error that it doesn’t know what Python is. * Mac users: it should state it is Python 3.6 (or whatever anaconda said it was) and not Python 2.7 |
| 162 | + * Should have text roughly like the text below. |
| 163 | + * `Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) ` |
| 164 | + * `[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin` |
| 165 | + * `Type "help", "copyright", "credits" or "license" for more information.` |
| 166 | + * `>>> ` |
| 167 | + * (ed note: doing blockquote code in lists sucks in markdown) |
| 168 | +4. Presuming everything described here as worked, you can close the window. This was just a test. |
| 169 | + |
| 170 | +# Appendix 2: Hooking PyCharm to your anaconda environment |
| 171 | + |
| 172 | +These directions presume that you have successfully installed Anaconda (or some other Python envirionment) into your computer. Review Appendix 1 for directions. |
| 173 | + |
| 174 | +1. Download (Available here: https://www.jetbrains.com/pycharm-edu/download/) and or other PyCharm edition that you'd like. |
| 175 | +2. Open the application. |
| 176 | +3. Select "Create New Project" when prompted in the opening screen. |
| 177 | +4. On the next screen you're going to tell PyCharm where your anaconda installation is and more information about your project. |
| 178 | +5. In **Location**: this is where you're going to save your project files. You're going to be presented with a file path that ends with Untitled. You can click the *...* button next to it to navigate to another folder. Then change Untitled to something reasonable, but leave the rest of the path in place. |
| 179 | +6. Under that is **Interpreter**: Click the drop down and let it populate with things. It might take a few seconds to find your anaconda. You should select the path that has 'anaconda' in it. |
| 180 | + * Windows: you might only see one option, which will be the anaconda bath. |
| 181 | + * Mac: you will see paths that will say 2.6 or 2.7 and one will likely be selected by default. It'll have System/Library/Frameworks at the beginning of the path. You need to find the Anaconda path, which should be something like `~/anaconda/bin/python`. This is the one that you want (or the relevant anaconda envirionment that you created elsewhere). |
| 182 | +7. **Be sure that you are selecting a 3.x version of Python!** Yes, it matters. |
| 183 | +8. Once you have set the correct path and Python, click Create. |
| 184 | +9. Now you're in the project view for PyCharm. On the left is your project file directory, and you have a gray screen which is where your scripts will appear when you have some. |
| 185 | +10. Right click on the project folder name on the left (this will have the project name that you gave it in step 5). |
| 186 | +11. In the right click menu, select New -> Python file |
| 187 | +12. Give it a name like 'testing'. You don't need to provide a file extension. Click OK. |
| 188 | +13. You should now have a blank white text file screen where the gray screen was. |
| 189 | +14. If this is your first time through with PyCharm, it may need several minutes to index your Python folder. Eventually you should see a big green button near the top left of that script. |
| 190 | +15. In the first line of the script, write `print("hello world")`. |
| 191 | +16. Click that big green button! |
| 192 | +17. The bottom of the screen should change to have an output screen appear, and it should read "hello world" followed by some blank lines and "Process finished with exit code 0". This means that everything worked just fine and you're ready to go! |
| 193 | + |
| 194 | +Bonus: check that you have Python 3 hooked up |
| 195 | + |
| 196 | +1. Go into your Python project you just created, or really any PyCharm project. |
| 197 | +2. Make a new Python file. |
| 198 | +3. On the first line of the script file, write `print "hello"`. |
| 199 | +4. Click the big green button. |
| 200 | +5. You should get an error in the output area that says `SyntaxError: Missing parentheses in call to 'print'`. You're good to go if this happens! This should fail. |
| 201 | +6. If this actually printed `hello` to the output area, then you have Python 2.x hooked to this project. |
| 202 | +7. Go into the Preferences or Settings pane (depending on if you're windows or mac), and you should see the project name as one of the options in there. Click on that and redo the Interpreter settings found in the previous set of directions (starting at item 6). |
|
0 commit comments