How to configure Atom to run Python3 scripts?

97,459

Solution 1

Go to the Atom's menu bar -> Packages -> Script -> Configure Script (Or, you can use the shortcut Shift+Ctrl+Alt+O)

Then type python3 to the Command space. Hopefully, it will work.

Solution 2

i am using "script" package (3.18.1 by rgbkrk) to run code inside atom and this is how i fixed it

  1. open package settings -> view code
  2. open lib -> grammars -> python.coffee
  3. change from python to python3 in those two places 'Selection Based' and 'File Based'

Solution 3

Install atom-runner in your Atom going into your settings of Atom and then inside Package and search for atom-runner and install it. enter image description here

Now click on settings tab for atom-runner as shown above on picture. Then click on View Code as shown in below picture. enter image description here

Then go to lib folder and open atom-runner.coffee and replace the following section of code:

defaultScopeMap:
coffee: 'coffee'
js: 'node'
ruby: 'ruby'
python: 'python3'
go: 'go run'
shell: 'bash'
powershell: 'powershell -noninteractive -noprofile -c -'

Make sure that for python keyword value is python3, by default it is python. Refer to the pic below: enter image description here

Other way is to find the location of python3 using command

which python3

for me output is :

/usr/local/bin/python3

and add as a shebang in your every python file. For example:-

#!/usr/local/bin/python3
import sys
print("Version ",sys.version)

Only catch is that you have to write this in each file.

Solution 4

If you are using Mac OS X, use the directory on the terminal to open the file.

Select the file python3, right click and select "get info". Select the directory from "Where:" and past it in Atom.

As Terry told you:

Then type python3 to the Command space.

Solution 5

You can use the Atom package atom-python-run to launch python code from Atom, the python version can be configured in the package settings. By default atom-python-run uses the syntax python {file}. If the python command on your system is not yet pointing to python3, just replace the setting and write python3 {file}.

Share:
97,459
EB2127
Author by

EB2127

Updated on October 04, 2021

Comments

  • EB2127
    EB2127 over 2 years

    In my terminal, I type $ which python3, outputting

    /opt/local/bin/python3
    

    I would like to configure Atom to run Python3 scripts. In my Atom Config, I have

    runner:
    python: "/opt/local/bin/python3"
    

    However, if I run the following script in some script named filename.py,

    import sys
    print(sys.version)
    

    I get the following output:

    2.7.11 (default, Feb 18 2016, 22:00:44) 
    [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
    

    How exactly does one set up the PATH for Python3.x scripts to run correctly? Is there a different package I could use?