Fatal error while compiling PyQt5: Python.h does not exist - python

I'm trying to install PyQt5 on my Ubuntu 12.04 box. So after downloading it from here I untarred it, ran python configure.py and make. Make however, results in the following:
cd qpy/ && ( test -f Makefile || /opt/qt5/bin/qmake /home/kram/Downloads/PyQt-gpl-5.0/qpy/qpy.pro -o Makefile ) && make -f Makefile
make[1]: Map '/home/kram/Downloads/PyQt-gpl-5.0/qpy' is entered
cd QtCore/ && ( test -f Makefile || /opt/qt5/bin/qmake /home/kram/Downloads/PyQt-gpl-5.0/qpy/QtCore/QtCore.pro -o Makefile ) && make -f Makefile
make[2]: Map '/home/kram/Downloads/PyQt-gpl-5.0/qpy/QtCore' is entered
g++ -c -pipe -fno-strict-aliasing -O2 -Wall -W -fPIC -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I/opt/qt5/mkspecs/linux-g++ -I. -I. -I../../QtCore -I/usr/local/include/python2.7 -I/opt/qt5/include -I/opt/qt5/include/QtCore -I. -o qpycore_chimera.o qpycore_chimera.cpp
qpycore_chimera.cpp:21:20: fatal error: Python.h: File or folder does not exist
compilation terminated.
make[2]: *** [qpycore_chimera.o] Error 1
make[2]: Map '/home/kram/Downloads/PyQt-gpl-5.0/qpy/QtCore' is left
make[1]: *** [sub-QtCore-make_first] Error 2
make[1]: Map '/home/kram/Downloads/PyQt-gpl-5.0/qpy' is left
make: *** [sub-qpy-make_first-ordered] Error 2
(I translated some parts of the error message from Dutch to English, so some words may be a bit off from the normal wording..)
Does anybody what the problem is here? Where could the relevant Python.h file be?

The problem is that the include path for all python headers in every Makefile will be pointing to /usr/local/include/python2.7 , which should have been /usr/include/python2.7
There are 2 possible solutions for this. Either you can change all the occurrence of this in every Makefile or else you can create a symlink to that location
sudo ln -s /usr/include/python2.7 /usr/local/include/python2.7
Now you can run make

sudo apt-get install python-dev
Your missing the python header files.

The problem you're having is that PyQt assumes you're not using your distro's managed python, and instead defaults to looking for sip in /usr/local/include/python2.7.
Luckily, configure.py provides options to override the python and sip include locations:
python configure.py --sip-incdir /usr/include/python2.7 py_inc_dir=/usr/include/python2.7
This solution should preferred to symlinking /usr/include/python2.7 into /usr/local/include/python2.7 as that will enable manually installed software to pollute (or corrupt packages installed to) distro-managed paths.

It is better to add existing header files to the project directory in both QTCreator and Anjuta IDE.

Related

Building pynauty with python3

