Sublime Forum

Sublime Text 4 will not run my python code on macos

#1

Let me first say… a few years back i used Sublime Text for basic Python coding and I LOVED IT!
now im trying to recreate that fire but having problems getting off the ground :worried:

I have installed sublime text 4 on MacOS 12.6. However I am not able to get it to run a simple python.py program using the “tools > build command”. that is to say, I see no response in the lower window pane.

I have done a lot of research online and think my problem may have to do with Python3.sublime-build file I created based on online resources I found. I have it defined as follows

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

In it, Im providing the direct path to my python3 executable

where am I going wrong?

0 Likes

#2

Does your python script require input? If so the built-in build system can’t do that.

0 Likes

#3

no . im starting with the simplest of things
print(‘hello’)

does my sublime-build file look correct?
I hardcoded the path to python3 in it

also, im not clear if sublime text is reading that file… i have put it in the
~/library/application support/sublime text/packages/user folder
is that the correct place for it?

or is is supposed to go in the preferences.sublime-settings file ?

i have tried both locations by the way

0 Likes

#4

Have you tried running that command on the command line? Have you selected the build system you’ve created (cmd+shift+b)?

0 Likes

#5

when you say run the command on the command line. can you please be more specific?

yes i can run
print(‘hello’) in IDLE ( the build in ide that is part of my python3 install) and it outputs “hello”

im not sure what command line you are talking about?

inside the ST app, i select tools > build system > python3
then tools > build
nothing happens

I also tried tools > build with > python3 (thats the cmd+shift+b i thnk you are reffering to )
nothing happens

does my script look correct? am i putting that script in the correct folder?

0 Likes

#6

What do you mean by “nothing happens”? Does the build panel not open? Does it open but only say that it is finished without producing any output? Does the status bar say something like “No build system” for a second after you run it?

Have you tried it with the build system for Python that comes with Sublime by default? For some reason people on the internet seem to think you need some extra magic setup for Python, but in 99.999% of cases the build system that ships with ST4 works just fine out of the box and trying to make your own is just borrowing problems.

0 Likes

#7

hi Terrance. I appreciate your help

I think i did clarify that ‘nothing happens’ means when i ran the ‘build’ command, there is no output in the lower pane of the window… i was expecting to see the my 1 line print(‘hello’) script execute and have ‘hello’ show up in that lower pane.

I do see an informational message in the status bar (bottom border of the window) show
"Line 1, Column 15 ; Building tab size 4: Python"

and then after a few seconds the word building disappears

I did also follow your advice and try using build system > python (rather than python3) and i see the same effect

as mentioned my python3 script runs fine with Idle and in macos terminal window

i have tried so many different changes to the Python3.sublime-build file … im completely out of ideas.

0 Likes

#8

Do you see any errors in the console (View > Show Console)?

0 Likes

#9

@bschaaf you sir are a genius. yes… here is the error message in the console (which I know know is a thing :grinning:)

here is the output of the console window (im trying to figure it out but it’s above my pay grade at this point)…

Running /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 -u /Users/mikesmbp/Library/CloudStorage/OneDrive-Personal/Reggies Docs on OneDrive/Reggies Python/sublime text/print.py
Traceback (most recent call last):

  • File “/private/var/folders/nz/7bc4xwxj41x2_qhr4705w5x40000gn/T/AppTranslocation/BA3C5193-FBA9-494F-9B95-A1FB4EC2E6EA/d/Sublime Text.app/Contents/MacOS/Lib/python38/sublime_plugin.py”, line 1657, in run_*
  • return self.run(*args)
  • File “/private/var/folders/nz/7bc4xwxj41x2_qhr4705w5x40000gn/T/AppTranslocation/BA3C5193-FBA9-494F-9B95-A1FB4EC2E6EA/d/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package/exec.py”, line 252, in run*
    PermissionError: [Errno 1] Operation not permitted
0 Likes

#10

Could be an app-translocation thing. If Sublime Text.app is not in your Applications folders I suggest moving it there using Finder. If it is you can move it somewhere else and then move it back.

Could also be a macOS permissions issue. Under System Preferences > Security & Privacy > Privacy > Full Disk Access you can try adding Sublime Text.

1 Like

#11

thanks for your latest suggestion. it turns out that when i installed sublime text, the executable for some reason stayed in my download folder. i have moved it to the applications folder as you suggest. but that didnt work

i then granted the app full disk access and that does work! thanks!!!

however this raises the question. why the heck was this so complicated. none of this is suggested anywhere online that i saw. also there is almost no apps that get full disk access on my rig (just smbd). am i opening up a security hole by granting this to Sublime Text?

0 Likes

#12

MacOS is supposed to prompt for application access to folders. It’s possible that got denied at some point and afaik after doing so you have to manually grant permissions. In my experience there’s plenty of weirdness around permissions on macOS.

It’s likely unrelated to app-translocation, but that has caused other issues in the past.

however this raises the question. why the heck was this so complicated.

Apple.

0 Likes

#13

lol. thanks… but it does feel like a dangerous work around to be giving this application full disk access when no other programs have it. i could understand it needing limited disk access

0 Likes

#14

You may have some luck with permissions under Files and Folders if you don’t want ST to have full disk access.

Note full disk access doesn’t give ST access to write to other users, system files or anything like that. MacOS permissions sit on top of unix ones to further restrict access.

1 Like

#15

thats good to know… but nonetheless there were no other 3rd party apps that had full disk access when i went to add it for sublimetext… i may play around with files and folders permissions, i have never used that part of preferences. Thanks

0 Likes