标签归档:intellij-idea

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

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

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

我是否缺少明显的东西?

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.

Am I missing something obvious?


回答 0

安装了Python插件后:

  1. 导航到文件>项目结构。
  2. 在Project SDK的“项目”菜单下,选择“新建”,然后
  3. 选择“ Python SDK”,然后选择“本地”。

假设您已安装Python SDK,则流程应该自然而然-导航至Python安装所在的位置。

With the Python plugin installed:

  1. Navigate to File > Project Structure.
  2. Under the Project menu for Project SDK, select “New” and
  3. Select “Python SDK”, then select “Local”.

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


回答 1

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

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

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

现在模块将被识别

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

Now you need to open Project Structure and go to SDK Section

Now Select your project’s virtual environment. In the Classpath tab add the PYTHONPATH by clicking + button

and now the modules will be recognized


回答 2

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

  • File -> Project Structure...
  • Modules在左侧列表中选择
  • 在模块列表中选择Python模块
  • 在右侧,从下拉列表中选择现有的Python SDK,或单击New...按钮创建virtualenv,或通过系统上的Python安装创建新的Python SDK。

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

  • File -> Project Structure...
  • Select Modules in 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.

回答 3

跟着这些步骤:

  1. 开启设定(Ctrl+ Alt+ s
  2. 点击插件
  3. 查找浏览存储库,然后单击
  4. 搜索“ python”
  5. 选择Python SDK或pycharm
  6. 重新启动IDE
  7. 转到项目结构
  8. 在项目中选择python SDK或使用python SDK创建一个新项目。

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.

回答 4

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

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

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

  3. 点击 Apply

此后,警告消失,自动补全也开始正常工作

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

To fix that, I had to do this:

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

  3. Click on Apply

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


如何使IntelliJ识别常见的Python模块?

问题:如何使IntelliJ识别常见的Python模块?

我正在使用IntelliJ 10 IDEA Ultimate Edition。

我创建了一个新文件Test.py,并且IntelliJ已正确切换到Python解析模式。(我可以通过输入“ d”来确认这一点,它会弹出“ def”作为建议,然后正确点击选项卡会给我“ def:”)

但是,当我尝试此代码时…

import os

cwd = os.getcw <Ctrl-space>

发生两件事…

  1. 我在os下面有一个乱七八糟的下划线,将鼠标悬停在它上面给我一条“未解决的参考’os’”消息
  2. 当我期望看到“ getcwd”时,没有任何建议可以击中上面的Ctrl-space。

我以为这一定是由于我没有正确配置IntelliJ以处理python模块而导致的,但是我不知道我缺少了什么。

任何IntelliJ / Python用户能够帮助我吗?

I’m using IntelliJ 10 IDEA Ultimate Edition.

I’ve created a new file Test.py, and IntelliJ has correctly switched to Python parsing mode. (I can confirm this by typing “d”, it pops up “def” as a suggestion, and hitting tab correctly gives me “def :”)

However, when I try this code…

import os

cwd = os.getcw <Ctrl-space>

Two things happen….

  1. I get a squggly underline underneath os and hovering over it gives me a “Unresolved reference ‘os'” message
  2. I get no suggestions hitting Ctrl-space above, when I’m expecting to see “getcwd”.

I’m assuming that this must be a result of my not configuring IntelliJ properly in order to handle python modules, but I have no idea what it is I’m missing.

Any IntelliJ/Python users able to help me out?


回答 0

只需创建并添加Python SDK

File -> Project Structure -> Project -> Project SDK -> new

并选择Python解释器的安装路径(例如,C:\Python26在Windows和/usr/bin/python2.7Linux中)作为主路径。

相关讨论:http : //devnet.jetbrains.net/thread/286883

Just create and add Python SDK

File -> Project Structure -> Project -> Project SDK -> new

and select the installation path of your Python interpreter (for example, C:\Python26 in windows and /usr/bin/python2.7 in Linux) as the home path.

Related discussion: http://devnet.jetbrains.net/thread/286883


回答 1

您是否设置了python解释器构面?

打开项目结构CTRL+ ALT+ SHIFT+S

Project settings -> Facets -> expand Python click on child -> Python Interpreter

然后:

Project settings -> Modules -> Expand module -> Python -> Dependencies -> select Python module SDK

Have you set up a python interpreter facet?

Open Project Structure CTRL+ALT+SHIFT+S

Project settings -> Facets -> expand Python click on child -> Python Interpreter

Then:

Project settings -> Modules -> Expand module -> Python -> Dependencies -> select Python module SDK


回答 2

如果您的Python SDK已正确配置,并且您仍然面临无法识别内置程序的问题,请尝试以下操作:

File -> Invalidate Caches/Restart

If your Python SDK is properly configured and you are still facing the problem that builtins are not recognized, try this:

File -> Invalidate Caches/Restart

回答 3

这就是我要做的。(而且我可能忘记了我的问题的一个重要方面,这并不是最初设置为Python项目,而是设置为Java项目,其中包含一些python文件。)

项目设置->模块->加号按钮(添加模块)-> Python

然后,单击Python解释器旁边的“ …”按钮。

在弹出的“配置SDK”对话框中,单击“ +”按钮。选择“ Python SDK”,然后选择出现在我的查找器对话框中的默认“ Python”快捷方式

等待约5分钟。阅读一些生产力提示。:)

点击确定

等待系统重建一些索引。

万岁!代码提示又回到了我的模块!

Here’s what I had to do. (And I probably forgot an important aspect of my problem, which is that this wasn’t set up as a Python project originally, but a Java project, with some python files in them.)

Project Settings -> Modules -> Plus button (add a module) -> Python