I am trying to build pynauty according to this instructions:
https://web.cs.dal.ca/~peter/software/pynauty/html/install.html#build
I would like point out that my main goal is to run this python code:
https://github.com/calebh/dihash
Sadly I can not pass the pynauty's make phase.
If I execute make pynauty command I get the following error:
cd nauty; make nauty.o nautil.o naugraph.o schreier.o naurng.o
make[1]: Entering directory '/home/pc/pynauty-0.6.0/nauty27rc5'
make[1]: 'nauty.o' is up to date.
make[1]: 'nautil.o' is up to date.
make[1]: 'naugraph.o' is up to date.
make[1]: 'schreier.o' is up to date.
make[1]: 'naurng.o' is up to date.
make[1]: Leaving directory '/home/pc/pynauty-0.6.0/nauty27rc5'
python setup.py build
running build
running build_py
running build_ext
building 'pynauty.nautywrap' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fdebug-prefix-map=/build/python2.7-8kFkPd/python2.7-2.7.17=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Inauty -Isrc -I/usr/include/python2.7 -c src/nautywrap.c -o build/temp.linux-x86_64-2.7/src/nautywrap.o -O4 -fPIC
src/nautywrap.c:15:10: fatal error: Python.h: No such file or directory
15 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
make: *** [Makefile:36: pynauty] Error 1
I guess the above is because I don't have python-dev package installed (I want to build if for python3). So I've added an alias for python3 with:
aliast python=python3.
But still when I type make in the pynauty's root directory I get a message saying that python2 is detected:
Available targets:
pynauty - build the pynauty extension module
tests - run all tests
clean - remove all python related temp files and dirs
user-ins - install pynauty into ~/.local/
user-unins - uninstall pynauty from ~/.local/
virtenv-ins - install pynauty into the active virtualenv
virtenv-unins - uninstall pynauty from the active virtualenv
dist - create a source distribution
docs - build pyanauty documentation
clean-docs - remove pyanauty documentation
nauty-objects - compile only nauty.o nautil.o naugraph.o schreier.o naurng.o
nauty-progs - build all nauty programs
clean-nauty - a "distclean" for nauty
clobber - clean + clean-nauty + clean-docs
Python version: 2 7 17
Machine type: x86_64
Edit the Makefile for nauty.
Change PYTHON = python to PYTHON = python3, and
PIP = pip to PIP = pip3 (or whatever your pip for Python 3 is called).

How can I solve the lto1: internal compiler error: in lto_tag_to_tree_code, at lto-streamer.h:1005 that appears after 'make' command

I am super desperate...I am using Ubuntu 18.04.3 LTS
For a robotics class I had to build their project (after cloning it from git) with the make command. After some time i am receiving the following:enter image description here
(...)
make[1]: Entering directory '/home/fia/robotics-course/rai/rai/ry'
* UpToDate ../../rai/Kin/libKin.so
* UpToDate ../../rai/Core/libCore.so
* UpToDate ../../rai/KOMO/libKOMO.so
* UpToDate ../../rai/LGP/libLGP.so
g++ -g -march=native -Wall -DRAI_PYBIND `python3-config --cflags` -Wno-terminate -fPIC -std=c++14 -o lgp-py.o -c lgp-py.cpp
* UpToDate ../../rai/Operate/libOperate.so
g++ -g -march=native -Wall -DRAI_PYBIND `python3-config --cflags` -Wno-terminate -fPIC -std=c++14 -o ry.o -c ry.cpp
* UpToDate ../../rai/Perception/libPerception.so
* UpToDate ../../rai/RosCom/libRosCom.so
g++ -L/home/fia/robotics-course/rai/lib -L/usr/local/lib -o libry.so ./lgp-py.o ./ry.o -lCore -lKin -lKOMO -lLGP -lOperate -lRosCom -lPerception `python3-config --ldflags` -lrt -shared
lto1: internal compiler error: in lto_tag_to_tree_code, at lto-streamer.h:1005
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-7/README.Bugs> for instructions.
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
../../build/generic.mk:299: recipe for target 'libry.so' failed
make[1]: *** [libry.so] Error 1
make[1]: Target 'default' not remade because of errors.
make[1]: Leaving directory '/home/fia/robotics-course/rai/rai/ry'
***** FAILED rai/rai/ry/libry.so
I am assuming that the line "internal compiler error" shows me whats wrong but I can not figure out how to solve it... I re-installed g++ and also redownloaded the git repository several times but nothing seems to work. I already thought that maybe me Operating System has a problem?
I already thought about reistalling Ubuntu...
So if anyone has an idea i would be super thankful!
Regards
Fia
"Internal compiler error" sounds like there's a bug in the compiler, so here are some ideas to try to work around it.
You could try compiling it with clang++ instead of g++. Install it using:
sudo apt-get install clang
Then build using something like:
CC=clang CXX=clang++ LD=clang make
Because the error mentions lto, you could also turning link-time optimization off:
LDFLAGS=-fno-lto make

