Bienvenue sur IndexError.

Ici vous pouvez poser des questions sur Python et le Framework Django.

Mais aussi sur les technos front comme React, Angular, Typescript et Javascript en général.

Consultez la FAQ pour améliorer vos chances d'avoir des réponses à vos questions.

Comment résoudre ce problème d'import avec pip ?

+5 votes

J'ai voulu me remettre à Python, et j'ai donc voulu installer quelques packages pour m'amuser (NodeTree, lxml, beautifulSoup). Seulement, je rencontre un problème à l'installation de NodeTree, par exemple.

Voici ce que je tape sur mon terminal :

pip install NodeTree

Et voici le retour de la commande :

Downloading/unpacking NodeTree
  Downloading NodeTree-0.3.tar.bz2
  Running setup.py (path:/tmp/pip_build_nairolf/NodeTree/setup.py) egg_info for package NodeTree
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_nairolf/NodeTree/setup.py", line 96, in <module>
        from sphinx.setup_command import BuildDoc
    ImportError: No module named sphinx.setup_command
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_nairolf/NodeTree/setup.py", line 96, in <module>

    from sphinx.setup_command import BuildDoc

ImportError: No module named sphinx.setup_command

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_nairolf/NodeTree
Storing debug log for failure in /home/nairolf/.pip/pip.log

Voici ce que contient le log ~/.pip/pip.log

/usr/bin/pip run on Thu Aug 27 22:50:51 2015
Downloading/unpacking NodeTree
  Getting page https://pypi.python.org/simple/NodeTree/
  URLs to search for versions for NodeTree:
  * https://pypi.python.org/simple/NodeTree/
  Analyzing links from page https://pypi.python.org/simple/nodetree/
    Found link https://pypi.python.org/packages/source/N/NodeTree/NodeTree-0.1.tar.bz2#md5=7f0302fc97096994c69205d767b27dea (from https://pypi.python.org/simple/nodetree/), version: 0.1
    Found link https://pypi.python.org/packages/source/N/NodeTree/NodeTree-0.2.tar.bz2#md5=274320546506c1b6b40c0e2afccd450d (from https://pypi.python.org/simple/nodetree/), version: 0.2
    Found link https://pypi.python.org/packages/source/N/NodeTree/NodeTree-0.3.tar.bz2#md5=b79443078965a8bc082082b273336093 (from https://pypi.python.org/simple/nodetree/), version: 0.3
  Using version 0.3 (newest of versions: 0.3, 0.2, 0.1)
  Downloading NodeTree-0.3.tar.bz2
  Downloading from URL https://pypi.python.org/packages/source/N/NodeTree/NodeTree-0.3.tar.bz2#md5=b79443078965a8bc082082b273336093 (from https://pypi.python.org/simple/nodetree/)
  Running setup.py (path:/tmp/pip_build_nairolf/NodeTree/setup.py) egg_info for package NodeTree
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_nairolf/NodeTree/setup.py", line 96, in <module>
        from sphinx.setup_command import BuildDoc
    ImportError: No module named sphinx.setup_command
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_nairolf/NodeTree/setup.py", line 96, in <module>

    from sphinx.setup_command import BuildDoc

ImportError: No module named sphinx.setup_command

----------------------------------------
Cleaning up...
  Removing temporary dir /tmp/pip_build_nairolf...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_nairolf/NodeTree
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1230, in prepare_files
    req_to_install.run_egg_info()
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 326, in run_egg_info
    command_desc='python setup.py egg_info')
  File "/usr/lib/python2.7/dist-packages/pip/util.py", line 715, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_nairolf/NodeTree
demandé 28-Aou-2015 par Nairwolf (130 points)

le package à l'air cassé ... As tu essayé pip install NodeTree==0.2 pour voir ?

2 Réponses

+5 votes
 
Meilleure réponse

Visiblement nodeTree, utilise une dépendance à sphinx qu'il ne déclare pas, ce qui fait que le paquet est cassé. Pour contourner le problème, installe sphinx avant :

pip install sphinx
répondu 28-Aou-2015 par Sam (4,984 points)
sélectionné 1-Sep-2015 par Nairwolf

J'imagine que tu voulais dire sphinx...

Voici ce que me donne la commande pip install sphinx :

Downloading/unpacking sphinx
  Downloading Sphinx-1.3.1-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded
Downloading/unpacking sphinx-rtd-theme>=0.1,<0.2 (from sphinx)
  Downloading sphinx_rtd_theme-0.1.8-py2.py3-none-any.whl (418kB): 418kB downloaded
Downloading/unpacking Jinja2>=2.3 (from sphinx)
  Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB): 263kB downloaded
Downloading/unpacking alabaster>=0.7,<0.8 (from sphinx)
  Downloading alabaster-0.7.6-py2-none-any.whl
