Pycharm:“未解决的参考";打开工作项目时 IDE 出现错误 [英] Pycharm: "unresolved reference" error on the IDE when opening a working project

查看:44
本文介绍了Pycharm:“未解决的参考";打开工作项目时 IDE 出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介

我在 git 存储库上有一个 Python 项目.对于大多数团队成员来说一切正常,我们可以在不同平台(Windows、Linux)上使用 Pycharm 同步代码并对其进行编辑,而不会出现任何问题

I have a Python project on a git repository. Everything works ok for most of the team members, we can sync the code and edit it without any problem with Pycharm on different platforms (Windows, Linux)

问题

在其中一台计算机上,除了 Python 的内置库(即 import datetime 正在工作)之外,几乎每次导入的代码中我们都会得到未解析的引用".这台电脑运行的是 Mac 版的 Pycharm.

On one of the computers we are getting "Unresolved reference" all over the code on almost every import with the exception of Python's built in libraries (i.e. import datetime is working). This computer is running the Mac version of Pycharm.

问题

任何人都知道如何解决这个问题吗?因为大多数导入都无法识别代码完成和导航槽 goto->declaration 等等都不起作用.Mac 版本是否存在任何已知问题?

Anyone knows how to solve this?, since most of the imports are not recognized code completion and navigation trough goto->declaration and so on is not working. Is there any known issue with the Mac version?

提前致谢!

推荐答案

关键是要把你的源码目录标记为源码根目录.请尝试以下操作:

The key is to mark your source directory as a source root. Try the following:

  • 在项目视图中,右键单击 Python 源目录
  • 在对话框菜单中选择 Mark Directory As > Source Root

文件夹现在应该显示为蓝色而不是米色,表示它是 Python 源文件夹.

The folder should now appear blue instead of beige, to indicate it is a Python source folder.

您还可以在 PyCharm 首选项中配置此项,方法是对 PyCharm 中已有的项目执行以下操作:

You can also configure this in PyCharm preferences by doing the following for a project that is already in PyCharm:

  • 在 Mac 工具栏中,选择 PyCharm > 首选项
  • 在打开的窗口中,从左侧的菜单窗格中选择项目结构
  • 如有必要,请在中间窗格中选择您的项目
  • 右键单击右侧窗格中的 Python 源代码,然后从菜单对话框中选择 Sources

这篇关于Pycharm:“未解决的参考";打开工作项目时 IDE 出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