How to setup Atom's script to run Python 3.x scripts? May the combination with Windows 7 Pro x64 be the issue?
Solution 1
This can be easily solved by editing the /home/.atom/packages/script/lib/grammars.coffee
file (note that the atom folder is hidden so you might have to press ctrl+H to view hidden files and folders)
Inside grammars.coffee
find:
Python:
"Selection Based":
command: "python"
args: (context) -> ['-u', '-c', context.getCode()]
"File Based":
command: "python"
args: (context) -> ['-u', context.filepath]
and replace with:
Python:
"Selection Based":
command: "python3"
args: (context) -> ['-u', '-c', context.getCode()]
"File Based":
command: "python3"
args: (context) -> ['-u', context.filepath]
Save changes, restart Atom and enjoy running your scripts with python 3
EDIT: On Windows I believe the grammars.coffee
file is located in
C:/Users/Your_Username/AppData/Local/atom/packages
Again, the AppData
folder is hidden so you might have to change your settings to view hidden files and folders.
Solution 2
To expand on @matt-nona answer. You can go to his mentioned config file right from Atom. Simply go to settings then "Open Config Folder":
Then /packages/script/lib/grammars.coffee Find "Python" and make the appropriate change to python3:
Solution 3
Update: for any other souls looking for this answer - On my Mac I do not have a grammars.coffee file within atom script config file.
Instead, there s a grammars folder, and I have a python.coffee file in there. The same changes outlines in the screenshot (ie add '3' to the end of the two mentions of python) fixed my issue and atom automatically runs Python3 now.
Not sure if the above answers are Windows specific or if there have been dev changes since 2017.
Solution 4
Following up on Matt Nona's advice , when Atom starts-> Welcome Guide (or control+shift+T)-> 5th one down 'Hack on the Init Script'. A blank page will open and you can add that modifications in there.
Related videos on Youtube
Robert Seifert
Electrical engineer with focus on magnetic bearings, linear and highspeed drives, magnetic field theory and fractional-order control systems. Fluent in Matlab, experienced in Python and C. LinkedIn | ResearchGate | Google Scholar | Xing | Twitter I was able to help you out? Feel free to buy me a coffee to keep me running.
Updated on July 05, 2022Comments
-
Robert Seifert almost 2 years
I'm trying to switch from Notepad++ to Atom, but I just can't manage to get my scripts executed in Atom.
I followed this answer (so I already installed script) which is not really extensive and also the rest on the web doesn't offer anything comprehensible for beginners.
In Notepad++ NPPexec I used to
NPP_SAVE cd "$(FULL_CURRENT_PATH)" C:\Python34\python.exe -u "$(FULL_CURRENT_PATH)"
and in Sublime Text 2 I made it run by creating a new "Build System":
{ "cmd": ["C:\\python34\\python.exe", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python" }
Can you please guide me how to setup Atom to be able to execute Python scripts with Python 3.4 scripts with a keyboard short-cut?
I already tried to set my init-script to:
process.env.path = ["C:\Python34\python.exe",process.env.PATH].join(";")
respectively
process.env.path = ["C:\Python34",process.env.PATH].join(";")
with no success.
When I go to Packages -> Script -> Configure Script and type
C:\\Python34\\python.exe
it works. But thats not a permanent solution.
When I press Ctrl+Shift+B to run a script, without configuring it before (as it is supposed to work), I get (suggestion of ig0774's comment implemented):
(it doesn't matter whether it is
C:\Python34
orC:\Python34\
)It complains that python is not in my path - but it is.
I read multiple times that Windows 7/8 64bit together with Python 3.x could cause issues with certain packages. May this be the reason in ths case as well? I have Windows 7 Pro x64.
Update
As I've switched to VSCode and probably stay there, I'm not willing/don't have the time to try out all the answers, so I let the community judge the answers and accept always the highest voted. Please ping me, if it's not correct anymore.
-
Brad Dausses almost 7 yearsThanks for this... By far the easiest solution for defaulting to Python 3 on OSX using the script package.
-
Arjee over 6 yearsBy far the best answer. requires more upvotes. I am searching fo a solution for last 2 hours (whew) thanks to @Daniel Chamorro as well.
-
wp78de over 6 yearsIn script version 3.17.3 there is an update of the file's location. Replace
grammars.coffee
withpython.coffee
. -
3pitt almost 6 yearswhy isn't a shebang
#!/usr/bin/env python3
sufficient for atom? -
Omar almost 6 yearsWorks like a charm - thanks for the screenshots, very helpful.
-
JBallin over 5 yearsI use this method as well but I believe we'll need to redo it when
script
updates, which is pretty infrequent anyway. Just something to watch out for.