首页 > 解决方案 > 我可以在 python 终端上导入 tensorflow,但是如果我尝试运行我的 py 文件,我不能

问题描述

当我在终端中使用 python 时;

pi@raspberrypi:~ $ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
2020-07-26 12:52:03.075590: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
>>> 

但我尝试运行我的 py 文件

pi@raspberrypi:~ $ sudo python /home/pi/tfdeneme.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "/home/pi/tfdeneme.py", line 17, in <module>
    import tensorflow
ModuleNotFoundError: No module named 'tensorflow'

我在我的 Windows 机器上使用 tensorflow 2.2.0,在树莓派 tensorflow 版本上 =

pi@raspberrypi:~ $ python
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-07-26 12:53:49.504578: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
>>> tf.__version__
'1.14.0'

我应该怎么做才能运行我的 py 文件?

标签: pythontensorflowraspberry-pi

解决方案


我在 TF 2.2.0 和 python 3.7 上遇到问题,因此降级到 python 3.6,现在它似乎正在工作。请注意我在Mac上


推荐阅读