【问题标题】:"pip install json" fails on Ubuntu“pip install json”在 Ubuntu 上失败
【发布时间】:2017-05-18 21:33:26
【问题描述】:

无法安装 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/

【问题讨论】:

  • raise RuntimeError("Package 'json' must not be downloaded from pypi") 有什么不清楚的地方?
  • 如果发生这种情况,它应该说“不需要包装”。如果我被告知我需要安装一个包,而安装程序说我不能从 X 下载它,那么一个合理的假设是我需要从其他地方下载它。但是在哪里?

标签: python-2.7 pip ubuntu-16.04


【解决方案1】:

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

【讨论】:

  • 这是一个内置模块,您不能使用pip 安装它。如果你使用 ubuntu,比如上面的用户,可能你有 python2 但你没有 json;看我的回答。
【解决方案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,它会工作的!

【讨论】:

  • 非常感谢@MichielB 的洞察力
猜你喜欢
  • 2019-02-11
  • 2022-01-16
  • 1970-01-01
  • 2021-05-13
  • 2016-12-08
  • 2021-06-28
  • 1970-01-01
  • 2015-12-22
  • 2012-09-24
相关资源
最近更新 更多