web-dev-qa-db-fra.com

"pip install json" échoue sous Ubuntu

Impossible d'installer le module json . Pour autant que je sache, je ne devrais pas utiliser Sudo. quel est le problème?

 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/
22
Eugenio

json est un module intégré, vous n'avez pas besoin de l'installer avec pip.

58
alecxe

Bien qu'il soit vrai que json soit un module intégré, j'ai également constaté que sur un système Ubuntu avec python-minimal installé, vous disposez de python mais vous ne pouvez pas faire import json. Et puis, je comprends que vous essayez d’installer le module avec pip!

Si vous avez python-minimal, vous obtiendrez une version de python avec moins de modules que lorsque vous le compiliez vous-même, et l’un des modules manquants est le module json. La solution consiste à installer un package supplémentaire, appelé libpython2.7-stdlib, pour installer toutes les bibliothèques python 'par défaut'.

Sudo apt install libpython2.7-stdlib

Et ensuite vous pouvez faire import json en python et ça marcherait!

2
MichielB