Which $path is needed so g++/pybind11 could locate Python.h?

I started using pybind11 (on Ubuntu 16.04 with Python 2.7).
To test the waters, I created a do-nothing wrapper around my c++ library. Alas, the compilation is unable to find Python.h:
$ g++ -std=c++0x -fPIC -pedantic -g -Wno-missing-field-initializers -Wno-switch -Wno-multichar -ftree-vectorize -ftree-vectorize -mssse3 backend.h uvc-v4l2.cpp wrap.cpp -o wrap.so
backend.h:4:9: warning: #pragma once in main file
#pragma once
^
In file included from /usr/local/include/pybind11/pytypes.h:12:0,
from /usr/local/include/pybind11/cast.h:13,
from /usr/local/include/pybind11/attr.h:13,
from /usr/local/include/pybind11/pybind11.h:36,
from wrap.cpp:1:
/usr/local/include/pybind11/common.h:72:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
However, I do seem to have the file:
$ find /usr -name Python.h
/usr/include/python2.7/Python.h
/usr/include/python3.5m/Python.h
Which (path?) should I correct so g++ would be able to locate Python.h?
Notes:
$ apt list | grep -iE -- '^python.-dev|^python-dev'
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
python-dev/xenial,now 2.7.11-1 amd64 [installed]
python3-dev/xenial,now 3.5.1-3 amd64 [installed]
$ dpkg -S Python.h
libpython2.7-dev:amd64: /usr/include/python2.7/Python.h
libpython3.5-dev:amd64: /usr/include/python3.5m/Python.h
$ dpkg -L python2.7-dev
/.
/usr
/usr/bin
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/doc
/usr/share/doc/python2.7
/usr/share/doc/python2.7/x86_64-linux-gnu
/usr/share/doc/python2.7/x86_64-linux-gnu/test_results.gz
/usr/share/doc/python2.7/x86_64-linux-gnu/pybench.log.gz
/usr/share/doc/python2.7/gdbinit.gz
/usr/share/doc/python2.7/HISTORY.gz
/usr/share/doc/python2.7/README.valgrind.gz
/usr/share/doc/python2.7/README.maintainers
/usr/bin/python2.7-config
/usr/share/man/man1/python2.7-config.1.gz
/usr/share/doc/python2.7-dev
-I/usr/include/python2.7
The -I flag adds the directory to the list of directories to be searched for header files. If you were to instead want the python3.5 equivalent, you'd replace 2.7 with 3.5m
A more reliable way to get this flag is to use pkg-config. For instance:
$ pkg-config --cflags python
-I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7
$ pkg-config --cflags python3
-I/usr/include/python3.6m -I/usr/include/x86_64-linux-gnu/python3.6m

PyYAML: how to specify an include directory?

I build libyaml and install it into a local area:
yaml-0.1.5 $ ./configure --prefix=/usr/local/sqlminus
yaml-0.1.5 $ make install
yaml-0.1.5 $ ls -l /usr/local/sqlminus/include/yaml.h
-rw-r--r--# 1 mh admin 54225 Jan 5 09:05 /usr/local/sqlminus/include/yaml.h
But when I build PyYAML, it cannot find yaml.h.
PyYAML-3.11 $ /usr/local/sqlminus/bin/python setup.py build
checking if libyaml is compilable
gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -I/usr/local/sqlminus/include/python2.7
-c build/temp.macosx-10.4-x86_64-2.7/check_libyaml.c
-o build/temp.macosx-10.4-x86_64-2.7/check_libyaml.o
build/temp.macosx-10.4-x86_64-2.7/check_libyaml.c:2:10:
fatal error: 'yaml.h'
file not found
#include <yaml.h>
^
1 error generated.
How can I tell PyYAML where I've installed libyaml?
(update) Based on dotslash's comment below, editing setup.cfg and adding these two lines made everything work smoothly.
include_dirs=/usr/local/sqlminus/include
library_dirs=/usr/local/sqlminus/lib
(end update)
I think you should install dependencies.
If you are using Ubuntu or Debian based system, you could search by this
apt-cache search libyaml
Then you may find there are some packages related.
I would suggest you try to install this: apt-get install libyaml-dev -y
If you are using Mac OS, you could change the source in file check_libyaml.c, tell it what the absolute path of yaml.h is.
Or just specify the path while compiling
python setup.py config --with-includepath=/path/to/your/install/of/python/includes/
Then go compiling.
More info can be found here.
Hope this be helpful.
Based on dotslash's comment, editing setup.cfg and adding these two lines made everything work smoothly:
include_dirs=/usr/local/sqlminus/include
library_dirs=/usr/local/sqlminus/lib

