Copterfly / modwsgi

Automatically exported from code.google.com/p/modwsgi
0 stars 0 forks source link

Problems with MacPorts Python not being used correctly. #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi.

I've tried to build this on OS/X and have run into a minor issue.

$ ./configure --with-apxs=/usr/local/apache2/bin/apxs 
--with-python=/usr/local/bin/python

$ apachectl configtest
httpd: Syntax error on line 415 of /usr/local/apache2/conf/httpd.conf: Syntax 
error on line 1 of 
/usr/local/apache2/conf.d/00_django.conf: Cannot load 
/usr/local/apache2/modules/
mod_wsgi.so into server: Symbol not found: _PyList_Type\n  Referenced from: 
/usr/local/
apache2/modules/mod_wsgi.so\n  Expected in: flat namespace\n

apache 2.3 HEAD
python 2.5 (downloaded from python.org)

running OS/X 10.4 
$ uname -a
Darwin Aeaea.local 8.10.3 Darwin Kernel Version 8.10.3: Wed Jun 27 23:29:36 PDT 
2007; 
root:xnu-792.23.3~1/RELEASE_I386 i386 i386

Original issue reported on code.google.com by kryton on 29 Aug 2007 at 2:03

Attachments:

GoogleCodeExporter commented 9 years ago
I would suspect that it is not finding the correct Python shared library when
starting Apache. Run 'otool -L' on mod_wsgi.so and post the result here:

 otool -L mod_wsgi.so 
mod_wsgi.so:
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.6)
        /System/Library/Frameworks/Python.framework/Versions/2.3/Python
(compatibility version 2.3.0, current version 2.3.5)
        /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
(compatibility version 1.0.0, current version 18.0.0)
        /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
(compatibility version 300.0.0, current version 567.27.0)

Rather than use Python 2.5 from python.org, you may be better off getting hold 
of one
of the prebuilt Python 2.5 installers for Mac OS X which installs it is a proper
MacOS X framework.

BTW, how many other versions of Python do you have installed besides the OS 
supplied
2.3.5?

Original comment by Graham.Dumpleton@gmail.com on 29 Aug 2007 at 3:17

GoogleCodeExporter commented 9 years ago
I have Problems to change the Python Version on OS X 10.4 .
I have installed macports python 2.4 .
When I tried this ./configure --with-python=/opt/local/bin/python2.4 
--with-apxs=/opt/local/apache2/bin/
apxs

It still shows python2.3 from apple:

otool -L mod_wsgi.so 
mod_wsgi.so:
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.9)
        /System/Library/Frameworks/Python.framework/Versions/2.3/Python (compatibility version 2.3.0, 
current version 2.3.5) 

Original comment by yves.ser...@gmail.com on 30 Aug 2007 at 11:38

GoogleCodeExporter commented 9 years ago
forgot to upload my config.log
The hello world examples works, but with python2.3.

Original comment by yves.ser...@gmail.com on 30 Aug 2007 at 11:43

Attachments:

GoogleCodeExporter commented 9 years ago
I haven't been able to Google up again the page I found which probably has the 
answer
to this, so I'll wing it and tell you what I believe you will need to do.

After you have run 'configure', edit 'Makefile'. You will find something like:

LDFLAGS = -framework Python -u __dummy -u _PyMac_Error -framework System  
-framework
CoreServices -framework Foundation

Edit this to insert at the start:

  -Wl,-F/some/path/to/macport/python/framework/directory

Ie.,

LDFLAGS = -Wl,-F/some/path/to/macport/python/framework/directory -framework 
Python -u
__dummy -u _PyMac_Error -framework System  -framework CoreServices -framework 
Foundation

This presumes that the macport frameworks are in their own area and not 
installed
into standard operating system directories.

