0

I want to use tensorflow in QGIS, so I type python -m pip install tensorflow in OSGeo4W Shell to install and it shows success. But when I type import tensorflow in python console in QGIS (my QGIS version is 3.20.1, and its corresponding python version is 3.9.5), then it returns:

Traceback (most recent call last):
  File "D:\QGIS320\apps\Python39\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\__init__.py", line 49, in <module>
    from ._api.v2 import __internal__
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\_api\v2\__internal__\__init__.py", line 13, in <module>
    from . import distribute
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\_api\v2\__internal__\distribute\__init__.py", line 10, in <module>
    from . import combinations
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\_api\v2\__internal__\distribute\combinations\__init__.py", line 10, in <module>
    from tensorflow.python.distribute.combinations import generate
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\python\distribute\combinations.py", line 39, in <module>
    from tensorflow.python.distribute import multi_process_runner
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\python\distribute\multi_process_runner.py", line 40, in <module>
    from tensorflow.python.distribute import multi_process_lib
  File "D:\QGIS320/apps/qgis/./python\qgis\utils.py", line 799, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\python\distribute\multi_process_lib.py", line 60, in <module>
    if _is_enabled():
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\python\distribute\multi_process_lib.py", line 39, in _is_enabled
    tpu_args = [arg for arg in sys.argv if arg.startswith('--tpu')]
  File "D:\QGIS320\apps\Python39\lib\site-packages\tensorflow\python\distribute\multi_process_lib.py", line 39, in <listcomp>
    tpu_args = [arg for arg in sys.argv if arg.startswith('--tpu')]
AttributeError: 'NoneType' object has no attribute 'startswith'

However, when I type import tensorflow directly in python-qgis.bat corresponding command-line environment, it seems to work well.

Test result

I feel confused. How to solve this problem?

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.