Setting Up Siblime Text 3 For Python Mac

Setting Up Siblime Text 3 For Python Mac

Document your code

Every project on GitHub comes with a version-controlled wiki to give your documentation the high level of care it deserves. It’s easy to create well-maintained, Markdown or rich text documentation alongside your code.

Sign up for free See pricing for teams and enterprises

This is my Sublime Text 3 setup, with ambitions to create a custom Python IDE. All of the below assumes you’ve already installed Package Control, the package manager for Sublime Text. General packages. Update Sublime Text 3 to Python 3 on Mac. This blog will explain how to update Sublime Text 3 to build with Python 3 on a mac. Step 1: Make sure your computer has Python 3 installed on it.

Configure your Mac so that when you double-click a .py file, it opens Sublime.

Configure Python2 and Python3 Build Systems

Configure Sublime so that you can switch between Python2 and Python3 for builds. When you set this, you can press command-B (on a Mac) in the editor and it will run your program. (Instructions inspired by this page, which has great screen shots.)

  1. First, make sure Sublime is running the correct Python2 by default.1. In the Sublime Text 2 app, go to Preferences > Browse Packages > Python.2. Edit the Python.sublime-build file.3. Comment out this line: //'cmd': ['/usr/local/bin/python', '-u', '$file'], (Add the //.)4. Add this line: 'cmd': ['/usr/bin/env', 'python', '-u', '$file'], (Don't forget the comma.)5. Save the file, open a simple Python2 program, and see if command-B works.
  2. Now, copy the contents of the preference file you used in the prior step.1. In the Sublime Text 2 app, go to Tools > Build System > New Build System...2. Paste into the blank file.3. Change the line to be 'cmd': ['/usr/bin/env', 'python3', '-u', '$file'],4. Save as Python3.5. If you ever need to edit this file again, you'll find it in ~/Library/Application Support/Sublime Text 2/Packages/User.
  3. When you are working in Python, in the Sublime app look under Tools > Build System and you should be able to selected between Python and Python3.

Other settings

Setting up Sublime Text for Python. I haven't done all of these, but installing the lint tool was helpful.

Clone this wiki locally
Active1 year, 6 months ago

I followed these steps to run Python 3 on Sublime Text 3.

Select the menu Tools > Build > New Build System and I entered the following:

After that, I saved it to the following (Mac-specific) directory: ~/Library/Application Support/Sublime Text 3/Packages/User

but I'm getting this error when I'm trying to run my code on Python 3 in Sublime:

baduker
1,2485 gold badges12 silver badges23 bronze badges
user3555502user3555502

3 Answers

Sublime Text 3 Download Mac

You need to provide the full path to python3, since Sublime Text does not read your ~/.bash_profile file. Open up Terminal, type which python3, and use that full path:

duan
4,9783 gold badges26 silver badges51 bronze badges
AndrewAndrew
14.3k10 gold badges54 silver badges82 bronze badges

This is the snippet that I've been using. It's a slight variation to Andrew's solution, such that python3 is dynamically located by consulting the UNIX environment's PATH setting (not unlike how you would do the same inside a Python shell script; e.g.: '#! /usr/bin/env python3').

This snippet also uses 'shell_cmd' instead of 'cmd', which sublime-text-3 has seemingly switched to.

I saved mine in '.../Packages/User/Python3.sublime-build'. I hope this helps you. =:)

NYCeyesNYCeyes

Siblime Text 3

1,9013 gold badges25 silver badges38 bronze badges

Barkada Text 3

Thanks for your question. I began to learn python a couple days ago, and I am stuck with the same problem that you have met.Just as Andrew said above,it is “path problem”. I would like to share the code that I used to get python3 on sublime3. For MacOS user:

and save the file as Python3.sublime-build.I deeply recommended the book 'A byte of python ' for the new beginner of python.This book contributes a lot to my answer for this question.

David_LDavid_L

Setting Up Siblime Text 3 For Python Machine

Not the answer you're looking for? Browse other questions tagged python-3.xsublimetext3 or ask your own question.