I am using Apache + mod-wsgi.
In my httpd.conf, I am having the following additional lines at the end of file.
LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so
WSGIScriptAlias / "C:/Projects/Folder/web/"
<Directory "C:/Projects/Folder/web">
AllowOverride None
Options None
Order deny,allow
Allow from all
</Directory>
When I execute the following index.py
scripts in Windows through http://localhost/script/index.py
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Works pretty fine.
However, when I add import utils
at the first line of index.py
, I get
ImportError: No module named utils
utils.py
is same directory as index.py
Is there any additional configuration I need to set?
I try suggestion given by @dan_waterworth
import sys, os
sys.path.append(os.path.dirname(__file__))
I get no more error by importing my own module. However, when I import module which is being installed through easy_install, error happens.
File "C:/Projects/Folder/web/script\\connection.py", line 1, in <module>
import psycopg2
File "build\\bdist.win32\\egg\\psycopg2\\__init__.py", line 65, in <module>
from psycopg2 import tz
ImportError: cannot import name tz
import psycopg2
executed no problem, if this script is being executed as standalone application.
I find that I have to add a few lines to append the python path. Something like:
import sys, os
sys.path.append(os.path.dirname(__file__))
import utils
for the second part, just add additional lines for your import directories. ie:
sys.path.append([enter path here])
to find your import directories, type into an interactive python prompt:
import sys
print sys.path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With