Indicate whether this works and what the framework directory is as want to 
document
this. Wish I could just find the page where I saw someone using this 
workaround. :-(

Original comment by Graham.Dumpleton@gmail.com on 30 Aug 2007 at 11:55

GoogleCodeExporter commented 9 years ago
Found it:

  http://d.hatena.ne.jp/Voluntas/20070804/1186236866

I don't know what ${prefix} expands to though. In your case possibly 
'/opt/local'.

The file though looks to be specifically for building mod_wsgi with macports.

Original comment by Graham.Dumpleton@gmail.com on 31 Aug 2007 at 12:01

GoogleCodeExporter commented 9 years ago
Issues now documented in:

  http://code.google.com/p/modwsgi/wiki/InstallationOnMacOSX

Let me know if suggestions are not correct.

Original comment by Graham.Dumpleton@gmail.com on 31 Aug 2007 at 12:44

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
thanks for the link, and the hints

I tried both. First in the Makefile with "LDFLAGS = 
-Wl,-F/opt/local/Library/Frameworks -framework Python" 
it worked, and afterwards with the port file. I doesn't worked with the 
original Portfile I needed to make a 
patch to configure. 

I attached the portfile with a patch. I anybody wants to use it you can add a 
local repository and add it there.
Follow the instructions from here 
http://geeklair.net/new_macports_guide/#development.local-repositories .

I will try to get this into macports.

(I readded this comment my .tgz was broken)

Original comment by yves.ser...@gmail.com on 31 Aug 2007 at 1:46

Attachments:

GoogleCodeExporter commented 9 years ago
Issue adequately covered in documentation now.

Original comment by Graham.Dumpleton@gmail.com on 5 Sep 2007 at 10:03

GoogleCodeExporter commented 9 years ago
Here's how I made mod wsgi compile against my macports python 2.6 correctly
http://tr.im/iKAV 

Original comment by andrii...@gmail.com on 13 Apr 2009 at 9:41

GoogleCodeExporter commented 9 years ago
@andriijas

Post what LDFLAGS was before you modified Makefile, as well as what you set it 
to. Also post what LDLIBS is set to.

Also find equivalent for your Python installation of the file

  /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/config/Makefile

In that file, what are the entries for:

UNIVERSALSDK=
PYTHONFRAMEWORK=        Python
PYTHONFRAMEWORKDIR=     Python.framework
PYTHONFRAMEWORKPREFIX=  /System/Library/Frameworks
PYTHONFRAMEWORKINSTALLDIR= /System/Library/Frameworks/Python.framework

Almost looks like MacPorts is reporting it is a Python framework when it isn't. 
I recollect seeing this once before 
when trying to sort out issue with someone.

Give me above and then I'll ask some more questions.

Original comment by Graham.Dumpleton@gmail.com on 13 Apr 2009 at 10:18

GoogleCodeExporter commented 9 years ago
Also want what this is set to in that Makefile.

CONFIG_ARGS=     '--prefix=/usr' '--mandir=/usr/share/man' '--infodir=/usr/share
/info' '--disable-dependency-tracking' '--enable-ipv6' '--with-threads' '--enabl
e-framework=/System/Library/Frameworks' '--enable-toolbox-glue' '--enable-dtrace
' '--with-system-ffi' 'CFLAGS=-g -Os -pipe -fno-common -Wno-long-double -mno-fus
ed-madd -DENABLE_DTRACE -pipe' 'LDFLAGS=-Wl,-F.'

Original comment by Graham.Dumpleton@gmail.com on 13 Apr 2009 at 10:20

GoogleCodeExporter commented 9 years ago
Generated by configure:

CPPFLAGS = 
-I/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 
-DNDEBUG 
CFLAGS =  -Wc,'-arch i386'
LDFLAGS =  -F/opt/local/Library/Frameworks -framework Python -u _PyMac_Error 
/opt/local/Library/Frameworks/  -arch i386
LDLIBS =  -ldl  

$ python2.6-config --ldflags
-L/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/conf
ig
-ldl -lpython2.6

I took this output and replaced it into the LDFLAGS line in the Makefile, I 
didnt
change anything else in the Makefile

From my
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config
/Makefile

# Short name and location for Mac OS X Python framework
UNIVERSALSDK=
PYTHONFRAMEWORK=    Python
PYTHONFRAMEWORKDIR= Python.framework
PYTHONFRAMEWORKPREFIX=  /opt/local/Library/Frameworks
PYTHONFRAMEWORKINSTALLDIR= /opt/local/Library/Frameworks/Python.framework

$ python_select -s
python26

I dont know whats the difference between python beeing installed as a "python
framework" or what the options to that are, would be happy if someone could 
explain
that. One thing for sure is that installing python26 or 30 with macports is 
different
than 24 and 23. I was told in the #macports irc channel the other they that 
"python
developer expects somethings about their python install" but I was never told 
exactly
what they/we expect.

I'll gladly post more data if you need more input. You have better knowledge in 
this
than me but if you tell me whats wrong with macports I can submit a bug report 
on
their trac if you dont want to do it yourself.

Original comment by andrii...@gmail.com on 13 Apr 2009 at 10:50

GoogleCodeExporter commented 9 years ago
Here's the whole Makefile

Original comment by andrii...@gmail.com on 13 Apr 2009 at 10:58

Attachments:

GoogleCodeExporter commented 9 years ago
And here's the python2.6/config/Makefile

Original comment by andrii...@gmail.com on 13 Apr 2009 at 11:01

Attachments:

GoogleCodeExporter commented 9 years ago
Part of the problem is that 2.6 Makefile has changed:

LINKFORSHARED=  -u _PyMac_Error  
$(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)

It used to be:

LINKFORSHARED=  -u __dummy -u _PyMac_Error -framework System 
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK) -framework 
CoreServices -
framework Foundation

