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

*爱你&永不变心* 提交于 2019-11-27 13:44:08

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.

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:

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.

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.

same problem just like you. 'Packages -> Script -> Configure Script' is not permanent. So I has tryed another script runner:https://atom.io/packages/atom-runner, just found the problem is in the python script itself.

When I use atom-runner, I got error message like this: atom-runner error

So it remind me that in the beginning of the python script: ' #!/usr/bin/env python3 '

It's obvious that the ENV_PATH is WRONG here. I should revise it in my python script.

Setting the PATH within Atom did not work, setting it with the cmd, via

set PATH=%PATH%;C:\Python34

neither, and setting it in the Windows 7 system properties failed as well.


However reinstalling Python 3.4 and check Add python.exe to Path

seems to be neccesary. Also I needed to uninstall Atom completely (inculding all packages or a least script) and reinstall it from scratch.

After all these steps:

  • Install Python with Add to Path
  • Install Atom
  • Install script package

it works out of the box (Ctrl+Shift+B) and no further steps are required.


I still don't know what was the reason before and I don't know which of this steps are really required. So feel free to include your procedure without reinstalling everything.


Update

Reinstalling everything is certainly not necessary, simply updating/repairing the installation with the installer is sufficient.

Use the script-runner https://atom.io/packages/script-runner/

"N.B. these keyboard shortcuts are currently being reviewed, input is welcome. Command Mac OS X Linux/Windows Run: Script ctrl-x alt-x Run: Terminate ctrl-c alt-c" And "Run Terminate" (Alt + c) to use the current python in your system.

CreativeX

For Linux and Mac, adding environment in the script will pick correct python version. (command + I to run)

for running with python3

#!/usr/bin/env python3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!