8

Before start I have been trying to accomplish it for some time now, but I had no luck. I'm trying to create my own python package, which I will import the modules in it, in separate files in my project. I tried to add my project's directory to pythonpath via 'sys' but still the mod_wsgi do not recognize it:

import sys
sys.path.append('/var/www/')

from core.core import main

And when trying:

ImportError: No module named core.core

Any help would be appreciated

3
  • 8
    Does your package have an __init__.py file in it? Commented Dec 11, 2012 at 22:25
  • 3
    What is the file structure of your project and package? Commented Dec 11, 2012 at 22:31
  • WTF.. I'll shoot myself in the head ASAP. My package did not have __init__.py file. Thanks guys. Commented Dec 11, 2012 at 22:43

2 Answers 2

6

If you do not have the file __init__.py in your core folder, it will not be recognized as a package.

Therefore the solution is to add a file __init__.py in your core folder.

If you have already added the problem may be the absolute path ... the core folder that has absolute path:

  1. /var/www/core
  2. /var/www/YourProject/core

if the second option you have to do: sys.path.append('/var/www/YourProject')

Sign up to request clarification or add additional context in comments.

1 Comment

You have used single quote at the beginning of your last code line, and a double quote at the end of that line.
0

You need to explicitly set PYTHONPATH with you root directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.