Ignoring what libraries are linked, it now uses PYTHONFRAMEWORKINSTALLDIR 
instead of PYTHONFRAMEWORKDIR.

There is a fiddle in the mod_wsgi configure script to remove that that crap. 
Don't know if that is interfering 
with things or not.

You could try running configure from scratch and then changed LDFLAGS to:

  LDFLAGS =  -F/opt/local/Library/Frameworks -framework Python -u _PyMac_Error  -arch i386

and see if that makes a difference.

Original comment by Graham.Dumpleton@gmail.com on 13 Apr 2009 at 11:09

GoogleCodeExporter commented 9 years ago

Original comment by Graham.Dumpleton@gmail.com on 13 Apr 2009 at 11:10

GoogleCodeExporter commented 9 years ago

Original comment by Graham.Dumpleton@gmail.com on 13 Apr 2009 at 11:11

GoogleCodeExporter commented 9 years ago
Regarding the shared stuff, dont know if it has to do anything with it:
http://trac.macports.org/ticket/18848

I rebuilt using   LDFLAGS =  -F/opt/local/Library/Frameworks -framework Python 
-u
_PyMac_Error  -arch i386  just for fun. Didnt work.

otool -L /opt/local/apache2/modules/mod_wsgi.so 
/opt/local/apache2/modules/mod_wsgi.so:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.3)
    /System/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility
version 2.5.0, current version 2.5.1)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

$ python2.6-config --ldflags
-L/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/conf
ig
-ldl -lpython2.6

seems to be the only LDFLAGS which I have got this to work with.

$ otool -L /opt/local/apache2/modules/mod_wsgi.so 
/opt/local/apache2/modules/mod_wsgi.so:
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/Python (compatibility
version 2.6.0, current version 2.6.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.3)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

I will be removing my macports python install this week and replace it with 
something
like this: 
http://jessenoller.com/2009/03/16/so-you-want-to-use-python-on-the-mac/  
So if you need me to try anything more, just let me know.

Late in sweden now. Good night.

Original comment by andrii...@gmail.com on 13 Apr 2009 at 11:27

