无法正确安装tensorflow

bfr*_*frt 6 python installation pip virtualenv tensorflow

系统信息

\n
    \n
  • Windows10 64位
  • \n
  • Python 版本 3.8
  • \n
  • 尝试使用 conda 和 pip 在 vi​​rtualenv 中安装
  • \n
  • CUDA/cuDNN 版本:9.2
  • \n
  • GPU型号和显存:NVIDIA GeForce GTX 950M
  • \n
\n

问题\n我创建了一个虚拟环境,并开始安装必要的软件包。当我尝试运行使用tensorflow的脚本时,它无法导入它。\n搜索此内容后,我尝试将其导入到jupyter笔记本中,但它不起作用。\n然后,我尝试将其添加到我的代码中但它也不起作用:\ ntf.compat.v1.enable_eager_execution(\ nconfig = None,device_policy = None,execution_mode = None \ n)\ n我尝试先使用 conda 然后使用 pip 在该环境中安装tensorflow。

\n

执行的命令/步骤的顺序

\n

- 运行脚本:

\n
d:\\software\\anaconda_envs\\sweaver\\avgn_paper-vizmerge\\avgn\\utils\\json.py:64: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\\\Software\\\\Anaconda_envs\\\\sweaver\\\\avgn_paper-vizmerge\\\\data\\\\processed\\\\sociable_weaver_damelio\\\\2020-08-21_09-35-13\\\\JSON\\\\2018-10-19_09-00-00-000001.JSON' mode='r' encoding='cp1252'>\n  return json.load(open(json_loc), object_pairs_hook=OrderedDict)\nResourceWarning: Enable tracemalloc to get the object allocation traceback\nHBox(children=(FloatProgress(value=0.0, description='loading json', max=1.0, style=ProgressStyle(description_w\xe2\x80\xa6\n[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.\n\n[Parallel(n_jobs=-1)]: Done   1 out of   1 | elapsed:    3.0s finished\nHBox(children=(FloatProgress(value=0.0, description='getting unique individuals', max=1.0, style=ProgressStyle\xe2\x80\xa6\n---------------------------------------------------------------------------\nModuleNotFoundError                       Traceback (most recent call last)\n<ipython-input-43-e50f361ab3a6> in <module>\n      1 # create a dataset object\n----> 2 dataset = DataSet(DATASET_ID, hparams = hparams)\n\nd:\\software\\anaconda_envs\\sweaver\\avgn_paper-vizmerge\\avgn\\dataset.py in __init__(self, DATASET_ID, hparams, default_rate, build_mel_matrix)\n     43 \n     44         if build_mel_matrix:\n---> 45             self.build_mel_matrix()\n     46 \n     47     def _get_wav_json_files(self):\n\nd:\\software\\anaconda_envs\\sweaver\\avgn_paper-vizmerge\\avgn\\dataset.py in build_mel_matrix(self, rate)\n     66         if rate is None:\n     67             rate = self.sample_json["samplerate_hz"]\n---> 68         self.mel_matrix = prepare_mel_matrix(self.hparams, rate)\n     69 \n     70     def _get_unique_individuals(self):\n\nd:\\software\\anaconda_envs\\sweaver\\avgn_paper-vizmerge\\avgn\\signalprocessing\\filtering.py in prepare_mel_matrix(hparams, rate, return_numpy, GPU_backend)\n     71             os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"  # see issue #152\n     72             os.environ["CUDA_VISIBLE_DEVICES"] = ""\n---> 73         import tensorflow as tf\n     74 \n     75     tf.compat.v1.enable_eager_execution(\n\nModuleNotFoundError: No module named 'tensorflow'\n
Run Code Online (Sandbox Code Playgroud)\n

- 在jupyter笔记本中导入

