Ipython: pip install error

Created on 14 Apr 2017  ·  28Comments  ·  Source: ipython/ipython

when running

pip install ipython

i get

Collecting ipython
  Using cached ipython-5.3.0-py2-none-any.whl
Collecting pickleshare (from ipython)
  Using cached pickleshare-0.7.4-py2.py3-none-any.whl
Collecting simplegeneric>0.8 (from ipython)
Collecting traitlets>=4.2 (from ipython)
  Using cached traitlets-4.3.2-py2.py3-none-any.whl
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython)
  Using cached backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Collecting decorator (from ipython)
  Using cached decorator-4.0.11-py2.py3-none-any.whl
Collecting pygments (from ipython)
  Using cached Pygments-2.2.0-py2.py3-none-any.whl
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/lib/python2.7/dist-packages (from ipython)
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython)
  Using cached pathlib2-2.2.1-py2.py3-none-any.whl
Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python2.7/dist-packages (from ipython)
Collecting prompt-toolkit<2.0.0,>=1.0.4 (from ipython)
  Using cached prompt_toolkit-1.0.14-py2-none-any.whl
Requirement already satisfied: enum34; python_version == "2.7" in /usr/lib/python2.7/dist-packages (from traitlets>=4.2->ipython)
Requirement already satisfied: six in /usr/lib/python2.7/dist-packages (from traitlets>=4.2->ipython)
Collecting ipython-genutils (from traitlets>=4.2->ipython)
  Using cached ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting scandir; python_version < "3.5" (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython)
  Using cached scandir-1.5.tar.gz
Requirement already satisfied: appdirs>=1.4.0 in /usr/local/lib/python2.7/dist-packages (from setuptools>=18.5->ipython)
Requirement already satisfied: packaging>=16.8 in /usr/local/lib/python2.7/dist-packages (from setuptools>=18.5->ipython)
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
  Using cached wcwidth-0.1.7-py2.py3-none-any.whl
Requirement already satisfied: pyparsing in /usr/local/lib/python2.7/dist-packages (from packaging>=16.8->setuptools>=18.5->ipython)
Building wheels for collected packages: scandir
  Running setup.py bdist_wheel for scandir ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-mGtqyq/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpzPzH0bpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying scandir.py -> build/lib.linux-x86_64-2.7
  running build_ext
  building '_scandir' extension
  creating build/temp.linux-x86_64-2.7
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
  _scandir.c:14:20: fatal error: Python.h: No such file or directory
   #include <Python.h>
                      ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for scandir
  Running setup.py clean for scandir
Failed to build scandir
Installing collected packages: scandir, pathlib2, pickleshare, simplegeneric, decorator, ipython-genutils, traitlets, backports.shutil-get-terminal-size, pygments, wcwidth, prompt-toolkit, ipython
  Running setup.py install for scandir ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-mGtqyq/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-kVFdnD-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 scandir.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_scandir' extension
    creating build/temp.linux-x86_64-2.7
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
    _scandir.c:14:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-mGtqyq/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-kVFdnD-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-mGtqyq/scandir/

Most helpful comment

That's unrelated to IPython, the issue comes from installing scandir, you should see that with the scandir maintainers.

If you are missing Python.h during compilation that's likely because you are missing the Python header. If you are going to compile c-extensions (which you do implicitly by install in scandir) you may want to install the Python headers (apt-get install python-dev maybe ?).

All 28 comments

That's unrelated to IPython, the issue comes from installing scandir, you should see that with the scandir maintainers.

If you are missing Python.h during compilation that's likely because you are missing the Python header. If you are going to compile c-extensions (which you do implicitly by install in scandir) you may want to install the Python headers (apt-get install python-dev maybe ?).

BTW, I close because this is not an IPython issue, but feel free to keep asking questions or commenting.

ur solution worked thnx

  • This email was sent using 100% recycled electrons. No humans or animals
    were injured or traumatized in the creation of this message. We cannot
    guarantee the same for the recipient.*

On Fri, Apr 14, 2017 at 1:11 PM, Matthias Bussonnier <
[email protected]> wrote:

BTW, I close because this is not an IPython issue, but feel free to keep
asking questions or commenting.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/ipython/ipython/issues/10454#issuecomment-294193464,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP0A5HJjJ3e9DRWaJEPUe_8PakiWUET9ks5rv6imgaJpZM4M96VS
.

