如何使用 PyCharm 插件在 IntelliJ IDEA 中配置 Python 解释器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24769117/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 05:10:14  来源:igfitidea点击:

How do I configure a Python interpreter in IntelliJ IDEA with the PyCharm plugin?

pythonintellij-idea

提问by kousen

There is a tutorial in the IDEA docs on how to add a Python interpreter in PyCharm, which involves accessing the "Project Interpreter" page. Even after installing the Python plugin, I don't see that setting anywhere.

IDEA 文档中有关于如何在 PyCharm 中添加 Python 解释器的教程,其中涉及访问“项目解释器”页面。即使在安装 Python 插件之后,我也没有在任何地方看到该设置。

Am I missing something obvious?

我错过了一些明显的东西吗?

回答by Makoto

With the Python plugin installed:

安装 Python 插件后:

  1. Navigate to File > Project Structure.
  2. Under the Project menu for Project SDK, select "New" and
  3. Select "Python SDK", then select "Local".
  1. 导航到文件 > 项目结构。
  2. 在 Project SDK 的 Project 菜单下,选择“New”并
  3. 选择“Python SDK”,然后选择“本地”。

Provided you have a Python SDK installed, the flow should be natural from there - navigate to the location your Python installation lives.

如果您安装了 Python SDK,那么流程应该很自然——导航到您的 Python 安装所在的位置。

回答by Prakash

Follow these steps:

按着这些次序:

  1. Open Setting (Ctrl+ Alt+ s)
  2. Click on plugins
  3. Find Browse Repositories and click
  4. Search for "python"
  5. Select Python SDK or pycharm
  6. Restart the IDE
  7. Go to project structure
  8. Select the python SDK in projects or create a new project with python SDK.
  1. 打开设置 ( Ctrl+ Alt+ s)
  2. 点击插件
  3. 找到浏览存储库并单击
  4. 搜索“蟒蛇”
  5. 选择 Python SDK 或 pycharm
  6. 重新启动IDE
  7. 转到项目结构
  8. 在项目中选择python SDK或者用python SDK新建一个项目。

回答by Menelaos Kotsollaris

For Pycharm users:

对于 Pycharm 用户:

File? Settings? Project: MyProject? Project Interpreter

File? Settings? Project: MyProject?Project Interpreter

回答by Tarun Lalwani

So here is a simple project, where I have used Seleniumand added that using external path

所以这是一个简单的项目,我在其中使用Selenium并添加了使用外部路径

Error

错误

Now you need to open Project Structureand go to SDKSection

现在您需要打开Project Structure并转到SDK部分

Project Structure

项目结构

Now Select your project's virtual environment. In the Classpathtab add the PYTHONPATHby clicking +button

现在选择您项目的虚拟环境。在Classpath选项卡中PYTHONPATH通过单击+按钮添加

Add SDK

添加开发工具包

and now the modules will be recognized

现在模块将被识别

Module recognized

模块识别

回答by Zoltán

If you have multiple modules in your project, with different languages, you can set the interpreter in the following way:

如果您的项目中有多个模块,使用不同的语言,您可以通过以下方式设置解释器:

  • File -> Project Structure...
  • Select Modulesin the list on the left
  • Select the Python module in the list of modules
  • On the right-hand side, either choose an existing Python SDK from the dropdown list, or click on the New...button to create either a virtualenv, or create a new Python SDK from a Python installation on your system.
  • File -> Project Structure...
  • Modules在左侧列表中选择
  • 在模块列表中选择 Python 模块
  • 在右侧,从下拉列表中选择现有的 Python SDK,或单击New...按钮创建 virtualenv,或从系统上的 Python 安装创建新的 Python SDK。

回答by Junaid

I was getting the error (IntelliJ on Ubuntu 18.04) while python SDK was configured.

配置 python SDK 时出现错误(Ubuntu 18.04 上的 IntelliJ)。

To fix that, I had to do this:

为了解决这个问题,我必须这样做:

  1. File-> Project Structure-> Modules
  2. Click on the Dependenciestab, and click on +and select the python SDK

    enter image description here

  3. Click on Apply

  1. File-> Project Structure->Modules
  2. 单击Dependencies选项卡,然后单击+并选择python SDK

    在此处输入图片说明

  3. 点击 Apply

After that, the warning went away and autocompletion also started working properly

在那之后,警告消失了,自动完成也开始正常工作