【问题标题】:hickle NameError: name 'file' is not definedhickle NameError:未定义名称“文件”
【发布时间】:2021-01-12 13:29:32
【问题描述】:

请向我解释为什么会出现这个错误。我已经在 ubuntu 中安装了 python 3.5

import os
import hickle as hkl
import numpy as np
array_obj = np.ones(32768, dtype='float32')
hkl.dump(array_obj, 'test.hkl', mode='w')

结果是

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\hickle.py", line 308, in dump
    h5f = file_opener(file_obj, mode, track_times)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35\lib\site-packages\hickle.py", line 148, in file_opener
    if isinstance(f, file):
NameError: name 'file' is not defined

【问题讨论】:

  • file() 在 Python 3 中不受支持。您应该安装 Python 2.7 并重试。

标签: python python-3.x tensorflow


【解决方案1】:

Hickle 不支持 Python3(它使用 Python3 不支持的 file() 函数),但你可以在 GitHub 上找到 modified version,或者直接使用 Python2。

【讨论】:

    【解决方案2】:

    作为hickle的主要开发者之一:3年前,它确实还不支持Python 3。 另一方面,现在它工作得很好(事实上,现在已经放弃了对 Python 2.7 的支持)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-20
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      相关资源
      最近更新 更多