[AstroPy] Astropy in fails to import in Apache mod_wsgi Flask application

Leo Singer lsinger at caltech.edu
Wed Jul 9 16:45:40 EDT 2014


Hi,

I have a Flask application that uses astropy, and I am trying to deploy it in Apache with mod_wsgi. Here's a minimal example app.wsgi file:

    import astropy

    from flask import Flask
    app = Flask(__name__)

    @app.route("/")
    def hello():
        return "Hello World!"

    application = app

It fails to import astropy because it cannot locate the Astropy config files. Here's the traceback from the Apache log file, error.log:

/home/***/***/local/lib/python2.7/site-packages/astropy/config/configuration.py:680: ConfigurationMissingWarning: Configuration defaults will be used due to OSError:Could not find unix home directory to search for astropy config dir
  warn(ConfigurationMissingWarning(msg))
[client ***.***.***.***:*****] mod_wsgi (pid=*****): Target WSGI script '/home/***/***/var/ptf-instance/wsgi/ptftoo.wsgi' cannot be loaded as Python module.
[client ***.***.***.***:*****] mod_wsgi (pid=*****): Exception occurred processing WSGI script '/home/***/***/var/ptf-instance/wsgi/ptftoo.wsgi'.
[client ***.***.***.***:*****] Traceback (most recent call last):
[client ***.***.***.***:*****]   File "/home/***/***/var/ptf-instance/wsgi/ptftoo.wsgi", line 4, in <module>
[client ***.***.***.***:*****]     import astropy
[client ***.***.***.***:*****]   File "/home/***/***/local/lib/python2.7/site-packages/astropy/__init__.py", line 268, in <module>
[client ***.***.***.***:*****]     _initialize_astropy()
[client ***.***.***.***:*****]   File "/home/***/***/local/lib/python2.7/site-packages/astropy/__init__.py", line 250, in _initialize_astropy
[client ***.***.***.***:*****]     config.configuration.update_default_config(__package__, config_dir)
[client ***.***.***.***:*****]   File "/home/***/***/local/lib/python2.7/site-packages/astropy/config/configuration.py", line 814, in update_default_config
[client ***.***.***.***:*****]     if path.exists(cfgfn):
[client ***.***.***.***:*****]   File "/home/***/***/lib/python2.7/genericpath.py", line 18, in exists
[client ***.***.***.***:*****]     os.stat(path)
[client ***.***.***.***:*****] TypeError: coercing to Unicode: need string or buffer, NoneType found

It's running as a user without a home directory. How do I import astropy if I don't have a home directory?

Thanks,
Leo




More information about the AstroPy mailing list