GoogleCodeExporter commented 9 years ago
Didn't expect to make much difference, but worth a try.

There just seems to be something odd about how MacPorts builds their Python 
framework such that it isn't 
properly recognised by the -F/opt/local/Library/Frameworks option.

Unfortunately I can't necessarily depend on being able to use python-config as 
that doesn't exist for older 
versions of Python. Also only in Python 3.0 is it qualified by the version 
number. Ie., python3.0-config. Thus, if 
using older versions of Python and have multiple versions installed in same 
root directory, but of a guess as to 
which version of Python the single 'python-config' script applies to. For this 
reason some distributions don't even 
provide it, requiring you to installed separate 'python-dev' package.

Since the problem is only on MacOS X, what I may instead be able to do is if 
lib/pythonX.Y/config/libpythonX.Y.a 
exists then link with -L/-l. This should mean that -F/-framework would likely 
only be used on older Python 
versions such as Python 2.3 where the .a linking back to Python framework 
doesn't exist.

Now you might appreciate all the variations that have to be dealt with. :-)

Thanks for attaching the complete Makefile from config directory as tells me a 
lot.

Original comment by Graham.Dumpleton@gmail.com on 13 Apr 2009 at 11:36

GoogleCodeExporter commented 9 years ago
I guess its all up to you, personally i dont have much over for people still 
using
2.3 or 2.4. Just put a not on the docs about pythonX.Y-config and I think that 
will
be enough, since its only macports/os x thingie. But if you sort it out I think 
it
will be easier for macports to include 2.4 instead of the obsolete 1.1.... They 
have
their patches within macports, if they want to solve it they can do it. Or just 
fix
their python port :)

Original comment by andrii...@gmail.com on 13 Apr 2009 at 11:44

GoogleCodeExporter commented 9 years ago
Try using configure script from:

  http://modwsgi.googlecode.com/svn/trunk/mod_wsgi/configure

Yes I know this is file from mod_wsgi 3.0, but it does exactly the same thing 
as required in mod_wsgi 2.4 and in 
fact I just copy back the configure stuff to old versions.

Original comment by Graham.Dumpleton@gmail.com on 14 Apr 2009 at 12:46

GoogleCodeExporter commented 9 years ago
Worked! It generated this in the Makefile:

CPPFLAGS = 
-I/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 
-DNDEBUG 
CFLAGS =  -Wc,'-arch i386'
LDFLAGS =  
-L/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/conf
ig 
-arch i386
LDLIBS =  -lpython2.6 -ldl 

$ otool -L /opt/local/apache2/modules/mod_wsgi.so 
/opt/local/apache2/modules/mod_wsgi.so:
    /opt/local/Library/Frameworks/Python.framework/Versions/2.6/Python (compatibility
version 2.6.0, current version 2.6.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.3)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

Original comment by andrii...@gmail.com on 14 Apr 2009 at 7:24

GoogleCodeExporter commented 9 years ago
Fixed in revision 1291 of 2.X branch for 2.5 and in revision 1290 for 3.0 in 
trunk.

Original comment by Graham.Dumpleton@gmail.com on 14 Apr 2009 at 11:15

GoogleCodeExporter commented 9 years ago
Appears that this might not be restricted to MacPorts Python 2.6 port, as has 
affected people who have used 
normal Python 2.6 distribution as well. It doesn't seem to be universally the 
case that it will not work though.

Either way, grabbing:

  http://modwsgi.googlecode.com/svn/branches/mod_wsgi-2.X/configure

and replacing existing configure script with it in mod_wsgi 2.4 will fix the 
problem.

Original comment by Graham.Dumpleton@gmail.com on 17 Apr 2009 at 9:08

GoogleCodeExporter commented 9 years ago
This problem may not even be because of Python but because of MacOS X compiler 
tools. Seems that Python 
version built much earlier even stopped being found when mod_wsgi was 
recompiled against it. Alternatively, 
how apxs or something is passing options to linker is working differently 
because of Apache having been 
updated.

