[ACCEPTED]-Python's working directory when running with WSGI and Apache-mod-wsgi
You should not change working directory.
Use:
import os
here = os.path.dirname(__file__)
The 8 variable here
will then contain the directory 7 where that code file is located. You can 6 then construct absolute paths for things 5 relative to that.
database = os.path.join(here, 'database.db')
Do note that the user your 4 code runs under in Apache still needs read/write 3 access to that directory.
As always, make 2 sure you read the documentation. Relevant 1 sections of documentation are:
I had a similar problem where I wanted to 8 use a glob() with a relative path. It worked 7 in my development environment but not on 6 the server with mod_wsgi. I discovered here that 5 there is a 'home=' option that you can add 4 to the WSGIDaemonProcess directive to set 3 the initial working directory of your application. You 2 find that in the virtual host file (on my 1 system in /etc/apache2/sites-available/mysite.conf)
While add a path to relative directory works, probably 4 you need to change lot of code.
Change home 3 from WSGIDaemonProcess works but you need 2 to set one for each vhost
reset the cwd at 1 beginning of your script:
here = os.path.dirname(__file__)
os.chdir(here)
for a quick workaround
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.