Python 3.4 on Sublime Text 3

不羁岁月 提交于 2019-12-17 10:27:29

问题


I followed these steps to run Python 3 on Sublime Text 3.

Select the menu Tools > Build > New Build System and I entered the following:

{
"cmd": ["python3", "$file"]
, "selector": "source.python"
, "file_regex": "file \"(...*?)\", line ([0-9]+)"
}

After that, I saved it to the following (Mac-specific) directory: ~/Library/Application Support/Sublime Text 3/Packages/User

but I'm getting this error when I'm trying to run my code on Python 3 in Sublime:

[Errno 2] No such file or directory: 'python3'

回答1:


You need to provide the full path to python3, since Sublime Text does not read your ~/.bash_profile file. Open up Terminal, type which python3, and use that full path:

{
  "cmd": ["path/to/python3", "$file"], 
  "selector": "source.python", 
  "file_regex": "file \"(...*?)\", line ([0-9]+)"
}



回答2:


This is the snippet that I've been using. It's a slight variation to Andrew's solution, such that python3 is dynamically located by consulting the UNIX environment's PATH setting (not unlike how you would do the same inside a Python shell script; e.g.: '#! /usr/bin/env python3').

This snippet also uses "shell_cmd" instead of "cmd", which sublime-text-3 has seemingly switched to.

{
    "shell_cmd": "/usr/bin/env python3 ${file}",
    "selector": "source.python",
    "file_regex": "^(...*?):([0-9]*):?([0-9]*)",
    "working_dir": "${file_path}",
}

I saved mine in ".../Packages/User/Python3.sublime-build". I hope this helps you. =:)




回答3:


Thanks for your question. I began to learn python a couple days ago, and I am stuck with the same problem that you have met.Just as Andrew said above,it is “path problem”. I would like to share the code that I used to get python3 on sublime3. For MacOS user:

{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf8",
"path": "/usr/local/Frameworks/Python.framework/Versions/3.3/bin/"
}

and save the file as Python3.sublime-build. I deeply recommended the book "A byte of python " for the new beginner of python.This book contributes a lot to my answer for this question.



来源:https://stackoverflow.com/questions/23257984/python-3-4-on-sublime-text-3

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