\n
import sys\n!conda install --yes --prefix {sys.prefix} tensorflow\n\nUnsatisfiableError: The following specifications were found to be incompatible with the existing python installation in your environment:\nSpecifications:\n- tensorflow -> python[version'3.5.*|3.6.*|3.7.*'\nYour python: python=3.8\n\nThe following specifications were found to be incompatible with your CUDA driver:\n- feature:/win-64::__cuda==9.2=0\nYour installed CUDA driver is: 9.2\n
Run Code Online (Sandbox Code Playgroud)\n

-当我尝试通过 conda 安装它时:

\n
(D:\\Software\\Anaconda_envs\\sweaver) D:\\Software\\Anaconda_envs\\sweaver>conda install tensorflow\nCollecting package metadata (current_repodata.json): done\nSolving environment: failed with initial frozen solve. Retrying with flexible solve.\nSolving environment: failed with repodata from current_repodata.json, will retry with next repodata source.\nCollecting package metadata (repodata.json): done\nSolving environment: failed with initial frozen solve. Retrying with flexible solve.\nSolving environment: -\nFound conflicts! Looking for incompatible packages.\nThis can take several minutes.  Press CTRL-C to abort.\nExamining @/win-64::__cuda==9.2=0:  67%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x8b                | 2/3 [00:00<00:00, 18.17it/s]|Examining conflict for __cuda:  67%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x8e                 | 2/3 [00:00<00:00,  3.77it/s]|failed\n\nUnsatisfiableError: The following specifications were found\nto be incompatible with the existing python installation in your environment:\n\nSpecifications:\n\n  - tensorflow -> python[version='3.5.*|3.6.*|3.7.*']\n\nYour python: python=3.8\n\nIf python is on the left-most side of the chain, that's the version you've asked for.\nWhen python appears to the right, that indicates that the thing on the left is somehow\nnot available for the python version you are constrained to. Note that conda will not\nchange your python version to a different minor version unless you explicitly specify\nthat.\n\nThe following specifications were found to be incompatible with your system:\n\n  - feature:/win-64::__cuda==9.2=0\n  - feature:|@/win-64::__cuda==9.2=0\n\nYour installed version is: 9.2\n
Run Code Online (Sandbox Code Playgroud)\n

-当我尝试使用 pip 安装它时:

\n
(D:\\Software\\Anaconda_envs\\sweaver) D:\\Software\\Anaconda_envs\\sweaver>pip install tensorflow\nCollecting tensorflow\n  Using cached tensorflow-2.3.0-cp38-cp38-win_amd64.whl (342.5 MB)\nRequirement already satisfied: wrapt>=1.11.1 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (1.11.2)\nCollecting keras-preprocessing<1.2,>=1.1.1\n  Using cached Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)\nCollecting tensorboard<3,>=2.3.0\n  Using cached tensorboard-2.3.0-py3-none-any.whl (6.8 MB)\nRequirement already satisfied: grpcio>=1.8.6 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (1.31.0)\nCollecting numpy<1.19.0,>=1.16.0\n  Using cached numpy-1.18.5-cp38-cp38-win_amd64.whl (12.8 MB)\nCollecting opt-einsum>=2.3.2\n  Using cached opt_einsum-3.3.0-py3-none-any.whl (65 kB)\nRequirement already satisfied: absl-py>=0.7.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (0.10.0)\nRequirement already satisfied: wheel>=0.26 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (0.34.2)\nCollecting scipy==1.4.1\n  Using cached scipy-1.4.1-cp38-cp38-win_amd64.whl (31.0 MB)\nCollecting astunparse==1.6.3\n  Using cached astunparse-1.6.3-py2.py3-none-any.whl (12 kB)\nRequirement already satisfied: h5py<2.11.0,>=2.10.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (2.10.0)\nCollecting protobuf>=3.9.2\n  Using cached protobuf-3.13.0-py2.py3-none-any.whl (438 kB)\nCollecting google-pasta>=0.1.8\n  Using cached google_pasta-0.2.0-py3-none-any.whl (57 kB)\nRequirement already satisfied: tensorflow-estimator<2.4.0,>=2.3.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (2.3.0)\nRequirement already satisfied: gast==0.3.3 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (0.3.3)\nRequirement already satisfied: six>=1.12.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorflow) (1.15.0)\nProcessing c:\\users\\bf\\appdata\\local\\pip\\cache\\wheels\\a0\\16\\9c\\5473df82468f958445479c59e784896fa24f4a5fc024b0f501\\termcolor-1.1.0-py3-none-any.whl\nRequirement already satisfied: werkzeug>=0.11.15 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorboard<3,>=2.3.0->tensorflow) (1.0.1)\nCollecting markdown>=2.6.8\n  Using cached Markdown-3.2.2-py3-none-any.whl (88 kB)\nCollecting google-auth-oauthlib<0.5,>=0.4.1\n  Using cached google_auth_oauthlib-0.4.1-py2.py3-none-any.whl (18 kB)\nRequirement already satisfied: setuptools>=41.0.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorboard<3,>=2.3.0->tensorflow) (49.6.0.post20200814)\nCollecting tensorboard-plugin-wit>=1.6.0\n  Using cached tensorboard_plugin_wit-1.7.0-py3-none-any.whl (779 kB)\nRequirement already satisfied: requests<3,>=2.21.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorboard<3,>=2.3.0->tensorflow) (2.24.0)\nRequirement already satisfied: google-auth<2,>=1.6.3 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from tensorboard<3,>=2.3.0->tensorflow) (1.20.1)\nCollecting requests-oauthlib>=0.7.0\n  Using cached requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)\nRequirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<3,>=2.3.0->tensorflow) (1.25.10)\nRequirement already satisfied: certifi>=2017.4.17 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<3,>=2.3.0->tensorflow) (2020.6.20)\nRequirement already satisfied: chardet<4,>=3.0.2 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<3,>=2.3.0->tensorflow) (3.0.4)\nRequirement already satisfied: idna<3,>=2.5 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from requests<3,>=2.21.0->tensorboard<3,>=2.3.0->tensorflow) (2.10)\nRequirement already satisfied: pyasn1-modules>=0.2.1 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from google-auth<2,>=1.6.3->tensorboard<3,>=2.3.0->tensorflow) (0.2.8)\nRequirement already satisfied: rsa<5,>=3.1.4; python_version >= "3.5" in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from google-auth<2,>=1.6.3->tensorboard<3,>=2.3.0->tensorflow) (4.5)\nRequirement already satisfied: cachetools<5.0,>=2.0.0 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from google-auth<2,>=1.6.3->tensorboard<3,>=2.3.0->tensorflow) (4.1.1)\nCollecting oauthlib>=3.0.0\n  Using cached oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)\nRequirement already satisfied: pyasn1<0.5.0,>=0.4.6 in d:\\software\\anaconda_envs\\sweaver\\lib\\site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<3,>=2.3.0->tensorflow) (0.4.8)\nERROR: Error while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new\nTraceback (most recent call last):\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 3021, in _dep_map\n    return self.__dep_map\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 2815, in __getattr__\n    raise AttributeError(attr)\nAttributeError: _DistInfoDistribution__dep_map\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 3012, in _parsed_pkg_info\n    return self._pkg_info\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 2815, in __getattr__\n    raise AttributeError(attr)\nAttributeError: _pkg_info\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_internal\\commands\\install.py", line 535, in _determine_conflicts\n    return check_install_conflicts(to_install)\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_internal\\operations\\check.py", line 108, in check_install_conflicts\n    package_set, _ = create_package_set_from_installed()\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_internal\\operations\\check.py", line 50, in create_package_set_from_installed\n    package_set[name] = PackageDetails(dist.version, dist.requires())\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 2736, in requires\n    dm = self._dep_map\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 3023, in _dep_map\n    self.__dep_map = self._compute_dependencies()\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 3032, in _compute_dependencies\n    for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 3014, in _parsed_pkg_info\n    metadata = self.get_metadata(self.PKG_INFO)\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 1420, in get_metadata\n    value = self._get(path)\n  File "D:\\Software\\Anaconda_envs\\sweaver\\lib\\site-packages\\pip\\_vendor\\pkg_resources\\__init__.py", line 1616, in _get\n    with open(path, 'rb') as stream:\nFileNotFoundError: [Errno 2] No such file or directory: 'd:\\\\software\\\\anaconda_envs\\\\sweaver\\\\lib\\\\site-packages\\\\numpy-1.19.1.dist-info\\\\METADATA'\nInstalling collected packages: numpy, keras-preprocessing, protobuf, markdown, oauthlib, requests-oauthlib, google-auth-oauthlib, tensorboard-plugin-wit, tensorboard, opt-einsum, scipy, astunparse, google-pasta, termcolor, tensorflow\n  Attempting uninstall: numpy\n    Found existing installation: numpy 1.19.1\nERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'd:\\\\software\\\\anaconda_envs\\\\sweaver\\\\lib\\\\site-packages\\\\numpy-1.19.1.dist-info\\\\RECORD'\n
Run Code Online (Sandbox Code Playgroud)\n

也许是tensorflow和numpy之间的兼容性问题?但文件 'd:\\software\\anaconda_envs\\sweaver\\lib\\site-packages\\numpy-1.19.1.dist-info\\RECORD' 实际上不存在。\n我在我的包中搜索并有一个numpy的文件夹,numpy-1.18.5.dist-info和numpy-1.19.1.dist-info,但最后一个里面只有两个文件:LICENSES_bundled.txt和REQUESTED。

\n

然后,我删除了文件夹 numpy-1.19.1dist-info 并使用 --user 通过命令行安装了tensorflow以允许安装,但它安装在其他地方。\n所以,我使用:

\n
import sys\nsys.path.append()\n
Run Code Online (Sandbox Code Playgroud)\n

在tensorflow的每个py文件中但仍然不起作用。另外其中一个文件(pywrap_tensorflow_internal.py)是空的,这表明安装时出现了一些问题。

\n

希望你能帮我。

\n

小智 0

有时conda会出现问题。我有同样的问题。你所要做的就是再次创建一个新环境并尝试将你的Python版本降级到3.7