"pip install json"在Ubuntu上失败了

Eug*_*nio 28 pip python-2.7 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/
Run Code Online (Sandbox Code Playgroud)

ale*_*cxe 69

json是一个内置模块,您不需要安装它pip.

  • 这是一个内置模块,您不能**通过pip安装它。如果您以上述用户身份使用ubuntu,则可能是您确实拥有python2但没有json;看我的答案。 (2认同)

Mic*_*elB 12

虽然它确实json是一个内置模块,但我还发现在python-minimal安装了 Ubuntu 的系统上,您python确实有但不能执行import json. 然后我知道您会尝试使用 pip 安装模块!

如果你有,python-minimal你会得到一个模块比你通常自己编译 python 时更少的模块,并且你将缺少的json模块之一是模块。解决方案是安装一个名为 的附加包libpython2.7-stdlib,以安装所有“默认”python 库。

sudo apt install libpython2.7-stdlib
Run Code Online (Sandbox Code Playgroud)

然后你可以import json在 python 中做,它会工作!