3

我刚刚克隆了一个carnd-term1-gpu使用 tensorflow 版本“0.12.1”的 tensorflow 和 gpu 工作的 miniconda 环境。该环境安装了许多其他 python 包。我想升级到最新版本的 tensorflow,所以我基于tensorflow Ubuntu做了以下操作:

1)将现有的工作环境克隆为tflow

conda create --name tflow --clone carnd-term1-gpu

这成功地完成了。

2) 源激活 tflow 并使用 pip 安装

source activate tflow
(tflow) xx@pc:~$ pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl

现在我尝试运行旧环境,假设它不应该被改变。

source activate carnd-term1-gpu
ipython

然后从 ipython 提示符输入import numpy as np并获得以下信息:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-4ee716103900> in <module>()
----> 1 import numpy as np

/home/ai/miniconda3/envs/carnd-term1-gpu/lib/python3.5/site-packages/numpy/__init__.py in <module>()
    140         return loader(*packages, **options)
    141 
--> 142     from . import add_newdocs
    143     __all__ = ['add_newdocs',
    144                'ModuleDeprecationWarning',

/home/ai/miniconda3/envs/carnd-term1-gpu/lib/python3.5/site-packages/numpy/add_newdocs.py in <module>()
     11 from __future__ import division, absolute_import, print_function
     12 
---> 13 from numpy.lib import add_newdoc
     14 
     15 ###############################################################################

/home/ai/miniconda3/envs/carnd-term1-gpu/lib/python3.5/site-packages/numpy/lib/__init__.py in <module>()
      6 from numpy.version import version as __version__
      7 
----> 8 from .type_check import *
      9 from .index_tricks import *
     10 from .function_base import *

/home/ai/miniconda3/envs/carnd-term1-gpu/lib/python3.5/site-packages/numpy/lib/type_check.py in <module>()
      9            'common_type']
     10 
---> 11 import numpy.core.numeric as _nx
     12 from numpy.core.numeric import asarray, asanyarray, array, isnan, \
     13                 obj2sctype, zeros

/home/ai/miniconda3/envs/carnd-term1-gpu/lib/python3.5/site-packages/numpy/core/__init__.py in <module>()
     51 from . import shape_base
     52 from .shape_base import *
---> 53 from . import einsumfunc
     54 from .einsumfunc import *
     55 del nt

ImportError: cannot import name 'einsumfunc'

我以为我是通过克隆一个单独的环境并仅更改该环境来保护我的,但是似乎在一个环境中的安装改变了在另一个环境中的行为。正是我以为我要避免的!出了什么问题,我该如何解决?到目前为止,新环境似乎运行良好。

我检查了两种环境中的文件日期。环境中的carnd-term1-gpu文件日期与我在tflow环境中进行升级的同一天。关于如何发生的任何想法?

我尝试将丢失的文件添加einsumfunc.py到我的carnd-term1-gpu环境中并再次启动 Ipython。这次我做import numpy as np了一个不同的文件无法导入。所以看起来我的carnd-term1-gpu环境已损坏。

比较conda list每个环境并仅查看numpy,我看到以下内容: 对于tflow 环境:

numpy                     1.11.3                    <pip>
numpy                     1.12.1                    <pip>
numpy                     1.11.3          py35_blas_openblas_200  [blas_openblas]  conda-forge

对于carnd-term1-gpu环境:

numpy                     1.11.3                    <pip>
numpy                     1.11.3          py35_blas_openblas_200  [blas_openblas]  conda-forge

然后我查看了使用conda list --revisions. 两种环境都只显示rev 0. 同样查看conda-meta/history仅显示 1 月 13carnd-term1-gpu日和 5 月 9 日的原始创建日期tflow。所以这个版本的pip的组合:

pip                       9.0.1                    py35_0    conda-forge

结合这个轮子:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-linux_x86_64.whl

不知何故破坏了环境carnd-term1-gpu。这似乎是一个错误,或者我以某种方式从 tensorflow 站点获得了一个损坏的轮子?如果是后者,它怎么会破坏与安装环境不同的环境?注意 pip 的版本在两种环境中都是相同的。

我执行了以下操作来调查在安装之日哪些文件发生了变化。

find /home/ai/miniconda3/envs/carnd-term1-gpu/  -type f -newermt 2017-05-09 -ls | wc -l

这表明创建/修改了 669 个文件。其中大部分都在/site-packages/numpy/,但six.py, pyparsing.py, /setuptools/, /pkg_resources/, easy_install.py,/werkzeug/也受到影响。

conda --version是 4.2.12

我尝试了以下方法来让我的旧环境再次运行。

conda env export > environment.yml
conda env create -f environment.yml -n sdc-gpu

这导致了以下错误:

Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
  File "/home/ai/miniconda3/envs/sdc-gpu/lib/python3.5/site-packages/pip/req/req_install.py", line 387, in setup_py
    import setuptools  # noqa
  File "/home/ai/miniconda3/envs/sdc-gpu/lib/python3.5/site-packages/setuptools/__init__.py", line 12, in <module>
    import setuptools.version
  File "/home/ai/miniconda3/envs/sdc-gpu/lib/python3.5/site-packages/setuptools/version.py", line 1, in <module>
    import pkg_resources
  File "/home/ai/miniconda3/envs/sdc-gpu/lib/python3.5/site-packages/pkg_resources/__init__.py", line 70, in <module>
    import packaging.version
ImportError: No module named 'packaging'

CondaValueError: Value error: pip returned an error.
4

1 回答 1

1

我刚刚从continuum得到以下信息;“为了防止这种情况发生,您必须在--copy克隆操作中使用标志。conda 设计的核心是广泛使用硬链接。这个确切的问题是最大的陷阱之一。”

因此,如果我在第一次克隆环境时执行以下操作,则可以避免损坏旧环境:

conda create --name tflow --copy --clone carnd-term1-gpu

该选项 --copy Install all packages using copies instead of hard- or soft-link‐ing将阻止 pip 能够覆盖文件。

关于这个问题以及未来如何解决的一些正在进行的讨论在这里:conda pip break

我唯一的恢复选择是重新安装每个损坏的包。将 pip 与 conda 一起使用时要小心...

于 2017-05-11T18:48:44.243 回答