Bug 16570 - Python/Python3: distutils cannot find the configuration file (pyconfig.h) in a standard configuration path
Summary: Python/Python3: distutils cannot find the configuration file (pyconfig.h) in ...
Status: RESOLVED FIXED
Alias: None
Product: Mageia
Classification: Unclassified
Component: RPM Packages (show other bugs)
Version: Cauldron
Hardware: All Linux
Priority: Normal normal
Target Milestone: ---
Assignee: Philippe Makowski
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-11 13:18 CEST by David GEIGER
Modified: 2015-08-30 20:02 CEST (History)
1 user (show)

See Also:
Source RPM: python3-3.4.3-3.mga6.src.rpm
CVE:
Status comment:


Attachments

Description David GEIGER 2015-08-11 13:18:20 CEST
I tried to compile a new library "audaspace" to import it on Mageia repo because soon this library will become needed for the future blender 2.8 version.

But actually we can't compile this library due to a non standard path of the pyconfig.h, under Mageia this file is in "/usr/include/multiarch-x86_64-linux/python3.4m/pyconfig.h" but standard config should be in "/usr/include/python3.4m/pyconfig.h".

We have degugged that with the audaspace developer on his github project:

https://github.com/audaspace/audaspace/issues/1

--------------------------------------
i.e.:

I just "debugged" the problem with Dave over IRC. The problem is as follows:

In python running

__import__("distutils.sysconfig").sysconfig.get_config_var('Py_ENABLE_SHARED')
does not print anything. We further investigated and found that
distutils.sysconfig (unlike the normal sysconfig package) tries to manually parse the configuration from the file /usr/include/python3.4m/pyconfig.h 

However, thanks to the "multiarch magic" in this file, the actual configuration is in /usr/include/multiarch-x86_64-linux/python3.4m/pyconfig.h and this is why distutils cannot find the configuration there. We hardcoded the path in /usr/lib64/python3.4/distutils/sysconfig.py in the get_config_h_filename() function and then building succeeded, but of course this is not the solution to go as it breaks any other architecture.

Now the debatable question is if this problem is in the way Mageia handles the python configuration files, or how Python's distutils reads the configuration, but this problem has to be solved somehow to make sure python extensions written in C/C++ actually compile on Mageia with setuptools.

There are many possible solutions: distutils could be patched in many positions (for the problem we are having it would be sufficient to just remove the last if in build_ext.py) or when creating the python package the pyconfig.h from multiarch-*/python*/pyconfig.h could be moved to python*/pyconfig.h.
I am sure, you know best how to fix this problem. 

Cheers, Jörg
--------------------------------------


Also I tried another test simply adding the line: "#define Py_ENABLE_SHARED 1" in "/usr/include/python3.4m/pyconfig.h" file and the build is succeed.

$ cat /usr/include/python3.4m/pyconfig.h
#define _MULTIARCH_HEADER python3.4m/pyconfig.h
#include
/* Defined if Python is built as a shared library. */
#define Py_ENABLE_SHARED 1

This can be a simple solution for fix.

@Philippe: what is your opinion on this issue?



Reproducible: 

Steps to Reproduce:
David GEIGER 2015-08-11 13:18:42 CEST

Assignee: bugsquad => makowski.mageia

Comment 1 Philippe Makowski 2015-08-11 23:22:59 CEST
I don't understand where is your problem, because in fact in setuptools build_ext.py we have : 
try:
    # Python 2.7 or >=3.2
    from sysconfig import _CONFIG_VARS
so it should have the correct information
it should never use distutils.sysconfig but sysconfig it self
and that's the first time that we reach your problem, all other python extension are building without problem
other point the /usr/include/python3.4m/pyconfig.h is correct, as it include /usr/include/multiarch-x86_64-linux/python3.4m/pyconfig.h
Comment 2 Philippe Makowski 2015-08-12 13:51:19 CEST
I think I found the origin :
http://svnweb.mageia.org/packages?view=revision&revision=211298
Date: 	Mon Feb 20 22:18:08 2012 UTC (3 years, 5 months ago)

but now, the problem is, why are you the only one with your audaspace build to reach this issue.

Maybe the problem is on your build, not really our Python install.

can you give me more details on how you are making your build ?

Eventually I can put back the patch, as it seems that the distutils parser is not clever enough.

guillomovitch, do you have any clue ?

CC: (none) => guillomovitch

Comment 3 David GEIGER 2015-08-12 18:53:20 CEST
I don't know if it is feasible or not but simply add this line "#define Py_ENABLE_SHARED 1" in /usr/include/python3.4m/pyconfig.h file is more than enough.