the apt install python-dev

  • This email was sent using 100% recycled electrons. No humans or animals
    were injured or traumatized in the creation of this message. We cannot
    guarantee the same for the recipient.*

On Fri, Apr 14, 2017 at 1:25 PM, Furlong, Jonathan <
[email protected]> wrote:

ur solution worked thnx

  • This email was sent using 100% recycled electrons. No humans or animals
    were injured or traumatized in the creation of this message. We cannot
    guarantee the same for the recipient.*

On Fri, Apr 14, 2017 at 1:11 PM, Matthias Bussonnier <
[email protected]> wrote:

BTW, I close because this is not an IPython issue, but feel free to keep
asking questions or commenting.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/ipython/ipython/issues/10454#issuecomment-294193464,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AP0A5HJjJ3e9DRWaJEPUe_8PakiWUET9ks5rv6imgaJpZM4M96VS
.

For CentOS users, I did 'yum groupinstall 'development tool' and was able to install ipython(just installing python-devel, did not work) though I think you need to just account for the c-extensions as noted by Carreau

On Windows, "pip install jupyter" was unable to install scandir. But "pip install scandir" succeeded. And "pip install jupyter" subsequently succeeded.

On Windows, "pip install jupyter" was unable to install scandir. But "pip install scandir" succeeded. And "pip install jupyter" subsequently succeeded.

That is weird, can you check the pip and setuptools versions ?

Sure thing! Sorry about the delay.
pip v9.0.1
setuptools v28.8.0

I should clarify that I installed all of the other dependencies in addition to scandir directly with pip before running the successful jupyter installation.

Also, for completeness,

python v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40, MSC v.1500 64 bit (AMD64)
Windows 10, Version 1703 (OS Build 15063.540)

I am running into this same issue on Red Hat Enterprise Linux Server release 7.4 (Maipo) with Python 2.7.
I am trying to install ipython and I can't because of scandir.
I haven't found any solution and searching for "scandir" puts this issue high in the results list.

Can someone provide instructions on how to install scandir on RHEL?

I keep getting this same error from running sudo pip install scandir

  _scandir.c:14:20: fatal error: Python.h: No such file or directory
   #include <Python.h>
                      ^
  compilation terminated.
  error: command 'gcc' failed with exit status 1

Seems like a PATH variable issue. Might want to do a
"whereis Python.h"
If one or more paths come up, add the directory (without the filename) to your PATH variable. Otherwise, you've got bigger problems, and we need to figure out how to get the header files on your machine.

Thanks so much for the quick response. Sorry for my verbosity.
So, whereis Python.h and whereis 'Python.h' turn up nothing at all.

This is a remote machine that was set up only with Python 2.7 on it when I first got access.
I didn't even have gcc so I ran sudo yum groupinstall 'development tool' _afterwards._
Could this be the problem? If so, should I uninstall Python and reinstall it?

If the above doesn't matter:
I'm a sudo user but not root, so I can scp any files I want to most places.
I just don't have any idea what to copy (some C header file Python.h?), where to copy it, and what to do (add something to gcc's include path right?, but from where is that gcc command being run? I don't know.

I'm stuck using yum (yuck) and rpm so unfortunately apt-get can't solve my problems.
According to the docs, I must use ipython version 5 and scandir version < 1.6 with Python 2.7. I cannot use Python 3.x because of 3rd party API constraints.

I'm an experienced developer (on everything except RHEL) so manual installation doesn't scare me.... I just can't find anything about how to do it.

As for my PATH, it's currently quite short as this machine has just been set up.
(It had Python 2.7 installed as I requested but nothing else, not even gcc. )

~$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

Python lives here:

$ whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz

Alright. I think I have a solution for you--or at least something to try. No need to apologize for verbosity. Complete reporting is a virtue in these kinds of situations.

sudo yum install python-devel
pip install scandir==1.5

That should install the Python header files to "/usr/include/python2.7/" and get the appropriate scandir version you need. If you have further errors, don't hesitate to post again!

Also, small correction from before. I should have advised you to use the following to check for the presence of the headers:

sudo updatedb
locate Python.h

At the time, I didn't realize that whereis is restricted to executables, their man pages, and their source files.

P.S. In my initial post, I accidentally hid some of the code, but it should be viewable now.

Thanks @jmchambers90 for helping !

