如何配置 Atom 来运行 Python3 脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35546627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure Atom to run Python3 scripts?
提问by EB2127
In my terminal, I type $ which python3
, outputting
在我的终端中,我输入$ which python3
,输出
/opt/local/bin/python3
I would like to configure Atom to run Python3 scripts. In my Atom Config, I have
我想配置 Atom 来运行 Python3 脚本。在我的原子配置中,我有
runner:
python: "/opt/local/bin/python3"
However, if I run the following script in some script named filename.py
,
但是,如果我在某个名为 的脚本中运行以下脚本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?
究竟如何为 Python3.x 脚本设置 PATH 以使其正确运行?我可以使用不同的包吗?
采纳答案by Terry
Go to the Atom's menu bar -> Packages -> Script -> Configure Script (Or, you can use the shortcut Shift+Ctrl+Alt+O)
转到 Atom 的菜单栏 -> 包 -> 脚本 -> 配置脚本(或者,您可以使用快捷键 Shift+Ctrl+Alt+O)
Then type python3
to the Command space.
Hopefully, it will work.
然后键入python3
命令空间。希望它会起作用。
回答by Nello
If you are using Mac OS X, use the directory on the terminal to open the file.
如果您使用的是 Mac OS X,请使用终端上的目录打开文件。
Select the file python3, right click and select "get info". Select the directory from "Where:" and past it in Atom.
选择文件python3,右键单击并选择“获取信息”。从“Where:”中选择目录并将其粘贴到 Atom 中。
As Terry told you:
正如特里告诉你的:
Then type python3 to the Command space.
然后在命令空间输入 python3 。
回答by MichaelHuelsen
You can use the Atom package atom-python-runto 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}
.
您可以使用 Atom 包atom-python-run从 Atom 启动 python 代码,python 版本可以在包设置中配置。默认情况下, atom-python-run 使用语法python {file}
. 如果您系统上的 python 命令尚未指向 python3,只需替换设置并写入python3 {file}
.
回答by Neo Ravi
Install atom-runner in your Atom going into your settings of Atom and then inside Package and search for atom-runner and install it.
在 Atom 中安装 atom-runner,进入 Atom 的设置,然后在 Package 中搜索 atom-runner 并安装它。
Now click on settings tab for atom-runner as shown above on picture.
Then click on View Code as shown in below picture.
现在单击 atom-runner 的设置选项卡,如上图所示。然后点击查看代码,如下图所示。
Then go to lib folder and open atom-runner.coffee and replace the following section of code:
然后转到 lib 文件夹并打开 atom-runner.coffee 并替换以下代码段:
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:
确保python关键字值为python3,默认情况下为python。请参考下图:
Other way is to find the location of python3 using command
另一种方法是使用命令找到python3的位置
which python3
for me output is :
对我来说输出是:
/usr/local/bin/python3
and add as a shebang in your every python file. For example:-
并在您的每个 python 文件中添加一个shebang。例如:-
#!/usr/local/bin/python3
import sys
print("Version ",sys.version)
Only catch is that you have to write this in each file.
唯一的问题是你必须在每个文件中写这个。
回答by Capt
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.
如果您在 Mac OS 上使用 Atom 并安装了 script 3.18.1 和 atom-python-run 0.9.7 软件包,以下步骤将对您有所帮助。
Script-> Configure Script
脚本-> 配置脚本
Then type in Python3 in the command field in the options dialog.
然后在选项对话框的命令字段中输入 Python3。
This should solve your problem.
这应该可以解决您的问题。
回答by Nafi Shahriyar
You are probably using atom-python-runpackage 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-runpackage to tell it that we want to use Python3. The process is simple. Go to settings>>Packages, click the settings button on atom-python-runpackage 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.
您可能正在使用atom-python-run包直接从 Atom 运行 Python。如果 Python2 是您系统中 Python 的默认版本,那么 Atom 将尝试使用 Python2 解释器运行您的 Python 代码。您所要做的就是更改atom-python-run包中的一些设置,以告诉它我们要使用 Python3。这个过程很简单。转到settings>> Packages,单击atom-python-runpackage上的设置按钮,在 F5 和 F6 命令字段中,将 python 与 python3 交换。就是这样。现在您可以通过按 F5 或 F6 按钮来运行您的 Python3 脚本。
回答by user3365784
i am using "script" package (3.18.1 by rgbkrk) to run code inside atom and this is how i fixed it
我正在使用“脚本”包(rgbkrk 的 3.18.1)在 atom 内部运行代码,这就是我修复它的方式
- open package settings -> view code
- open lib -> grammars -> python.coffee
- change from python to python3 in those two places 'Selection Based' and 'File Based'
- 打开包设置 -> 查看代码
- 打开 lib -> 语法 -> python.coffee
- 在“基于选择”和“基于文件”这两个地方从 python 更改为 python3
回答by Vivek Trivedi
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.
只需在配置运行选项中添加您的命令并保存即可。然后使用“使用配置文件运行”来使用命令来执行您的脚本。这对我有用。