简体   繁体   中英

I get a type error when importing tensorflow

So I have this line of code import tensorflow but whenever I run it I get this error

  File "C:\Users\bartl\Documents\PythonProjects\TensorFlowMachineLearningTutorials\LinearRegression.py", line 1, in <module>
    import tensorflow
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py", line 64, in <module>
    from tensorflow.python.framework.framework_lib import *  # pylint: disable=redefined-builtin
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\framework_lib.py", line 52, in <module>
    from tensorflow.python.framework.importer import import_graph_def
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\importer.py", line 28, in <module>
    from tensorflow.python.framework import function
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\function.py", line 36, in <module>
    from tensorflow.python.ops import array_ops
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\array_ops.py", line 429, in <module>
    listdiff.__doc__ = gen_array_ops.list_diff.__doc__ + "\n" + listdiff.__doc__
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

I have only just installed tensorflow using pip install tensorflow and I went to check if it installed properly but I keep getting this error message. Does anyone know how to fix this? EDIT: I get this error from reinstalling tensorflow

ERROR: Exception:
Traceback (most recent call last):
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\cli\base_command.py", line 188, in _main
    status = self.run(options, args)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\cli\req_command.py", line 185, in wrapper
    return func(self, options, args)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\commands\install.py", line 333, in run
    reqs, check_supported_wheels=not options.target_dir
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 179, in resolve
    discovered_reqs.extend(self._resolve_one(requirement_set, req))
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 362, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\resolution\legacy\resolver.py", line 314, in _get_abstract_dist_for
    abstract_dist = self.preparer.prepare_linked_requirement(req)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 469, in prepare_linked_requirement
    hashes=hashes,
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 259, in unpack_url
    hashes=hashes,
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 130, in get_http_url
    link, downloader, temp_dir.path, hashes
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\operations\prepare.py", line 277, in _download_http_url
    download = downloader(link)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\network\download.py", line 189, in __call__
    resp = _http_get_download(self._session, link)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\network\download.py", line 157, in _http_get_download
    stream=True,
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\requests\sessions.py", line 543, in get
    return self.request('GET', url, **kwargs)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_internal\network\session.py", line 421, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 44, in send
    cached_response = self.controller.cached_request(request)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\cachecontrol\controller.py", line 145, in cached_request
    resp = self.serializer.loads(request, cache_data)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\cachecontrol\serialize.py", line 97, in loads
    return getattr(self, "_loads_v{}".format(ver))(request, data)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\cachecontrol\serialize.py", line 184, in _loads_v4
    cached = msgpack.loads(data, raw=False)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\msgpack\fallback.py", line 129, in unpackb
    ret = unpacker._unpack()
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\msgpack\fallback.py", line 670, in _unpack
    ret[key] = self._unpack(EX_CONSTRUCT)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\msgpack\fallback.py", line 670, in _unpack
    ret[key] = self._unpack(EX_CONSTRUCT)
  File "C:\Users\bartl\AppData\Local\Programs\Python\Python37\lib\site-packages\pip\_vendor\msgpack\fallback.py", line 683, in _unpack
    return bytes(obj)
MemoryError

This is probably a broken installation, since the error comes from importing the package.

Try to reinstall tensorflow with

pip install -I tensorflow

Also, the tensorflow web page says that it needs a "newer version" of pip, so you might want to update pip, too. (Before installing tensorflow)

python -m pip install -U pip

Memoryerror when trying to install Tensorflow

As mentioned here and here , try reinstalling without caching:

pip install -I --no-cache-dir tensorflow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM