无法安装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/
json
是一个内置模块,你不需要用pip
安装它。
虽然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
它会工作!