How to configure Atom to run Python3 scripts?

前端 未结 8 1135
南旧
南旧 2020-11-27 19:12

In my terminal, I type $ which python3, outputting

/opt/local/bin/python3

I would like to configure Atom to run Python3 scrip

相关标签:
8条回答
  • 2020-11-27 19:32

    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.

    0 讨论(0)
  • 2020-11-27 19:38

    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}.

    0 讨论(0)
  • 2020-11-27 19:38

    You are probably using atom-python-run package to run Python directly from Atom. If Python2 is the default version of Python in your system, then Atom will try to run your Python code with Python2 interpreter. All you have to do is to change some settings in atom-python-run package to tell it that we want to use Python3. The process is simple. Go to settings>>Packages, click the settings button on atom-python-run package and in the fields of F5 and F6 command, exchange python with python3. That's it. Now you can run your Python3 script by pressing F5 or F6 button.

    0 讨论(0)
  • 2020-11-27 19:38

    Just add your command in the Configure Run Options and save it. Then use 'Run with Profile' to use the command to execute your script. This worked for me.

    0 讨论(0)
  • 2020-11-27 19:39

    If you are using Atom on Mac OS and have script 3.18.1 and atom-python-run 0.9.7 packages installed, the following steps will help you out.

    Script-> Configure Script

    Then type in Python3 in the command field in the options dialog.

    This should solve your problem.

    0 讨论(0)
  • 2020-11-27 19:42

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

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

    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:

    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.

    0 讨论(0)
提交回复
热议问题