导入os.path时的怪异行为 [英] weird behavior when importing os.path
问题描述
我不太确定这个问题属于StackOverflow,而不属于其他SE网站,但是由于它与python相关,所以我认为它可能合适.
I'm not quite sure this question belong to StackOverflow and not other SE website, but since it's python related I thought it might fit.
最近,我开始在我的IDE中出现错误(下面的我的IDE上的详细信息)-我收到一个错误在'os.py'中找不到引用'路径'"通过查看os.py,我意识到os.path只是posixpath.py(在Linux上)或ntpath.py(在Windows上)的别名.现在,没有对我的python安装进行任何更改,并且在运行导入os.path(或从中导入)的脚本时,它们都可以正常运行,因此没有实际错误,只是在我的IDE中令人讨厌的警告.我尝试在IDE中更改项目解释器,但没有用.我还尝试使用所说的IDE从终端运行,并且运行良好.难道是PyCharm中的错误?
Recently, I started getting error in my IDE (details on my IDE below) - I get an error "cannot find reference 'path' in 'os.py'" Looking into os.py, I realize that os.path is just an alias for posixpath.py (on Linux) or ntpath.py (on Windows). Now, no change has been made to my python installation, and when running scripts that import os.path (or from it), they all run fine, so there is no actual error, just annoying warning in my IDE. I tried changing the project interpreter in the IDE and it didn't work. I also tried running from terminal with the said IDE, and it worked fine. Could it be a bug in PyCharm?
我在网上查看,找不到错误报告或任何遇到相同问题的人.
I looked online and couldn't find bug report or anyone struggling with the same problem.
PyCharm构建详细信息:
PyCharm 2018.1(社区版)内部版本#PC-181.4203.547,于2018年3月26日建立JRE:1.8.0_152-release-1136-b20 amd64JVM:JetBrains s.r.o的OpenJDK 64位服务器VMLinux 4.7.0-0.bpo.1-amd64
PyCharm 2018.1 (Community Edition) Build #PC-181.4203.547, built on March 26, 2018 JRE: 1.8.0_152-release-1136-b20 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.7.0-0.bpo.1-amd64
推荐答案
此错误已在2018.1.1中修复. https://youtrack.jetbrains.com/issue/PY-28764
It's a bug that was fixed in 2018.1.1 https://youtrack.jetbrains.com/issue/PY-28764
这篇关于导入os.path时的怪异行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!