or perhaps add "#include <multiarch-x86_64-linux/python3.4m/pyconfig.h>"?
Comment 4 Philippe Makowski 2015-08-12 21:53:34 CEST
(In reply to David GEIGER from comment #3)
> I don't know if it is feasible or not but simply add this line "#define
> Py_ENABLE_SHARED 1" in /usr/include/python3.4m/pyconfig.h file is more than
> enough.
hum, I would prefer not, the patch is better, others settings might be important too 
> or perhaps add "#include <multiarch-x86_64-linux/python3.4m/pyconfig.h>"?
it is done already, but clearly distutils parser is not clever enough.

for now the best solution I see is to re add the patch, as we have in Python2.
Comment 5 David GEIGER 2015-08-13 06:32:24 CEST
(In reply to Philippe Makowski from comment #4)
> > or perhaps add "#include <multiarch-x86_64-linux/python3.4m/pyconfig.h>"?
> it is done already, but clearly distutils parser is not clever enough.

Ok but how is it done the link between "/usr/include/python3.4m/pyconfig.h" and 
"/usr/include/multiarch-x86_64-linux/python3.4m/pyconfig.h" ?

I tested adding #include <multiarch-x86_64-linux/python3.4m/pyconfig.h> and it works.
Comment 6 Philippe Makowski 2015-08-13 09:23:08 CEST
(In reply to David GEIGER from comment #5)
> Ok but how is it done the link between "/usr/include/python3.4m/pyconfig.h"
> and 
> "/usr/include/multiarch-x86_64-linux/python3.4m/pyconfig.h" ?
> 
like that :

#define _MULTIARCH_HEADER python3.4m/pyconfig.h
#include <multiarch-dispatch.h>

by the way, we have two diff with python2 :
1/ python2 have in files :
%multiarch %multiarch_includedir/python%{dirver}/pyconfig.h
instead of
%multiarch_includedir/python%{dirver}/pyconfig.h

2/ the patch in distutils

I did both in cauldron, python3-3.4.3-4.mga6 should land soon
Comment 7 Philippe Makowski 2015-08-14 09:07:53 CEST
Finaly I added as a quick fix an include (python3-3.4.3-6.mga6 http://svnweb.mageia.org/packages/cauldron/python3/current/SPECS/python3.spec?r1=864562&r2=864561&pathrev=864562 )

but for me it's a temporary fix only
distutils have to be investigated

python3 -c "import distutils;print(__import__('distutils.sysconfig').sysconfig.get_config_var('Py_ENABLE_SHARED'))"

should report the same thing than working

python3 -c "import sysconfig;print(sysconfig.get_config_var('Py_ENABLE_SHARED'))"
Comment 8 Philippe Makowski 2015-08-14 20:05:11 CEST
for the record and more investigation, where we loose the sys.arch (Mageia specific) 

http://svnweb.mageia.org/packages?view=revision&revision=266813
Comment 9 Philippe Makowski 2015-08-15 00:35:39 CEST
fixed for audaspace with this patch :

$ cat python3-link.patch
Index: bindings/python/setup.py.in
===================================================================
--- bindings/python/setup.py.in
+++ bindings/python/setup.py.in	2015-08-14 23:59:51.356624466 +0200
@@ -25,6 +25,7 @@
                       library_dirs = ['.', 'Debug', 'Release'],
                       language = 'c++',
                       extra_compile_args = extra_args,
+                      extra_link_args = ['-lpython3.4m', '-lm'],
                       sources = [os.path.join(source_directory, file) for file in ['PyAPI.cpp', 'PyDevice.cpp', 'PyHandle.cpp', 'PySound.cpp', 'PySequenceEntry.cpp', 'PySequence.cpp']]
 )
 
this is related to our policy about --no-undefined 

but may be we also need to find a way to help cmake and distutils to find the correct link flags

if really as david said "simply add this line "#define Py_ENABLE_SHARED 1" in /usr/include/python3.4m/pyconfig.h file is more than enough" may be we should try

so I keep the bug open even if the build problem of audaspace is solved now.
Comment 10 David GEIGER 2015-08-15 09:01:21 CEST
Thanks a lot philippem!

patch adding 'extra_link_args' on setup file works well :)
Comment 11 Philippe Makowski 2015-08-29 18:35:34 CEST
I think that I found the correct patch for Python3
http://svnweb.mageia.org/packages/cauldron/python3/current/SOURCES/python3-3.4.2-distutils-init.patch?view=log

python3-3.4.3-7.mga6 should fix your issue with distutils as with the patch I get :

$ python3
Python 3.4.3 (default, Jul  1 2015, 18:38:11) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> __import__("distutils.sysconfig").sysconfig.get_config_var('Py_ENABLE_SHARED')
1
Comment 12 David GEIGER 2015-08-30 20:02:44 CEST
Yes, thanks Philippe for your nice job! :)

Now audaspace built properly without python3 link flags.

distutils check properly "pyconfig.h" file configuration.

So closing of this bug. :)

Status: NEW => RESOLVED
Resolution: (none) => FIXED


Note You need to log in before you can comment on or make changes to this bug.