A quick tutorial on how to run either a Python 2.7 script or a Python 3.5 script using Sublime Text 3.

The contents of the sublime-build file are:

{
“cmd”: [“/usr/bin/python3”, “$file”],
“selector”: “source.python”,
“file_regex”: “file “(…*?)”, line([0-9]+)”
}

If you are using either Mac or Windows, instead of using the “whereis” command to find your installation path to Python, you can just run the following script, which will output the path to where Python is installed on your machine:

“`
import os
import sys
os.path.dirname(sys.executable)
“`

Website:

Nguồn: https://codeigniterbrasil.com

Xem thêm bài viết khác: https://codeigniterbrasil.com/lap-trinh-php/

43 Comments

John Keane

April 24, 2020

Excellent Video. Thank You.

Reply

Minecraft killer

April 24, 2020

import pygame

pygame.init()

width = 800

height = 600

screen = pygame.dislay.set_mode((width,height))

i am getting a error can you tell me why and your tutorials are super

Reply

M C

April 24, 2020

I checked the path by typing "whereis python" in Terminal and it returns "/usr/bin/python". Should i modify your code above and replace python3 with python?

Reply

alaindiouly

April 24, 2020

thank you so much for your clear and straight-to-the-point video

Reply

Munachi Marcel

April 24, 2020

I don't have a terminal in my system what's an alternative

Reply

Loop loop

April 24, 2020

how you run the script?

Reply

Vaibhav Pandey

April 24, 2020

thank you so much.It worked

Reply

Eshaan Devgan

April 24, 2020

For those people who were unable to locate path with whereis use which instead as which python3.

Reply

prospectnyc

April 24, 2020

Thank you!

Reply

Daven Thakkar

April 24, 2020

I keep getting a message saying permission denied in my terminal. How can I fix that

Reply

Kha Nguyễn

April 24, 2020

So, Can chance version 3.5 into version 3.7 ?

Reply

KINGTERRARIAGAMINGMARIO KTGM/

April 24, 2020

um i got this error as shown below:
C:UsersUserAppDataLocalProgramsPythonPython37python.exe: can't find '__main__' module in ''

this is the build content i think its correct:

{

"cmd": ["C:/Users/User/AppData/Local/Programs/Python/Python37/python.exe", "$file"],

"selector": "source.python",

"file_regex": "file "(…*?)", line([0-9]+)"

}

i moved my python app file to a text box to see the path and copied it to the path box, and the build file name is Python3.sublime-build

can it be fixed?

if you want to see the full box of the error content then read down below:
C:UsersUserAppDataLocalProgramsPythonPython37python.exe: can't find '__main__' module in ''

[Finished in 1.0s with exit code 1]

[cmd: ['C:/Users/User/AppData/Local/Programs/Python/Python37/python.exe', '']]

[dir: C:Program FilesSublime Text 3]

[path: C:ProgramDataOracleJavajavapath;C:Program Files (x86)InteliCLS Client;C:Program FilesInteliCLS Client;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesIntelIntel(R) Management Engine ComponentsDAL;C:Program FilesIntelIntel(R) Management Engine ComponentsIPT;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsDAL;C:Program Files (x86)IntelIntel(R) Management Engine ComponentsIPT;C:UsersUserAppDataLocalSmartbarApplication;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:UsersUserAppDataLocalMicrosoftWindowsApps;]

Reply

AndR3 Av3l4s

April 24, 2020

Your are amazing thnkx so much✴

Reply

Reza Zandi

April 24, 2020

I was about to just give up on being a software developer… until I finally got it lol. I'm on a Mac, so I was having trouble just like everyone else. Here's what worked finally,

{
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.7/bin/python3", "$file"],
"selector": "source.python",
"file_regex": "file "(…*?)", line([0-9]+)"
}

Make sure to keep that "$file" in there, and just add the "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3" part to it WITH a comma as show above. Also, you can use type -a python3 in terminal to find out where your python3 is located. Your welcome!

Reply

huy hung ta

April 24, 2020

tks

Reply

Erick

April 24, 2020

Thanks!

Reply

mohammed zakeer

April 24, 2020

where u copy this code in untitle file

Reply

Alexandre Vieira

April 24, 2020

Thank you, it worked perfectly.

Reply

Almirr Shakiil

April 24, 2020

doesn't work

Reply

Mario Pellegrino

April 24, 2020

the "whereis" command is not found on my command prompt

Reply

Michael B B

April 24, 2020