I think you might also want to look at scandir issue tracker : https://github.com/benhoyt/scandir/issues/85 have mentions of RHEL, and I believe you should avoid using sudo+pip it's a recipe for issue as yum and pip will fight over files.

As long as you have pip 9+, pip should also avoid installing IPython 6+ on Python 2, if you have an earlier version of pip and can't upgrade; you may want to pip install ipython<6.

The error about Python.h generally means you don't have the Python development headers installed. On Red hat, the package you need should be something like python-devel or python2-devel (on Debian, it's python-dev). If anyone is seeing the same error on Python 3, the package will probably be something like python3-devel or python3-dev.

@Carreau
I already looked at that and posted a question there. It didn't work for me.

@jmchambers90
Thanks for the ideas. I've already tried them, and different variations.
Here is the output:

~$ sudo yum install python-devel
Loaded plugins: product-id, search-disabled-repos, subscription-manager
rhel-7-server-optional-rpms                                                                                                                                                             | 3.5 kB  00:00:00
No package python-devel available.
Error: Nothing to do
~$ pip install scandir==1.5
Collecting scandir==1.5
  Using cached scandir-1.5.tar.gz
Building wheels for collected packages: scandir
  Running setup.py bdist_wheel for scandir ... error
  Complete output from command /usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-VI4qqT/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpdgntdppip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying scandir.py -> build/lib.linux-x86_64-2.7
  running build_ext
  building '_scandir' extension
  creating build/temp.linux-x86_64-2.7
  gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
  _scandir.c:14:20: fatal error: Python.h: No such file or directory
   #include <Python.h>
                      ^
  compilation terminated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for scandir
  Running setup.py clean for scandir
Failed to build scandir
Installing collected packages: scandir
  Running setup.py install for scandir ... error
    Complete output from command /usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-VI4qqT/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-W_j9CZ-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 scandir.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_scandir' extension
    creating build/temp.linux-x86_64-2.7
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c _scandir.c -o build/temp.linux-x86_64-2.7/_scandir.o
    _scandir.c:14:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python2 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-VI4qqT/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-W_j9CZ-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-VI4qqT/scandir/



md5-411faa47d16581696ff1f461eadf5851



~$ sudo updatedb
sudo: updatedb: command not found



md5-411faa47d16581696ff1f461eadf5851



~$ locate Python.h
-bash: locate: command not found

On my Fedora system the package is now called python2-devel. I can't try on RHEL, but I'm confident that there will be a package somewhere that contains Python.h. You'll need to work out what it is and install it.

@takluyver Thanks for the answer.
I think this machine is just screwed and has to be wiped clean.
Probably because of corporate firewalls and proxies, pip and yum seem to be aware of very little.

$ pip install python2-devel
Collecting python2-devel
  Could not find a version that satisfies the requirement python2-devel (from versions: )
No matching distribution found for python2-devel

@takluyver is right. There's almost certainly a development package on yum.

More things to try. Search for the package:

sudo yum search python | grep -i devel

Others have found the following to be successful:

sudo yum install python-devel.x86_64

If all else fails, we can pull the includes from the Python source. The latest version of 2.7 is at

https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz

And Python.h is in the "Include" directory of the unzipped file.

Also, I believe @takluyver was suggesting that you attempt the package install on yum, not pip:

sudo yum install python2-devel

I'm installing RHEL Server 7.4 to hopefully see what you see instead of continuing to guess.

Something must be wrong with yum.
I can't even install well-known things like ruby
This machine is mis-configured and I think only tech support can fix it.

Thanks anyway everyone. You've been more than helpful.

~$ sudo yum install python2-devel
Loaded plugins: product-id, search-disabled-repos, subscription-manager
No package python2-devel available.
Error: Nothing to do
~$ sudo yum install python-devel.x86_64
Loaded plugins: product-id, search-disabled-repos, subscription-manager
No package python-devel.x86_64 available.
Error: Nothing to do
~$ sudo yum search python | grep -i devel
dbus-python-devel.i686 : Libraries and headers for dbus-python
dbus-python-devel.x86_64 : Libraries and headers for dbus-python
gstreamer-python-devel.i686 : Headers for developing programs that will use
gstreamer-python-devel.x86_64 : Headers for developing programs that will use
nautilus-python-devel.x86_64 : Python bindings for Nautilus
nemo-python-devel.x86_64 : Python bindings for Nemo
ovirt-engine-sdk-python.noarch : oVirt Engine Software Development Kit (Python)
python-caja-devel.x86_64 : Python bindings for Caja
python-cherrypy2.noarch : Pythonic, object-oriented web development framework
python-nbxmpp-doc.noarch : Developer documentation for python-nbxmpp
python-pillow-devel.i686 : Development files for python-pillow
python-pillow-devel.x86_64 : Development files for python-pillow
python-pyside-devel.x86_64 : Development files for python-pyside
python-tools.x86_64 : A collection of development tools included with Python
python2-behave.noarch : Tools for the behavior-driven development, Python style
                             : developed at OSRF
