PyCharm 自动导入和自动完成

发布于 2024-11-14 07:06:41 字数 252 浏览 1 评论 0原文

我是第一次尝试 PyCharm。来自 Eclipse/PyDev 环境,我不得不说到目前为止一切进展顺利。

我缺少一个功能,但我似乎找不到,如下所示:

在 PyDev 的自动完成列表中,当输入文件范围内不存在的符号时,它将显示一个列表如果您选择该自动完成项,PyDev 不仅会为您完成符号,还会自动添加 import 语句来处理依赖关系。

PyCharm 中存在这个吗?

到目前为止,它似乎只是自动完成文档范围内已有的内容。

I am giving PyCharm a try for the first time. Coming from an Eclipse/PyDev environment I have to say so far things have been going well.

There is one feature I am missing that I can't seem to find though and that is as follows:

In the auto-complete list in PyDev, when typing a symbol that doesn't exist in the file's scope it will show a list of modules that it's in. If you select that autocomplete item not only will PyDev complete the symbol for you but it will automatically add the import statement to take care of the dependency as well.

Does this exist in PyCharm?

So far it only seems to autocomplete things already in the scope of the document.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

jJeQQOZ5 2024-11-21 07:06:41

请参阅设置 | 编辑器 | 一般 | 自动导入

See Settings | Editor | General | Auto Import.

吾家有女初长成 2024-11-21 07:06:41

我认为这绝对是一个bug或者功能不好

全新安装的pycharm 2021.3.3,在编写代码时,IDE本身会根据代码中的随机单词自动悄悄地放置一些包。
结果,环境被破坏了。

这是一个示例(来自 pycharm eventlog):

source /home/user/.cache/pypoetry/virtualenvs/project-_uWvZL1R-py3.9/bin/activate
/home/user/anaconda3/bin/poetry add self

Using version ^2020.12.3 for self

Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 2 installs, 0 updates, 1 removal

  • Removing setuptools (62.6.0)
  • Installing decorator (5.1.1)
  • Installing self (2020.12.3)

  EnvCommandError

    × python setup.py egg_info did not run successfully.
    │ exit code: 1
    ╰─> [1 lines of output]
        ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
        [end of output]

I think this is definitely a bug or bad functional

Fresh installation of pycharm 2021.3.3, when writing code, the IDE itself automatically quietly puts some packages according to random words from the code.
As a result, the environment was broken.

here is an example (that from pycharm eventlog):

source /home/user/.cache/pypoetry/virtualenvs/project-_uWvZL1R-py3.9/bin/activate
/home/user/anaconda3/bin/poetry add self

Using version ^2020.12.3 for self

Updating dependencies
Resolving dependencies...

Writing lock file

Package operations: 2 installs, 0 updates, 1 removal

  • Removing setuptools (62.6.0)
  • Installing decorator (5.1.1)
  • Installing self (2020.12.3)

  EnvCommandError

    × python setup.py egg_info did not run successfully.
    │ exit code: 1
    ╰─> [1 lines of output]
        ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
        [end of output]
完美的未来在梦里 2024-11-21 07:06:41

这些变体已经存在,只是出于性能原因未包含在基本完成和完成自动弹出窗口中。为了看到它们,您需要在同一位置第二次调用完成或使用专用快捷方式(在键盘映射设置中搜索“第二次基本完成”)。

自动-导入扩展完成演示

These variants are already there, they are just not included in the basic completion and completion auto-popup for performance reasons. In order to see them you need to invoke completion for the second time at the same place or use a dedicated shortcut (search for "Second Basic Completion" in the keymap settings).

Auto-import extended completion demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文