Linking Boost Python on OSX 10.10

I am trying to build the project from: https://github.com/TNG/boost-python-examples which is a set of boost python examples on Yosemite.
First I installed Boost and Boost python and cmake
brew install boost
brew install boost-pyton
brew install cmake
I've run into the following error:
/usr/local/Cellar/cmake/3.0.2/bin/cmake -H/Users/demo/devel/boost-python-examples -B/Users/demo/devel/boost-python-examples/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.0.2/bin/cmake -E cmake_progress_start /Users/demo/devel/boost-python-examples/build/CMakeFiles /Users/demo/devel/boost-python-examples/build/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f 01-HelloWorld/CMakeFiles/hello.dir/build.make 01-HelloWorld/CMakeFiles/hello.dir/depend
cd /Users/demo/devel/boost-python-examples/build && /usr/local/Cellar/cmake/3.0.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/demo/devel/boost-python-examples /Users/demo/devel/boost-python-examples/01-HelloWorld /Users/demo/devel/boost-python-examples/build /Users/demo/devel/boost-python-examples/build/01-HelloWorld /Users/demo/devel/boost-python-examples/build/01-HelloWorld/CMakeFiles/hello.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f 01-HelloWorld/CMakeFiles/hello.dir/build.make 01-HelloWorld/CMakeFiles/hello.dir/build
Linking CXX shared module hello.so
cd /Users/demo/devel/boost-python-examples/build/01-HelloWorld && /usr/local/Cellar/cmake/3.0.2/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ -g -bundle -Wl,-headerpad_max_install_names -o hello.so CMakeFiles/hello.dir/hello.cpp.o /usr/local/lib/libboost_python-mt.dylib
Undefined symbols for architecture x86_64:
"_PyString_Type", referenced from:
boost::python::to_python_value<char const* const&>::get_pytype() const in hello.cpp.o
"__Py_NoneStruct", referenced from:
boost::python::api::object::object() in hello.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [01-HelloWorld/hello.so] Error 1
make[1]: *** [01-HelloWorld/CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2
It looks like its calling:
/usr/bin/c++ -stdlib=libstdc++ -g -bundle -Wl,-headerpad_max_install_names -o hello.so CMakeFiles/hello.dir/hello.cpp.o /usr/local/lib/libboost_python-mt.dylib
I've tried the following:
Removing the -stdlib=libstdc++
Using gcc instead of c++
Using -m32 (bad idea)
As far as i can tell the dynlib is good:
/usr/local/lib/libboost_python-mt.dylib: Mach-O 64-bit dynamically linked shared library x86_64
So I'm not sure where my issue currently is. I'm assuming its some sort of build flag i'm missing here.
Thanks!
You also need to link in the Python library.
In your CMakeLists.txt you can add
include(FindPythonLibs)
This will define a variable PYTHON_LIBRARIES which you can then use like this
target_link_libraries(your_exe ${PYTHON_LIBRARIES ...)
Try to force cmake to use the right directories:
cmake -DBOOST_ROOT=xxx -DPYTHON_LIBRARY=xxx -DPYTHON_INCLUDE_DIR=xxx ..

Categories

Resources