解决pip 问题AttributeError: '_NamespacePath' object has no attribute 'sort'

在虚拟环境python3.6下执行如下指令:

(pyDense3.6) Xdn@xwfx:~/.conda/envs/pyDense3.6$ pip install  chumpy

出现错误:

Traceback (most recent call last):

  File "/home/Xdn/.conda/envs/pyDense3.6/bin/pip", line 4, in

    import pip

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/__init__.py", line 26, in

    from pip.utils import get_installed_distributions, get_prog

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in

    from pip._vendor import pkg_resources

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3018, in

    @_call_aside

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3004, in _call_aside

    f(*args, **kwargs)

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3046, in _initialize_master_working_set

    dist.activate(replace=False)

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2578, in activate

    declare_namespace(pkg)

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2152, in declare_namespace

    _handle_ns(packageName, path_item)

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2092, in _handle_ns

    _rebuild_mod_path(path, packageName, module)

  File "/home/Xdn/.conda/envs/pyDense3.6/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2121, in _rebuild_mod_path

    orig_path.sort(key=position_in_sys_path)

AttributeError: '_NamespacePath' object has no attribute 'sort'

问题解决:

参考:https://stackoverflow.com/questions/47955397/pip3-error-namespacepath-object-has-no-attribute-sort

简单来说就是:在__init__.py中第2021行orig_path.sort时没有sort属性,参考如上解答,将2021-2022行的代码换为如下:

#orig_path.sort(key=position_in_sys_path)

#module.__path__[:] = [_normalize_cached(p) for p in orig_path]

orig_path_t = list(orig_path)orig_path_t.sort(key=position_in_sys_path)

module.__path__[:] = [_normalize_cached(p) for p in orig_path_t]

该方法解决了我的问题,网上也有通过更新PIP和setuptools解决该问题的,我也尝试了这些方法但是对我的问题没有生效。

修改后运行结果:

(pyDense3.6) Xdn@xwfx:~/.conda/envs/pyDense3.6$ pip install chumpy

Collecting chumpy

  Cache entry deserialization failed, entry ignored

  Using cached https://files.pythonhosted.org/packages/87/81/d7a94ad0ff556b9dd1bf27b84c0b255d9ba22ad5952f20088dafacd9292e/chumpy-0.69.tar.gz

Requirement already satisfied: numpy>=1.8.1 in /home/Xdn/.local/lib/python3.6/site-packages (from chumpy)

Requirement already satisfied: scipy>=0.13.0 in ./lib/python3.6/site-packages (from chumpy)

Requirement already satisfied: six>=1.11.0 in /home/Xdn/.local/lib/python3.6/site-packages (from chumpy)

Building wheels for collected packages: chumpy

  Running setup.py bdist_wheel for chumpy ... done

  Stored in directory: /home/Xdn/.cache/pip/wheels/df/11/36/2758327d759bad62803f3f9190db1c063e52a0358cecd33e94

Successfully built chumpy

Installing collected packages: chumpy

Successfully installed chumpy-0.69

你可能感兴趣的:(解决pip 问题AttributeError: '_NamespacePath' object has no attribute 'sort')