安装 Tensorflow 时出现 CondaVerificationError

cac*_*tie 5 python installation conda tensorflow

我在 64 位 Win10 上安装 Tensorflow 时遇到 CondaVerificationError。

CondaVerificationError: The package for tensorflow-estimator located at C:\Users\viviennejia.zhong\AppData\Local\Continuum\anaconda3\pkgs\tensorflow-estimator-1.13.0-py37h39e3cac_0
appears to be corrupted. The path 'Lib/site-packages/tensorflow_estimator/python/estimator/canned/linear_optimizer/python/utils/__pycache__/sharded_mutable_dense_hashtable.cpython-37.pyc'
specified in the package manifest cannot be found.

ClobberError: This transaction has incompatible packages due to a shared path.
packages: conda-forge::tensorboard-1.13.1-py37_0, conda-forge::tensorflow-base-1.13.1-py37_7
path: 'scripts/tensorboard-script.py'

ClobberError: This transaction has incompatible packages due to a shared path.
packages: conda-forge::tensorboard-1.13.1-py37_0, conda-forge::tensorflow-base-1.13.1-py37_7
path: 'scripts/tensorboard.exe'
Run Code Online (Sandbox Code Playgroud)

在我看到的一些帖子中conda clean --all可以提供帮助。运行这个,我得到了

FileNotFoundError: [WinError 3] 'C:\\Users\\xxxx\\AppData\\Local\\Continuum\\anaconda3\\pkgs\\tensorflow-base-2.0.0-mkl_py37hd1d5974_0\\Lib\\site-packages\\tensorflow-2.0.0.data\\purelib\\tensorflow_core\\include\\tensorflow_core\\core\\common_runtime\\isolate_placer_inspection_required_ops_pass.h'
Run Code Online (Sandbox Code Playgroud)

我是 conda 新手,非常感谢您帮助解决这个问题。

小智 1

在这里提供解决方案(答案部分),即使它出现在评论部分中,也是为了社区的利益。

通过 pip 安装 Tensorflow 已解决问题

pip install tensorflow (install latest version)
Run Code Online (Sandbox Code Playgroud)

或者

pip install tensorflow==2.0 (for older version)
Run Code Online (Sandbox Code Playgroud)

除了上面的方法之外,还有一个推荐的方法是创建一个Virtual EnvironmentinAnaconda并安装Tensorflowin that Virtual Environment,这在大多数情况下都有效。

使用虚拟环境具有以下优点

  • 我们可以维护多个版本,Tensorflow每个Virtual Environments版本都Virtual Environment包含version类似的版本1.14, 1.15, 2.0, 2.1, 2.2,etc..
  • 我们可以在每个中使用不同的Python Versions( )2.x, 3.6, 3.7Virtual Environment
  • 如果我们想要修改source code任何 Tensorflow API,我们可以在虚拟环境中进行,而不会影响其在其他Virtual Environments.

对于不同的操作系统,创建新的虚拟环境并安装的步骤Tensorflow如下Anaconda

# Create a New Virtual Environment
conda create --name TF_2_VE

# When conda asks you to proceed, type y:
proceed ([y]/n)?

# Activate the Virtual Environment. Conda Version > 4.6 
conda activate TF_2_VE

# Activating Virtual Environment, Conda Version < 4.6 and Windows OS
activate TF_2_VE

# Activating Virtual Environment, Conda Version < 4.6 and Linux and Mac OS
source activate TF_2_VE


# Install the TF Version you need
conda install tensorflow
Run Code Online (Sandbox Code Playgroud)

上面的命令将安装Latest Versionof Tensorflow2.2截至目前)。如果您想要像这样的旧版本2.0,您可以将上述命令组的最后一步替换为

conda install tensorflow==2.0