python34-cairo-devel.x86_64 : Libraries and headers for python34-cairo
python34-devel.x86_64 : Libraries and header files needed for Python 3
                      : development
python34-gobject-devel.x86_64 : Development files for embedding Python 3.4
python34-greenlet-devel.x86_64 : C development headers for python34-greenlet
wxPython-devel.x86_64 : Development files for wxPython add-on modules
xapian-bindings-python.x86_64 : Files needed for developing Python scripts which
TurboGears.noarch : Back-to-front web development in Python
edk2-tools-python.noarch : EFI Development Kit II Tools
gnome-python2-devel.x86_64 : Development files for building add-on libraries
hawkey-devel.i686 : A Library providing simplified C and Python API to libsolv
hawkey-devel.x86_64 : A Library providing simplified C and Python API to libsolv
kobo.noarch : Python modules for tools development
pygtksourceview-devel.x86_64 : Development files for using pygtksourceview in
pyldb-devel.i686 : Development files for the Python bindings for the LDB library
pyldb-devel.x86_64 : Development files for the Python bindings for the LDB
python-igraph-devel.x86_64 : Development files for igraph
python-pycxx-devel.noarch : PyCXX header and source files
python-strainer.noarch : Tools to allow developers to cleanup web serialization
python-zc-buildout.noarch : System for managing development buildouts
python2-clint.noarch : A set of awesome tools for developing commandline
qscintilla-python-devel.noarch : Development files for QScintilla PyQt4 bindings
redhat-support-lib-python.noarch : Red Hat Support Software Development Library
spyder.noarch : Scientific Python Development Environment

Again, if all else fails, we can dispense with yum and just pull the includes straight from the Python source (https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz). After you unzip, you'll find Python.h in the "Include" directory of the unzipped file. Standard practice seems to be to plug the includes into /usr/include/python2.7/. So, once you have them in place, you can try pip install scandir==1.5 again. If gcc still can't find the includes, then we'll either need to add /usr/include/python2.7/ to the system path or download the scandir source and modify the call to gcc in the setup files for scandir.

It's really strange for yum to have python34-devel.x86_64 and not the equivalent for Python 2.7.

To fix your immediate problem, you can download and install the Python 2.7 development package directly from the CentOS repo at http://mirror.centos.org/centos/7/os/x86_64/Packages/python-devel-2.7.5-58.el7.x86_64.rpm. Then you can scp it over and install it as follows:

sudo rpm -ivh python-devel-2.7.5-58.el7.x86_64.rpm

In the long run, you'll probably want to add the CentOS repositories to yum so you can get the other yum packages you're interested in. See https://techglimpse.com/configure-yum-rhel-centos-repository/.

Lastly, I see what you mean about the stripped-down nature of RHEL. I've been playing around with the minimal installation, and it's remarkable how little it includes. No wget, mlocate, python-devel, or ruby. However, _all_ of those packages are available on the original installation media in the Packages directory. If IT can help you, I'd _highly_ recommend having them copy the entire Packages directory from the installation media to your machine so that you have an easy, reliable place to source your packages even when yum is failing. Alternatively, you can download the CentOS version of most if not all of these packages directly from http://mirror.centos.org/centos/7/os/x86_64/Packages and install them using the rpm command. Admittedly, yum is superior if you can get it to work since it handles dependencies for you; but, for that, you'd have to add the CentOS repos using the guide I cited above.

@jmchambers90 THAT DID IT! IT WORKED!
Thank you so much I've been on this for at least 10 or 11 hours now.

Had the same issue on Redhat 7 , and worked after :

yum install python-devel.x86_64

@Carreau Thank you very much!! Your solution helped me with Droidbot installation :)

Was this page helpful?
0 / 5 - 0 ratings