简体   繁体   English

无法正确安装 tensorflow

[英]Can't install tensorflow properly

System information系统信息

  • Windows10 64bit视窗10 64位
  • Python version 3.8 Python 3.8 版
  • Tryed to install in a virtualenv using conda and pip尝试使用 conda 和 pip 在 vi​​rtualenv 中安装
  • CUDA/cuDNN version: 9.2 CUDA/cuDNN 版本:9.2
  • GPU model and memory: NVIDIA GeForce GTX 950M GPU型号和内存:NVIDIA GeForce GTX 950M

Problem I created a virtual environment and there I started to install necessary packages.问题我创建了一个虚拟环境,然后我开始安装必要的包。 When I tried to run a script that used tensorflow, it could not imported it.当我尝试运行使用 tensorflow 的脚本时,它无法导入它。 After searching for this, I tried to import it in jupyter notebook, but it didn't work.搜索后,我尝试将其导入到 jupyter notebook 中,但没有成功。 Then, I tried to add this to my code but it didn't work either: tf.compat.v1.enable_eager_execution( config=None, device_policy=None, execution_mode=None ) I tried to install tensorflow in that environment using first conda and then pip.然后,我尝试将其添加到我的代码中,但它也不起作用: tf.compat.v1.enable_eager_execution( config=None, device_policy=None, execution_mode=None ) 我尝试使用第一个 conda 在该环境中安装 tensorflow 和然后点。

Sequence of commands / steps executed执行的命令/步骤的顺序

-Running the script: - 运行脚本:

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'>
  return json.load(open(json_loc), object_pairs_hook=OrderedDict)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
HBox(children=(FloatProgress(value=0.0, description='loading json', max=1.0, style=ProgressStyle(description_w…
[Parallel(n_jobs=-1)]: Using backend LokyBackend with 8 concurrent workers.

[Parallel(n_jobs=-1)]: Done   1 out of   1 | elapsed:    3.0s finished
HBox(children=(FloatProgress(value=0.0, description='getting unique individuals', max=1.0, style=ProgressStyle…
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-43-e50f361ab3a6> in <module>
      1 # create a dataset object
----> 2 dataset = DataSet(DATASET_ID, hparams = hparams)

d:\software\anaconda_envs\sweaver\avgn_paper-vizmerge\avgn\dataset.py in __init__(self, DATASET_ID, hparams, default_rate, build_mel_matrix)
     43 
     44         if build_mel_matrix:
---> 45             self.build_mel_matrix()
     46 
     47     def _get_wav_json_files(self):

d:\software\anaconda_envs\sweaver\avgn_paper-vizmerge\avgn\dataset.py in build_mel_matrix(self, rate)
     66         if rate is None:
     67             rate = self.sample_json["samplerate_hz"]
---> 68         self.mel_matrix = prepare_mel_matrix(self.hparams, rate)
     69 
     70     def _get_unique_individuals(self):

d:\software\anaconda_envs\sweaver\avgn_paper-vizmerge\avgn\signalprocessing\filtering.py in prepare_mel_matrix(hparams, rate, return_numpy, GPU_backend)
     71             os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"  # see issue #152
     72             os.environ["CUDA_VISIBLE_DEVICES"] = ""
---> 73         import tensorflow as tf
     74 
     75     tf.compat.v1.enable_eager_execution(

ModuleNotFoundError: No module named 'tensorflow'

-Import it in jupyter notebook - 将其导入 jupyter notebook

import sys
!conda install --yes --prefix {sys.prefix} tensorflow

UnsatisfiableError: The following specifications were found to be incompatible with the existing python installation in your environment:
Specifications:
- tensorflow -> python[version'3.5.*|3.6.*|3.7.*'
Your python: python=3.8

The following specifications were found to be incompatible with your CUDA driver:
- feature:/win-64::__cuda==9.2=0
Your installed CUDA driver is: 9.2

-When I tried to install it through conda: - 当我尝试通过 conda 安装它时:

(D:\Software\Anaconda_envs\sweaver) D:\Software\Anaconda_envs\sweaver>conda install tensorflow
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
Examining @/win-64::__cuda==9.2=0:  67%|████████████████████████████████▋                | 2/3 [00:00<00:00, 18.17it/s]|Examining conflict for __cuda:  67%|███████████████████████████████████▎                 | 2/3 [00:00<00:00,  3.77it/s]|failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - tensorflow -> python[version='3.5.*|3.6.*|3.7.*']

Your python: python=3.8

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

The following specifications were found to be incompatible with your system:

  - feature:/win-64::__cuda==9.2=0
  - feature:|@/win-64::__cuda==9.2=0

Your installed version is: 9.2

-When I tried to install it using pip: -当我尝试使用 pip 安装它时:

(D:\Software\Anaconda_envs\sweaver) D:\Software\Anaconda_envs\sweaver>pip install tensorflow
Collecting tensorflow
  Using cached tensorflow-2.3.0-cp38-cp38-win_amd64.whl (342.5 MB)
Requirement already satisfied: wrapt>=1.11.1 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (1.11.2)
Collecting keras-preprocessing<1.2,>=1.1.1
  Using cached Keras_Preprocessing-1.1.2-py2.py3-none-any.whl (42 kB)
Collecting tensorboard<3,>=2.3.0
  Using cached tensorboard-2.3.0-py3-none-any.whl (6.8 MB)
Requirement already satisfied: grpcio>=1.8.6 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (1.31.0)
Collecting numpy<1.19.0,>=1.16.0
  Using cached numpy-1.18.5-cp38-cp38-win_amd64.whl (12.8 MB)
Collecting opt-einsum>=2.3.2
  Using cached opt_einsum-3.3.0-py3-none-any.whl (65 kB)
Requirement already satisfied: absl-py>=0.7.0 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (0.10.0)
Requirement already satisfied: wheel>=0.26 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (0.34.2)
Collecting scipy==1.4.1
  Using cached scipy-1.4.1-cp38-cp38-win_amd64.whl (31.0 MB)
Collecting astunparse==1.6.3
  Using cached astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Requirement already satisfied: h5py<2.11.0,>=2.10.0 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (2.10.0)
Collecting protobuf>=3.9.2
  Using cached protobuf-3.13.0-py2.py3-none-any.whl (438 kB)
Collecting google-pasta>=0.1.8
  Using cached google_pasta-0.2.0-py3-none-any.whl (57 kB)
Requirement already satisfied: tensorflow-estimator<2.4.0,>=2.3.0 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (2.3.0)
Requirement already satisfied: gast==0.3.3 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (0.3.3)
Requirement already satisfied: six>=1.12.0 in d:\software\anaconda_envs\sweaver\lib\site-packages (from tensorflow) (1.15.0)
Processing c:\users\bf\appdata\local\pip\cache\wheels\a0\16\9c\5473df82468f958445479c59e784896fa24f4a5fc024b0f501\termcolor-1.1.0-py3-none-any.whl
Requirement 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)
Collecting markdown>=2.6.8
  Using cached Markdown-3.2.2-py3-none-any.whl (88 kB)
Collecting google-auth-oauthlib<0.5,>=0.4.1
  Using cached google_auth_oauthlib-0.4.1-py2.py3-none-any.whl (18 kB)
Requirement 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)
Collecting tensorboard-plugin-wit>=1.6.0
  Using cached tensorboard_plugin_wit-1.7.0-py3-none-any.whl (779 kB)
Requirement 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)
Requirement 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)
Collecting requests-oauthlib>=0.7.0
  Using cached requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Requirement 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)
Requirement 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)
Requirement 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)
Requirement 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)
Requirement 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)
Requirement 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)
Requirement 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)
Collecting oauthlib>=3.0.0
  Using cached oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
