Beginning a new programming language can be a challenge. This tutorial will go through how to set up python on a Mac ( Windows users can go here). There are many schools of thought on the ‘best’ development environments, IDE’s, etc to work with. The goal of this article is to help you get up and running on a Mac writing Python using the Sublime Text IDE. Sublime Text is a simple IDE/text editor that can be used with a number of languages, including Python.
1. Download & Install Sublime Text
Visit http://www.sublimetext.com/2, and press the OS X button. When the download is complete, open the downloaded dmg file, and move the program to your applications folder.
I am trying to go through Python Crash Course I go to tools, new build system, and then after typing in the code for Python3, I try to save the file Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts. Sublime Text will put it in the right path by default. Once you click save, close the file so that you’re back on your scratch.py file. Now go to Tools - Build System, and select Python3 (or whatever you named your Build System). If you don’t see your new build system, you may have to quit Sublime Text and reopen it.
2. Setup Local Environment
Once you have installed Sublime Text, you can open it from your Applications folder, and add it to your dock. As you learn more about Python and programming in general, you will need to become familiar with the command line. There are some tools packaged with Sublime Text that can make your life a lot easier. One of these is the ability to open files and Sublime itself from the command line. To start, search Spotlight in the upper right-hand corner of your Mac for a program called ‘Terminal’. This program is an extremely useful tool for a variety of things, including running Python programs.
From Terminal, we will set up a folder using the command ‘mkdir’. This command produces the same result as the ‘New Folder’ option you might be familiar with from Finder. Type ‘mkdir bin’ from Terminal. If you type ‘ls’ (show folders and files), you should see ‘bin’ listed. The full path of this is ~/bin, which we will use in a moment.
To use the bin folder in Terminal in the future, we will need to be able to access it in our Terminal’s profile. The profile is essentially a list of places that terminal can look for running programs and using core system tools. To add to your path, type:
This should open a file that contains commands that show where to look. Press the down arrow to the bottom of the file. Type ‘i’. You should now be able to insert text into the file. Type the following below the last line:
Download Aio Runtimes V2.1.6.Exe uploaded at SaveShared.com™, file hash 2ece31bef7eadc8a48af68098e7d9b19, file size 358.99 MB and last modified on 2014-09-03 17:28:09. Aio runtimes_v2 1.6. File Name: Aio Runtimes V2.1.6 Winxp.Zip: Upload Date: 2020-08-03 14:37:33: Mime Type: Application/zip: Virus Scan Result: Clean: Size: 216.49 MB: Total Downloads.
This tells Terminal to look for the bin folder you created within its profile. To save the file, press escape, type ‘:wq’, then press enter. The file has been saved, but to use the new profile, we also need to tell terminal to use the latest version. To do this, type:
3. Allow Terminal to use the Sublime command line tools directly
To setup the command line tools offered with Sublime Text, we will be creating a ‘symbolic link’ using Terminal. The command for this is ln -s . We will be using the Sublime Text app as the first file, and creating a link to that in the ‘bin’ folder we just created. This symbolic link will allow us to access Sublime using the command ‘subl’ from the command line. To do this, type the following in Terminal:
4. First Python Program
First, save the file you have opened in step 3 in Sublime as ‘hello.py’ (using either File -> Save, or the command -> s keyboard shortcut). You will now see syntax highlighting when you start typing. Type the following:
Save the file again. Now we’re ready to run the program. To do so, go back to Terminal, and type:
6. Be clear about the Python you are using
Because Python is installed by default on Macs, this runs automatically, and you should see “Hello, world” in your Terminal. We are not done here, though. It’s important to understand that not all operating systems have the same Python environment. We also might want to install a later version of Python in the future. This makes it important to tell this program to run from the exact version of Python that we want it to run on so we don’t unexpectedly run it from another version of Python. To find out where Python is on your system, type in ‘which python’ into your Terminal. This will display the exact location of Python that is on your system. Copy the output, and come back to your hello.py file. At the top of the file, type:
Now paste the Terminal output. If there is a ‘/python’ at the end of the line, remove this, and replace it with a ‘ python’. The line should now say something like:
or
This tutorial outlined how to set up a Python IDE on a Mac, and how to set up a Python file to run from the exact version of Python you want it to, every time. Python is a great language with many features, and you’ve learned a few wayss to get up and running using Python on a Mac.
Sublime Text is a commonly-used text editorused to write Python code. Sublime Text's slick user interface along with itsnumerous extensions for syntax highlighting, source file finding and analyzingcode metrics make the editor more accessible to newprogrammers than some other applications like Vim andEmacs.
What makes Sublime Text awesome?
Sublime Text is often the first editor that newer programmers pick up becauseit works on all operating systems and it is far more approachable thanEmacs, Vim or even PyCharm.
It is easy to get started in Sublime because the menus and options areaccessible by using a mouse. There are no different modes to learn likeVim's normal and insert modes. The keyboard shortcuts can be learned overtime rather than all at once in the case of Vim or Emacs.
Sublime Text works well for beginners as soon as they install it and thencan be extended with many of the features provided by an IDE likePyCharm as a developer's skill level ramps up.
An additional bonus of using Sublime Text as a Python developer is thatplugins are written in Python.Python developers can extend Sublime Text with their own programming languagerather than learn a new language like Emacs' Elisp or Vim's Vimscript.
Why use any other editor if Sublime is so great?
Picking a text editor or IDE to use tends tobe a weirdly personal decision for each developer. Yet it makes sense whenyou realize that you are going to spend hours upon hours every day in yourchosen environment so why not make sure it is one that is enjoyable andhighly productive?
For some folks they prefer Vim's keyboard-driven style,PyCharm's Swiss Army Knife set of Python tools or one ofthe many other editors with its own strengths and weaknesses.
The only 'best' editor choice is to pick one that works really well for youand stick to it. Master your tool so it gets out of your way and enablesas much time inprogramming flow aspossible.
Python-specific Sublime Text resources
There are many Python-specific Sublime Text tutorials and resources becausethe editor is so frequently used to create Python applications. The followinglinks should get your editor customized with linters,code metrics, syntax checking and many otherintegrated development environment features.
Setting Up Sublime Text 3 for Full Stack Python Developmentis a spectacular tutorial that covers installing Sublime Text andconfiguring a multitude of helpful Python programming plugins.
Sublime Text 3 Heavenis a quick overview of the extensions, packages and bonus toys thatone developer uses for his own Sublime Text development setup.
Sublime Tutor is an interactive in-editorkeyboard shortcuts tutorial that plugs into Sublime so you can learn andbecome more productive as you use the editor.
Using Generators for Fun and Profit - Utility for developersis not about setting up your Sublime Text environment but instead how tocreate your own plugins using Python. The tutorial is written by theauthor of a Sublime Text plugin who uses generatorsto implement features with Sublime's API.
Turning Sublime Text Into a Lightweight Python IDEshows the basic settings and configuration specific to using Sublime withPython as more than just a text editor.
Setting up Sublime Text 3 for Python Type Checkingshows one way of setting up support for Python 3.6 static type checking inSublime.
Three steps to lint Python 3.6 in Sublime Textwalks through setting up Flake8 toenforce code style guidelines and show you the errors and warnings inSublime as you are working.
Text editing techniques every front-end developer should knowgives examples in Sublime Text of time-saving text manipulation you maynot have known existed such as line bubbling, ragged line selection,AceJump and transpose. While the techniques can be used in most editorsthe provided video clips show how to perform each of these shortcuts inSublime.
General Sublime Text resources
Sublime Text can be used for much more than Python development and there aremany useful tutorials that are not targeted at a specific programming languagewhich are still useful.
Sublime Python Package
Super charge your Sublime Text 3 to increase your productivityprovides many shortcuts and tricks for using the editor.
Disassembling Sublime Text uses a binary disassembler to dive into the reverse engineeredsource code of Sublime Text because it is not open source software. All in 1 hdd docking model 875.
Sync your sublime text 3 configurations safely and easyexplains how to mitigate configuration conflicts that can arise when tryingto use copied files from one computer to another.
7 shortcuts of a highly effective Sublime Text usershows keyboard shortcuts for opening any file, going to any specificblock of text, handling multiple cursors and more.
Sublime Plugin resources
Sublime Text plugins are written in Python which makes it convenient forour ecosystem to customize the editor. The following resources provideinformation on writing your own plugins as well as great community pluginsyou will want to take a look at adding to your installation.
Sublime's documentation coversplugin basics, theAPI for plugins andgives a'Hello, world!'-level examplethat you can extend.
Sublime Text plugin development basicshas some good advice and further resources.
The 25 Best Sublime Text Plugins for Front End Developersis not specific to Python development but there is a bunch of overlapbetween plugins useful for general front-end development and any Pythonweb development project.
5 Awesome Sublime Plugins you Won’t Find in Top Plugin Postscovers some lesser-known plugins and how you can find your own viaPackage Control's trending plugins section.
What do you want to code using Sublime Text?
I want to learn how to code a Python web application using a framework.
Sublime Python Cannot Input
I've built a Python web app, now how do I deploy it?