您现在的位置是:课程教程文章

python用import报错如何解决

2023-12-18 23:04课程教程文章 人已围观

 

一个文件夹下的同一级的文件,import 时却无法导入,为什么呢?

This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, 
this is possible 
in a limited but useful number of cases. Top-level and class-level items are supported better than 
instance items.

 import不成功就是因为路径没对应,事实上是pycharm默认该项目的根目录为source目录,所以import使用绝对路径而不是相对路径的话,就会从项目的根目录中查找,而不是我们希望的其中的/src目录,所以import不成功。

解决方法

关键点在于mark as sources 的是py 文件所在的文件夹目录,紧接着开始调用函数了。

课程教程:python用import报错如何解决

上一篇:python如何导入包

下一篇:没有了

站点信息

  • 文章统计篇文章