{"id":1250,"date":"2015-07-31T08:00:47","date_gmt":"2015-07-31T12:00:47","guid":{"rendered":"http:\/\/novicenolonger.com\/?p=1250"},"modified":"2015-07-31T09:40:47","modified_gmt":"2015-07-31T13:40:47","slug":"safe-python-playing-with-virtualenv","status":"publish","type":"post","link":"https:\/\/novicenolonger.com\/safe-python-playing-with-virtualenv\/","title":{"rendered":"Safe Python playing with Virtualenv"},"content":{"rendered":"
Python<\/a> is a pretty great programming language. It’s fast to write, easy to read, and extremely flexible. It’s a good language to have in your arsenal for when you quickly need to write a web scraper to quick app prototype (although Go Lang<\/a> is also quite popular for the latter task as well).<\/p>\n You’re going<\/em> to make mistakes when you first start with Python, and you’re going to want to try the latest and greatest tools (like IPython<\/a>). Unfortunately, this kind of playing\/learning\u00a0can<\/em> have a negative impact on your computer, so it’s important to set up a safe environment in which to play. That’s what we’re going to be doing today, by setting up secure environments using virtualenv<\/a>.<\/p>\n <\/p>\n If you’re running a modern operating system (such as OS X, which is what I’m using to write this article), there’s a good chance you already have Python installed. To check, open up the Terminal app and type:<\/p>\n then click Enter.<\/p>\n (The $ symbol denotes that this is a command line input, and should not be typed into the Terminal. Type everything after the $.)<\/em><\/p>\n This will launch your default Python environment, and should show you exactly what version of Python you’re running. The output should look something like this:<\/p>\n As you can see, I’m running Python version 2.7.6. Also note that after running the python command, you’ll see >>> at the beginning of your prompt, not a $. This means you’re currently inside<\/em>\u00a0Python. You can press Ctrl-Z to exit back to the regular command prompt. Let’s do that now.<\/p>\n If you don’t see Python…that’s weird. You’ll have to install it from their website<\/a>.<\/p>\n Maybe version 2.7.6 is exactly what you want, or maybe you want to start exploring Python 3.x. Maybe you’ve heard a lot of about IPython<\/a>, which brings a ton of cool tools, such as text coloring, directly to your terminal. If you were to simply follow the instructions to install these new versions or tools, you’d be installing them for the default account \u2014 potentially losing old versions of software or messing things up for your entire computer if something happens to be buggy.<\/p>\n That’s why we’re going to play it safe with virtual environment wrappers!<\/p>\n The first tool we need to install is pip<\/a>, a package management system for Python. This will allow us to install a variety of tools (including virtualenv) directly in the terminal. This, and virtualenv, are the only<\/strong> tools that we’ll be installing for the default user.<\/p>\n To install pip, visit the official pip installation page<\/a> and right-click then\u00a0select Save Link As to download the installation script.<\/p>\nInstalling Python<\/h1>\n
$ python<\/pre>\n
Python 2.7.6 (default, Sep\u00a0 <\/span>9 2014, 15:04:36) \r\n<\/span>[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin\r\n<\/span>Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n<\/span>>>><\/span><\/pre>\n
Installing pip, then virtualenv<\/h1>\n