Then, click the “…” button next to Python Interpreter.

In the “Configure SDK” dialog that pops up, click the “+” button. Select “Python SDK”, then select the default “Python” shortcut that appears in my finder dialog

Wait about 5 minutes. Read some productivity tips. :)

Click Ok

Wait for the system to rebuild some indexes.

Hooray! Code hinting is back for my modules!


回答 4

另一个可能的解决方法(解决了我的问题)

您可能已经正确配置了环境,但是由于某种原因,环境一直中断。在这种情况下,请转到:

file > project settings > modules

部署SDK列表,并[invalid]在末尾寻找一条红线。如果找到一个,则必须重新创建一个python sdk。

您以前可以使用的SDK也可能在那里,但不是红色。删除它。

现在,您可以单击new按钮并添加您喜欢的python virtualenv。现在应该可以了。

Another possible fix (solved my problem)

You might have configured the environment properly but for some reason it broke along the way. In this case go to:

file > project settings > modules

Deploy the list of SDKs and look for a red line with [invalid] at the end. If you find one, you have to recreate a python sdk.

It is likely that your previously working SDK is there too, but not red. Delete it.

Now you can click on the new button and add your favorite python virtualenv. And it should work now.


回答 5

几个步骤对我有所帮助(上面提到了其中一些步骤):

通过以下方式打开项目结构:

命令+; (Mac用户)或右键单击项目“ ->打开模块设置”

  1. 构面->+ ->Python -><您的项目> ->确定
  2. 模块->Python -><选择python解释器>
  3. 项目->Project SDK -><选择相关的SDK>
  4. SDK -><确保它是正确的>

点击OK

通过以下方式打开运行/调试配置:运行->编辑配置

  1. Python解释器-><确保它是正确的>

点击OK

Few steps that helped me (some of them are mentioned above):

Open project structure by:

command + ; (mac users) OR right click on the project -> Open Module Settings

  1. Facets -> + -> Python -> <your-project> -> OK
  2. Modules -> Python -> <select python interpreter>
  3. Project -> Project SDK -> <select relevant SDK>
  4. SDKs -> <make sure it’s the right one>

Click OK.

Open Run/Debug Configurations by: Run -> Edit Configurations

  1. Python Interpreter -> <make sure it’s the right one>

Click OK.


回答 6

这就是我解决问题的方式(我已经导入了项目,并且仅在此处显示,新创建的文件未显示那些错误):

1)Command + alt + R(在Windows中为Control

2)将出现“调试”窗口,选择文件并按向右箭头(->),然后选择“编辑”,然后按Enter(将出现“编辑配置设置”窗口)

3)在配置下,您会在底部看到错误(请选择一个带有有效python sdk的模块),因此在Python解释器中,选中“使用指定的解释器”,然后在下拉菜单中选择您的Python版本

(如果没有python,请使用以下链接https://www.jetbrains.com/help/idea/2016.3/installing-updating-and-uninstalling-repository-plugins.html下载intelliJ的python插件

4)单击应用,然后将其关闭。

宾果游戏完成了。

This is how i solved my problem (i have imported the project and it was showing there only, newly created files were not showing those errors):

1) Command + alt + R (Control in case of windows

2) Debug window will appear, select your file and press right arrow (->) and choose Edit then press enter (Edit configuration setting window will appear)

3) Under configuration, at the bottom you can see the error (please select a module with a valid python sdk), So in Python Interpreter, check Use Specified Interpreter, then in drop down you select your Python version

(In case python is not there download python plugin for intelliJ using following link https://www.jetbrains.com/help/idea/2016.3/installing-updating-and-uninstalling-repository-plugins.html

4) Click on apply then close it.

Bingo it’s done.


回答 7

使用需求文件(请参阅指向JetBrains文档的链接)

就我而言,我需要arrow。所以,我加了

arrow==0.7.0

到我的项目 requirements.txt

然后Intellij提示我第一次import arrow使用Python脚本编写时添加库

Use a Requirements File (see link to JetBrains documentation)

In my case I needed arrow. So, I added

arrow==0.7.0

to my projects requirements.txt

Then Intellij prompted me to add the library the first time that I wrote import arrow in a Python script


回答 8

我的问题类似于@Toddarooski的问题,除了我在“ Dependencies”选项卡下具有的模块未列出SDK之外。我右键单击“ SDK”,从下拉菜单中选择“编辑”,然后选择我的Python SDK。做到了。

My problem was similar to @Toddarooski ‘s, except that the module I had, under the “Dependencies” tab, had no SDK listed. I right clicked on ‘SDK’, picked edit from the drop down menu, and selected my Python SDK. That did the trick.


回答 9

在取消选中“运行/调试配置”中的以下选项后,我可以使用它 main.py

Add content roots to PYTHONPATH

Add source roots to PYTHONPATH

这是在我使缓存无效并重新启动之后。

I got it to work after I unchecked the following options in the Run/Debug Configurations for main.py

Add content roots to PYTHONPATH

Add source roots to PYTHONPATH

This is after I had invalidated the cache and restarted.


回答 10

甚至我在Pycharm中的Intellisense都不适合时间模块,例如 系统中的问题没有选择口译员转到文件 -> 设置…(Ctrl + Alt + S)打开项目口译员

就我而言,项目口译员被选中。我选择了可​​用的python解释器。如果不可用,您可以添加一个新的解释器。

Even my Intellisense in Pycharm was not working for modules like time Problem in my system was no Interpreter was selected Go to File –> Settings… (Ctrl+Alt+S) Open Project Interpreter

Project Interpreter In my case was selected. I selected the available python interpreter. If not available you can add a new interpreter.