Skip to content Skip to sidebar Skip to footer

Unable To Load A Python Package Via A File

I am trying to load a file having these contents: import os, sys sys.path.append('/opt/graphite/webapp') os.environ['DJANGO_SETTINGS_MODULE'] = 'graphite.settings' import django.c

Solution 1:

Your problem is likely going to be because mod_wsgi is compiled for and bound to a different Python version/installation than you intend to use. It therefore isn't looking at the spot where you installed all your packages.

What Python version are you wanting to use and what do you get for:

import sys
print(sys.version_info)
print(sys.prefix)

when running that from the interpreter.

Then work out what version of Python mod_wsgi is using:


UPDATE 1

To check where the django module is coming from normally from command line Python, so you can see whether you are using the same Python installation as mod_wsgi is compiled for and using, you would in the interpreter do:

>>> import django
>>> print django.__file__
/some/path/lib/python2.7/site-packages/django/__init__.pyc

Modules should have the __file__ attribute, with the exception of builtin modules which are static linked into the Python binary.

So the django module must have one.


Solution 2:

Your are probably loading the /opt/graphite/conf/graphite.wsgi through a webserver or something. Can you show us what you do when you get this error.

Have you checked /opt/graphite/conf/graphite.wsgi is executable ?

chmod +x /opt/graphite/conf/graphite.wsgi

The import of import django.core.handlers.wsgi is working fine. But thats not where the error is located. The actual error is, that whatever you are using cannot load the file /opt/graphite/conf/graphite.wsgi as python module not any django module.


Solution 3:

Being new to Python but having recently done battle with Netbeans trying to figure out why a java module was loading wrong, I learned that multiple java versions exist on my Ubuntu 14.04 box. For example, ~$ whereis python -- told me of multiple locations ~$ which python -- gave me /usr/bin/python

So, could your IDE be using a different python? One that, in the terminal, finds the path but not in the IDE?


Post a Comment for "Unable To Load A Python Package Via A File"