" pip install json"在Ubuntu上失败了

时间:2017-01-04 14:37:28

标签: python-2.7 pip ubuntu-16.04

无法安装json模块。 据我所知,我不应该使用sudo。这是怎么回事?

 pip install json
The directory '/home/snow/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/snow/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting json
  Downloading json-99.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-YkvqVh/json/setup.py", line 2, in <module>
        raise RuntimeError("Package 'json' must not be downloaded from pypi")
    RuntimeError: Package 'json' must not be downloaded from pypi

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-YkvqVh/json/

2 个答案:

答案 0 :(得分:60)

json内置模块,您不需要使用pip进行安装。

答案 1 :(得分:2)

虽然确实是json是一个内置模块,但我还发现,在安装了python-minimal的Ubuntu系统上,您确实拥有python,但不能执行{ {1}}。然后,我了解到您将尝试使用pip安装模块!

如果您拥有import json,则将获得一个版本的python,其模块数量少于通常自己编译python的模块,而您将缺少的模块之一是python-minimal模块。解决方案是安装一个名为json的附加软件包,以安装所有“默认” python库。

libpython2.7-stdlib

然后您就可以在python中进行sudo apt install libpython2.7-stdlib 的操作了!