Although linking to .a seems to help, some hand built Python installations lack 
the .a. If problem experienced 
with those, would need to create symlink in Python config directory name 
libpythonX.Y.a which points at 'Python' 
framework file. X.Y should be replaced with actual version.

Original comment by Graham.Dumpleton@gmail.com on 11 May 2009 at 3:49

GoogleCodeExporter commented 9 years ago
Released mod_wsgi 2.5.

Original comment by Graham.Dumpleton@gmail.com on 11 May 2009 at 11:46

GoogleCodeExporter commented 9 years ago
Thanks! Great work!

Original comment by andrii...@gmail.com on 11 May 2009 at 11:47

GoogleCodeExporter commented 9 years ago
Further issue, although possibly affecting non MacPorts Pyuthon on MacOS X only 
that don't supply .a in 
config directory.

Namely, should have in configure.ac:

        LDFLAGS1="-Wl,-F${PYTHONFRAMEWORKPREFIX} -framework ${PYTHONFRAMEWORK}"

This was how it was a while back, but -Wl, prefix got dropped when doing some 
other changes and didn't get 
put back when those other changes were reverted.

Original comment by Graham.Dumpleton@gmail.com on 20 May 2009 at 12:23

GoogleCodeExporter commented 9 years ago
The linking using -L/-l should only be done for Python 2.6. Doesn't work for 
Python 2.5 an older when using 
standard Python source distribution.

Original comment by Graham.Dumpleton@gmail.com on 21 May 2009 at 11:59

GoogleCodeExporter commented 9 years ago
Only use -L/-l for Python 2.6 or later. Committed in revsion 1327 of 2.X for 
2.6 and 1326 of trunk for 3.0.

Original comment by Graham.Dumpleton@gmail.com on 22 May 2009 at 4:29

GoogleCodeExporter commented 9 years ago
I get this issue under Snow Leopard / mod_wsgi 2.5.  Snow Leopard has python 
2.6.1 
installed, and I have python 2.6.2 installed (under macports)  even when I 
throw the 
linking in using output from : /opt/local/bin/python2.6-config --ldflags, it 
still links 
against the Snow Leopard Python.  Thus I get those apache warnings: compiled 
for 2.6.2 
runtime 2.6.1

Original comment by aventure...@gmail.com on 5 Sep 2009 at 4:15

GoogleCodeExporter commented 9 years ago
Snow Leopard only seems to work if use -F/-framework, put the LDFLAGS in 
Makefile back as described in:

  http://groups.google.com/group/modwsgi/browse_frm/thread/f20b8af4bd94bb8d

Original comment by Graham.Dumpleton@gmail.com on 6 Sep 2009 at 4:54

GoogleCodeExporter commented 9 years ago
Because of the unpredictability due to Python installations not always behaving 
the same, have reverted to always 
linking against the Python framework if it is present.

If this causes a problem with wrong framework being picked up at run time, then 
the '--disable-framework' 
option can be supplied to 'configure' script for mod_wsgi. This will cause 
makefile to link against Python library, 
which is actually a symlink to Python framework, using -L/-l flags. In some 
cases this causes things to work 
okay.

This change made in revision 1418 of mod_wsgi trunk for 3.0.

Original comment by Graham.Dumpleton@gmail.com on 25 Sep 2009 at 1:32

GoogleCodeExporter commented 9 years ago
Change now backported in revision 1419 for mod_wsgi 2.6.

Original comment by Graham.Dumpleton@gmail.com on 25 Sep 2009 at 1:40

GoogleCodeExporter commented 9 years ago
Version 3.0 of mod_wsgi now released wuth --disable-framework option to 
'configure'. This was already 
released for 2.X branch in mod_wsgi 2.6.

Original comment by Graham.Dumpleton@gmail.com on 22 Nov 2009 at 2:49