Lets say you want to edit the build file system / menu how would you go about doing that?

Reply

LmaonadeJuice

April 24, 2020

just saying if it doesnt work add an indent to the text inside the {}

Reply

Diego Chavarro

April 24, 2020

Thanks

Reply

Ghada JW

April 24, 2020

you are the best thank you so much <3

Reply

Gibson Farabow

April 24, 2020

If you are on mac and do

os.path.dirname(sys.executable)
you may need to add python3 to the end of it after bin/ (I did).

Reply

Steve Garip

April 24, 2020

thanks 👍🏽👍🏽

Reply

Victor Vrabii

April 24, 2020

Thank you! you save my time)

Reply

Patricio Contreras

April 24, 2020

Muchas gracias, funciona perfecto.

Reply

Erick

April 24, 2020

Thank you!

Reply

dhf336

April 24, 2020

Just the video I was looking for ! Thank you .

Reply

julio rr

April 24, 2020

/usr/bin/python3.6: can't find '__main__' module in ''

# i have the last version, but after of save and load… error…
(ubuntu 18.04)

Reply

Christian picón calderon

April 24, 2020

In the new versions of mac OS, the command whereis sometimes doesn't work, instead, you could try the command -which python3-. Hopefully it can helps you.

Reply

Martín Fernández

April 24, 2020

hi first sorry, please mi poor english, iam learning python in youtube in linux mint with sublime tex now i know how to use python3 but how i do tools sublimeREPL run current file in python 3??

Reply

Wavvy

April 24, 2020

it says python is not recognized as an internal command, operable program or batch file plllsss help!

Reply

Tiffany Sung

April 24, 2020

Thank you so much for this tutorial. I've been struggling with this for a long time.

Reply

Edward Dalcoy

April 24, 2020

you are a life saver! thank you very much.

Reply

Johny Walker

April 24, 2020

Hey man, nice video but I have a question.
My "untitled.sublime-build" is contain only following line:

{
"shell_cmd" : "make"
}

I am running sublime on Ubuntu 18.04 LTS

Reply

vinodh venugopalan

April 24, 2020

Not able to get sublime to run python 3 code on windows 10. Environment variables are set, but no luck. Welcome your suggestion to fix this.

Reply

Avijeet Karmaker

April 24, 2020

I am facing input output problem… i can not get output if i use import sys and want to print any variable using this value
code:
import sys
n = int(input("enter a number : "))

print("the number is : " + n)

output:
enter a number :

but when i enter a number , I dont get the printed line "the number is <any number>"

Reply

Iñaki M Longa

April 24, 2020

I'm having the same problem as some of the other people. "whereis" won't return anything. I'm using a MacBook Pro.

I tried running the script below on Sublime, but I'm not getting anything either. Help!

import os
import sys
os.path.dirname(sys.executable)

Reply

Caden Davidson

April 24, 2020

Hello, I believe I've correctly followed all the steps in this video, but when I run my Python 3 script using the Python3 build, I get this message down in the console:

[Errno 13] Permission denied
[cmd: ['/Library/Frameworks/Python.framework/Versions/3.6/bin', '/Users/hp2/Desktop/pythonstuff/test.py']]
[dir: /Users/hp2/Desktop/pythonstuff]
[path: /Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/share/dotnet:/Library/Frameworks/Mono.framework/Versions/Current/Commands]
[Finished]

I am using macOS 10.13.2 (High Sierra) and Sublime Text 3. I used the directory '/Library/Frameworks/Python.framework/Versions/3.6/bin' for the Python3 build, which is the directory I got when I ran the os.path.dirname(sys.executable) line. Any insights?

I believe the problem has something to do with the permissions in one or more of my directories, but I have no idea what the specific problem is or how to fix it.

EDIT: Now this appears to be a pointless comment, as I have found the solution here:
https://stackoverflow.com/questions/39187323/im-getting-errno-13-permission-denied-when-trying-to-use-python
I simply changed the directory for the Python3 build to '/usr/local/bin/python3.6'
I will leave this comment up in case anybody else comes across the same problem.

Reply

Vincenz Buhler

April 24, 2020

when I run the whereis command, nothing happens. I used the exit command and even closed out the terminal entirely. Not able to locate where Python 3 downloaded on my computer.

Reply

Freya van Odin

April 24, 2020

thanks for copying the message in the comments because I do not get that message and would would have had to write it my self, because mine says:
'python' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 0.1s]

Reply

Leave a Reply