49

Cannot install the json module. As far as I know I shouldn't use sudo. what's the matter?

 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/
Eugenio
  • 683
  • 1
  • 5
  • 9
  • 2
    What is not clear about `raise RuntimeError("Package 'json' must not be downloaded from pypi")`? – Martijn Pieters Jan 04 '17 at 14:41
  • 10
    It should say something like "package is unnecessary" if that's what's happening. If I'm told I need to install a package, and the installer says I can't download it from X, a reasonable assumption is that I need to download it from somewhere else. But where? – Keith Tyler Feb 14 '17 at 20:56

2 Answers2

110

json is a built-in module, you don't need to install it with pip.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 3
    It's a built-in module and you **can't** install it with `pip`. If you use ubuntu such as the user above, it might be you DO have python2 but you DON'T have json; see my answer. – MichielB Aug 24 '18 at 09:07
14

While it's true that json is a built-in module, I also found that on an Ubuntu system with python-minimal installed, you DO have python but you can't do import json. And then I understand that you would try to install the module using pip!

If you have python-minimal you'll get a version of python with less modules than when you'd typically compile python yourself, and one of the modules you'll be missing is the json module. The solution is to install an additional package, called libpython2.7-stdlib, to install all 'default' python libraries.

sudo apt install libpython2.7-stdlib

And then you can do import json in python and it would work!

MichielB
  • 4,181
  • 1
  • 30
  • 39