ramkrishanbhatt / modwsgi

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

brew Python 3.3 installation has a broken sitecustomize.py file. #319

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When using brew Python 3.3, you will see on restart the messages:

Error in sitecustomize; set PYTHONVERBOSE for traceback:
ValueError: list.remove(x): x not in list

This is because brew sitecustomize.py file is broken and doesn't take into 
consideration that sys.prefix may not always be what it things it will. In 
particular, in an embedded system it will be different.

Specifically, brew has:

    # Fix 2)
    #   Remove brewed Python's hard-coded site-packages
    sys.path.remove('/usr/local/Cellar/python3/3.3.1/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages')

That is fine for command line brew python3, but is wrong for embedded system 
where sys.prefix will actually be:

/usr/local/Frameworks/Python.framework/Versions/3.3

and so will not match that location.

To have things work properly with this brew python3 version, you needed to set 
in the Apache configuration file:

WSGIPythonHome 
/usr/local/Cellar/python3/3.3.1/Frameworks/Python.framework/Versions/3.3

which will override the PYTHONHOME to be what brew is expecting it to always be.

Note that they appear to have possibly fixed this issue in the sitecustomize.py 
file for upcoming Python 3.4 recipe.

https://github.com/Homebrew/homebrew/blob/master/Library/Formula/python3.rb

where they now use:

          # Only do this for a brewed python:
          opt_executable = '#{opt_bin}/python#{VER}'
          if os.path.realpath(sys.executable) == os.path.realpath(opt_executable):
              # Remove /System site-packages, and the Cellar site-packages
              # which we moved to lib/pythonX.Y/site-packages. Further, remove
              # HOMEBREW_PREFIX/lib/python because we later addsitedir(...).
              sys.path = [ p for p in sys.path
                           if (not p.startswith('/System') and
                               not p.startswith('#{HOMEBREW_PREFIX}/lib/python') and
                               not (p.startswith('#{rack}') and p.endswith('site-packages'))) ]

Specifically, it is now more tolerant of sys.prefix being different as it would 
in an embedded system.

Original issue reported on code.google.com by Graham.Dumpleton@gmail.com on 29 Apr 2014 at 12:15

GoogleCodeExporter commented 8 years ago
Closing as no specific action being taken.

Original comment by Graham.Dumpleton@gmail.com on 16 Sep 2014 at 6:52