“pip install json”在Ubuntu上失败了

问题描述 投票:24回答:2

无法安装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/
python-2.7 pip ubuntu-16.04
2个回答
61
投票

json是一个内置模块,你不需要用pip安装它。


2
投票

虽然json确实是一个内置模块,但我发现在安装了python-minimal的Ubuntu系统上,你有python,但你不能做import json。然后我明白你会尝试使用pip安装模块!

如果你有python-minimal你会得到一个python版本,模块少于你自己通常自己编译python的版本,而你将缺少的一个模块是json模块。解决方案是安装一个名为libpython2.7-stdlib的附加软件包来安装所有“默认”python库。

sudo apt install libpython2.7-stdlib

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

© www.soinside.com 2019 - 2024. All rights reserved.