Requirement 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)
ERROR: Error while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new
Traceback (most recent call last):
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3021, in _dep_map
    return self.__dep_map
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3012, in _parsed_pkg_info
    return self._pkg_info
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2815, in __getattr__
    raise AttributeError(attr)
AttributeError: _pkg_info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_internal\commands\install.py", line 535, in _determine_conflicts
    return check_install_conflicts(to_install)
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_internal\operations\check.py", line 108, in check_install_conflicts
    package_set, _ = create_package_set_from_installed()
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_internal\operations\check.py", line 50, in create_package_set_from_installed
    package_set[name] = PackageDetails(dist.version, dist.requires())
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 2736, in requires
    dm = self._dep_map
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3023, in _dep_map
    self.__dep_map = self._compute_dependencies()
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3032, in _compute_dependencies
    for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 3014, in _parsed_pkg_info
    metadata = self.get_metadata(self.PKG_INFO)
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1420, in get_metadata
    value = self._get(path)
  File "D:\Software\Anaconda_envs\sweaver\lib\site-packages\pip\_vendor\pkg_resources\__init__.py", line 1616, in _get
    with open(path, 'rb') as stream:
FileNotFoundError: [Errno 2] No such file or directory: 'd:\\software\\anaconda_envs\\sweaver\\lib\\site-packages\\numpy-1.19.1.dist-info\\METADATA'
Installing 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
  Attempting uninstall: numpy
    Found existing installation: numpy 1.19.1
ERROR: 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'

Maybe it's a problem of compatibility between tensorflow and numpy?也许这是tensorflow和numpy之间的兼容性问题? But the file 'd:\\software\\anaconda_envs\\sweaver\\lib\\site-packages\\numpy-1.19.1.dist-info\\RECORD' actually does not exist.但是文件 'd:\\software\\anaconda_envs\\sweaver\\lib\\site-packages\\numpy-1.19.1.dist-info\\RECORD' 实际上并不存在。 I searched in my packages and there is a folder of numpy, numpy-1.18.5.dist-info and numpy-1.19.1.dist-info, but inside the last one, there are only two files: LICENSES_bundled.txt and REQUESTED.我在我的包中搜索,有一个 numpy、numpy-1.18.5.dist-info 和 numpy-1.19.1.dist-info 的文件夹,但在最后一个里面,只有两个文件:LICENSES_bundled.txt 和 REQUESTED .

Then, I deleted the folder numpy-1.19.1dist-info and intalled tensorflow through the command line using --user to allow the installation, but it got installed in other place.然后,我删除了文件夹 numpy-1.19.1dist-info 并使用 --user 通过命令行安装了 tensorflow 以允许安装,但它安装在其他地方。 So, I use:所以,我使用:

import sys
sys.path.append()

in every py file of tensorflow but still didn't work.在 tensorflow 的每个 py 文件中,但仍然无法正常工作。 Also one of the files (pywrap_tensorflow_internal.py) was empty, showing that there was some problem in installation.还有一个文件(pywrap_tensorflow_internal.py)是空的,说明安装有问题。

Hope you can help me.希望您能够帮助我。

Sometimes conda has issues.有时conda有问题。 I had the same problem.我有同样的问题。 All you have to do is create a new environment again and try do downgrade your Python version to 3.7您所要做的就是再次创建一个新环境并尝试将您的 Python 版本降级到 3.7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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