简体   繁体   English

如何在 OSX 上使用 IntelliJ IDEA 设置 Python 3?

[英]How do I set up Python 3 with IntelliJ IDEA on OSX?

I'm highly confused about this.我对此非常困惑。 Python3 is installed per default on the MacBook. Python3 默认安装在 MacBook 上。

which python3 will output /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 which python3将输出/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

Great, so that's my SDK to put into IntelliJ IDEA, one should think.太好了,这就是我要放入 IntelliJ IDEA 的 SDK,你应该想一想。

I have the Python plugin for IDEA.我有适用于 IDEA 的 Python 插件。 However, I can't run Python files.但是,我无法运行 Python 文件。 So I try to change the configuration and set it to the above PATH for the Python interpreter.所以我尝试更改配置并将其设置为 Python 解释器的上述 PATH。

However, still nothing.然而,还是什么都没有。 Trying to run the Python file inside IDEA will prompt a new configuration?尝试运行IDEA里面的Python文件会提示新配置?

I can run the script just file doing python3 script.py in the terminal?我可以只在终端中执行python3 script.py文件来运行脚本吗? I know the path for the Python3 library, yet, IDEA doesn't recognise it at all and doesn't save the configuration.我知道 Python3 库的路径,但是,IDEA 根本无法识别它并且不保存配置。

What am I doing wrong in this process?我在这个过程中做错了什么? This should be fairly easy to set up but turns out it isn't :)这应该很容易设置,但事实证明它不是:)

I even tried to create a Python 3.6.2 virtual environment with the IDEA internal tool - same thing?我什至尝试使用 IDEA 内部工具创建 Python 3.6.2 虚拟环境 - 同样的事情? It doesn't allow me to run the Python3 script from inside IDEA.它不允许我从 IDEA 内部运行 Python3 脚本。

Should I use python from usr/bin/python ?我应该使用usr/bin/python吗? If I cd there, I can see Python3.如果我在那里 cd,我可以看到 Python3。 But inside IDEA, i only have access to Python2..但在 IDEA 中,我只能访问 Python2 ..

After installing Python 3.8.1 via pyenv which I now recommend over using Homebrew (see https://github.com/pyenv/pyenv ), I did the following to add this version to IntelliJ IDEA.通过 pyenv 安装 Python 3.8.1 后,我现在推荐使用 Homebrew(参见https://github.com/pyenv/pyenv ),我执行以下操作将此版本添加到 IntelliJ IDEA。

  1. Close all open projects.关闭所有打开的项目。 This will display the Welcome to IntelliJ IDEA window listing recent projects along the left.这将显示欢迎使用 IntelliJ IDEA 窗口,在左侧列出最近的项目。
  2. Click on Configure -> Structure for New Projects单击配置 -> 新项目的结构
  3. Click on SDKs under Platform Settings along the left单击左侧 Platform Settings 下的 SDKs
  4. Click on the + sign above the SDK list and select Python SDK单击 SDK 列表上方的 + 号并选择 Python SDK
  5. From the Add Python Interpreter window, select System Interpreter从“添加 Python 解释器”窗口中,选择“系统解释器”
  6. Click on the ... button to the right of the Interpreter drop down and browse to $HOME/.pyenv/versions/3.8.1/bin/python.单击 Interpreter 下拉菜单右侧的 ... 按钮并浏览至 $HOME/.pyenv/versions/3.8.1/bin/python。 Replace 3.8.1 with the desired Python version if you want to configure another version.如果要配置另一个版本,请将 3.8.1 替换为所需的 Python 版本。

Updated for IntelliJ IDEA 2019.3.3针对 IntelliJ IDEA 2019.3.3 更新

在 IDEA 的菜单中试试这个: File -> Settings -> Project: Name of project -> Project Interpreter ,从上面的窗口中你可以选择解释器版本或 virtualenv。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM