ImportError:无法导入名称“ extract_zipped_pa​​ths”

时间:2019-09-11 13:22:29

标签: python-3.x tensorflow

我正在尝试访问Tensorflow 2.0中列出的数据集。我使用Windows 10。

我已经运行了以下命令:

pip install tfds-nightly

pip install tensorflow-datasets

我PC中的Tensorflow版本为:

2.0.0-alpha0

(尝试将其升级到更新的版本b时遇到异常:

  Found existing installation: wrapt 1.10.11
ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

当我尝试导入模块时:

import tensorflow_datasets as tfds

我收到以下错误消息:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-30-46a8a2031c9c> in <module>()
----> 1 import tensorflow_datasets as tfds

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow_datasets\__init__.py in <module>()
     44 # needs to happen before anything else, since the imports below will try to
     45 # import tensorflow, too.
---> 46 from tensorflow_datasets.core import tf_compat
     47 tf_compat.ensure_tf_install()
     48 

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow_datasets\core\__init__.py in <module>()
     21 tf_compat.ensure_tf_install()
     22 
---> 23 from tensorflow_datasets.core.dataset_builder import BeamBasedBuilder  # pylint:disable=g-import-not-at-top
     24 from tensorflow_datasets.core.dataset_builder import BuilderConfig
     25 from tensorflow_datasets.core.dataset_builder import DatasetBuilder

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow_datasets\core\dataset_builder.py in <module>()
     33 from tensorflow_datasets.core import constants
     34 from tensorflow_datasets.core import dataset_utils
---> 35 from tensorflow_datasets.core import download
     36 from tensorflow_datasets.core import file_format_adapter
     37 from tensorflow_datasets.core import lazy_imports_lib

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow_datasets\core\download\__init__.py in <module>()
     17 
     18 from tensorflow_datasets.core.download.checksums import add_checksums_dir
---> 19 from tensorflow_datasets.core.download.download_manager import DownloadConfig
     20 from tensorflow_datasets.core.download.download_manager import DownloadManager
     21 from tensorflow_datasets.core.download.extractor import iter_archive

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow_datasets\core\download\download_manager.py in <module>()
     32 from tensorflow_datasets.core import utils
     33 from tensorflow_datasets.core.download import checksums
---> 34 from tensorflow_datasets.core.download import downloader
     35 from tensorflow_datasets.core.download import extractor
     36 from tensorflow_datasets.core.download import resource as resource_lib

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\tensorflow_datasets\core\download\downloader.py in <module>()
     31 import promise
     32 import requests
---> 33 from requests.utils import extract_zipped_paths
     34 from six.moves import urllib
     35 import tensorflow as tf

ImportError: cannot import name 'extract_zipped_paths'

2 个答案:

答案 0 :(得分:0)

删除所有现有的请求版本。并专门安装pip install requests==2.22.0

答案 1 :(得分:0)

您需要将请求库的版本降级到2.21.0

pip install requests==2.21.0

我使用tensorflow的'2.0.0-beta1'版本时遇到了完全相同的问题,并且让我pip安装了tensorflow_datasets,这导致了您提到的错误。

我注意到在安装tensorflow_datasets时,requests模块已更新到最新版本2.22.0,尽管该函数在request.utils子模块中定义,但似乎无法导入“ extract_zipped_pa​​ths”。在这里:

https://2.python-requests.org/en/master/_modules/requests/utils/

此外,在没有TF的情况下,请求模块似乎可以正常运行。我不知道问题出在哪里,但是将请求模块降级到2.21.0可以正常工作。

摘要:

tf.__version__ == '2.0.0-beta1'

pip install tensorflow_datasets 

pip install requests==2.21.0