Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Atom's script to run Python 3.x scripts? May the combination with Windows 7 Pro x64 be the issue?

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):

enter image description here

(it doesn't matter whether it is C:\Python34 or C:\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.

like image 917
Robert Seifert Avatar asked Aug 14 '15 09:08

Robert Seifert


3 Answers

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.

like image 65
Matt Nona Avatar answered Nov 03 '22 08:11

Matt Nona


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":

enter image description here

Then /packages/script/lib/grammars.coffee Find "Python" and make the appropriate change to python3:

enter image description here

like image 23
DC IT Avatar answered Nov 03 '22 08:11

DC IT


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.

like image 1
Rookie Avatar answered Nov 03 '22 08:11

Rookie