问题: ......Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2解决: os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
问题:FutureWarning: Conversion of the second argument of issubdtype from......
FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters解决:不影响结果,可以不用管,直接忽略。后面相关函数版本更新之后,就不会出现此问题。
问题:pycharm无法载入自定义的函数模块。
解决:
法一:直接 import
这里有个大前提,就是你的py执行文件和模块同属于同个目录(父级目录),如下图:

- main.py 和 pwcong模块同在python目录
- 执行文件为main.py
- pwcong文件夹为一个模块
我把pwcong模块提供的函数写在 __init__.py 里,里面只提供一个 hi 函数:
# pwcong 模块的 __init__.py
# -*- coding: utf-8 -*-
def hi():
print("hi")- 1
- 2
- 3
- 4
- 5
执行文件main.py直接import模块:
# main.py
# -*- coding: utf-8 -*-
import pwcong
pwcong.hi()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
接着我们运行一下main.py可以看到命令行窗口输出了一句 hi ,第一种方式完成。
使用模块方式为:先导入-》接着输入
模块.变量|函数, 如上面例子的 pwcong.hi()
法二:通过sys模块导入自定义模块的path
如果执行文件和模块不在同一目录,这时候直接import是找不到自定义模块的。如下图:

- 执行文件main.py在main目录下
- pwcong模块在python目录下
sys模块是python内置的,因此我们导入自定义模块的步骤如下:
先导入sys模块
然后通过
sys.path.append(path)函数来导入自定义模块所在的目录导入自定义模块。
这时候 main.py 这样写:
# main.py
# -*- coding: utf-8 -*-
import sys
sys.path.append(r"C:\Users\Pwcong\Desktop\python")
import pwcong
pwcong.hi()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
最后执行main.py文件,最终输出 hi ,第二种方式完成。
法三:通过pth文件找到自定义模块
这个方法原理就是利用了系统变量,python会扫描path变量的路径来导入模块,可以在系统path里面添加。但是我还是推荐使用pth文件添加。
模块和执行文件目录结构跟上图一样:

- 执行文件main.py在main目录下
- pwcong模块在python目录下
我们创建一个 module_pwcong.pth 文件,里面内容就是 pwcong模块所在的目录:
C:\Users\Pwcong\Desktop\python- 1
将该 module_pwcong.pth 文件放到这里: python安装目录\Python35\Lib\site-packages
例如我的: 
然后 main.py 导入并使用自定义模块:
# -*- coding: utf-8 -*-
import pwcong
pwcong.hi()
- 1
- 2
- 3
- 4
- 5
- 6
最后执行 main.py 文件,可以输出 hi ,第三种方式完成。
(此解决方案受到 CSDN pwcong 的启示和指导,在此表示感谢 )
本文介绍了解决PyCharm中无法加载自定义模块的问题,提供了三种方法:直接导入、通过sys模块导入自定义模块的路径、以及通过pth文件让Python找到自定义模块。

432

被折叠的 条评论
为什么被折叠?