Downloading/unpacking babel>=1.3 (from sphinx)
  Downloading Babel-2.0.tar.gz (3.4MB): 3.4MB downloaded
  Running setup.py (path:/tmp/pip_build_nairolf/babel/setup.py) egg_info for package babel

    warning: no previously-included files matching '*' found under directory 'docs/_build'
    warning: no previously-included files matching '*.pyc' found under directory 'tests'
    warning: no previously-included files matching '*.pyo' found under directory 'tests'
Requirement already satisfied (use --upgrade to upgrade): six>=1.4 in /usr/lib/python2.7/dist-packages (from sphinx)
Requirement already satisfied (use --upgrade to upgrade): Pygments>=2.0 in /usr/local/lib/python2.7/dist-packages (from sphinx)
Downloading/unpacking snowballstemmer>=1.1 (from sphinx)
  Downloading snowballstemmer-1.2.0.tar.gz (49kB): 49kB downloaded
  Running setup.py (path:/tmp/pip_build_nairolf/snowballstemmer/setup.py) egg_info for package snowballstemmer

    warning: no files found matching '*.py' under directory 'src'
Downloading/unpacking docutils>=0.11 (from sphinx)
  Downloading docutils-0.12.tar.gz (1.6MB): 1.6MB downloaded
  Running setup.py (path:/tmp/pip_build_nairolf/docutils/setup.py) egg_info for package docutils

    warning: no files found matching 'MANIFEST'
    warning: no files found matching '*' under directory 'extras'
    warning: no previously-included files matching '.cvsignore' found under directory '*'
    warning: no previously-included files matching '*.pyc' found under directory '*'
    warning: no previously-included files matching '*~' found under directory '*'
    warning: no previously-included files matching '.DS_Store' found under directory '*'
Downloading/unpacking MarkupSafe (from Jinja2>=2.3->sphinx)
  Downloading MarkupSafe-0.23.tar.gz
  Running setup.py (path:/tmp/pip_build_nairolf/MarkupSafe/setup.py) egg_info for package MarkupSafe

Downloading/unpacking pytz>=0a (from babel>=1.3->sphinx)
  Downloading pytz-2015.4-py2.py3-none-any.whl (475kB): 475kB downloaded
Installing collected packages: sphinx, sphinx-rtd-theme, Jinja2, alabaster, babel, snowballstemmer, docutils, MarkupSafe, pytz
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1436, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 672, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 902, in move_wheel_files
    pycompile=self.pycompile,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 206, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 193, in clobber
    os.makedirs(destsubdir)
  File "/usr/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/sphinx'

Storing debug log for failure in /home/nairolf/.pip/pip.log

J'ai l'impression que le problème n'est pas juste lié à ce package. J'avais des problèmes à installer lxml ou BeautifulSoup correctement, mais je vois qu'avec ce rappel, lxml est un peu plus compliqué qu'à la normale pour s'installer.

Par exemple, un pip install beautifulsoup me renvoie ceci :

Downloading/unpacking beautifulsoup
  Downloading BeautifulSoup-3.2.1.tar.gz
  Running setup.py (path:/tmp/pip_build_nairolf/beautifulsoup/setup.py) egg_info for package beautifulsoup

Installing collected packages: beautifulsoup
  Running setup.py install for beautifulsoup
    error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/BeautifulSoupTests.py'
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_nairolf/beautifulsoup/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-LIMPrB-record/install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-2.7

copying BeautifulSoup.py -> build/lib.linux-x86_64-2.7

copying BeautifulSoupTests.py -> build/lib.linux-x86_64-2.7

running install_lib

copying build/lib.linux-x86_64-2.7/BeautifulSoupTests.py -> /usr/local/lib/python2.7/dist-packages

error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/BeautifulSoupTests.py'

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_nairolf/beautifulsoup/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-LIMPrB-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_nairolf/beautifulsoup
Storing debug log for failure in /home/nairolf/.pip/pip.log

Est-ce que ces packages sont difficiles à installer, ou ai-je un problème avec pip ? (Ne pas savoir comment l'utiliser est un problème).

Ici le message d'erreur est assez explicite :

error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/BeautifulSoupTests.py'

ton user n'a pas les droits suffisant pour écrire dans le répoertoire de destination de l'installation des packages;

Plusieurs solutions :

  • utiliser sudo. mais pas un bonne idée : tu vas installer tes
    packages system-wide. Ca peut clasher avec des packages installés
    avec le package manager de ta distrib.

  • tiliser l'option --user qui va installer les packages dans ton home (~/.local/)

  • utiliser virtualenv
0 votes

Apparement, Si t'es sous linux (genre ubuntu pour le apt-get install, ou pacman -S install sur arch ...)

sudo apt-get install python-sphinx

Lectures supplémentaires par , ici, ou encore

répondu 29-Aou-2015 par boblinux (3,092 points)
...