14

I want use Twisted in Python, but when I installing ,in comes this error, how to handle it?

....
running build_ext
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c conftest.c -o conftest.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c conftest.c -o conftest.o
building 'twisted.runner.portmap' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c twisted/runner/portmap.c -o build/temp.linux-i686-2.7/twisted/runner/portmap.o
twisted/runner/portmap.c:10:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
1

1 Answer 1

37

You are missing the python development headers, needed to build packages that need to compile extensions.

If you are building on OSX, make sure you either install a prebuilt mac python package or if building python from source, use the framework flag when configuring. And also make sure you have XCODE installed so that you have a compiler.

If you are building on Linux, you probably need to install the python devel headers. For instance on Ubuntu you would need: apt-get install build-essential python-dev. Once you have the python development headers, twisted should be able to find them when you build with that python interpreter.

Sign up to request clarification or add additional context in comments.

5 Comments

I can't test at the moment under Linux, but in Windows the headers are already included in the default python installation. He probably just has to add the include directory correctly.
@Voo: The OP does not seem to be using windows. Look at the include path in the commands. I presume it to be linux: /usr/include/python2.7
I meant: If the headers are included under windows with the default installation, I'd assume that'd also be so under other linux (I'm not sure why exactly the headers are included in the first place, but I'd assume the arguments for including them under windows also hold under *nix).
@Voo: It would be different for each platform. Windows does not come with python in the first place, so the installer for windows includes the headers. On OSX, the included python is built as a framework which includes headers for development purposes. On *nix, you usually get a very slim build of python and have to install the development headers separately.
I just dealt with this issue. For anyone using synaptic and python 2.7, the package is specifically called: python2.7-dev

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.