Pycharm: quot;unresolved referencequot; error on the IDE when opening a working project(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 出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Pycharm:“未解决的参考";打开工作项目时 I
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
