Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python sys.path - appending PYTHONPATH

Tags:

python

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

like image 398
0xmtn Avatar asked Dec 11 '12 22:12

0xmtn


1 Answers

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')

like image 195
wancharle Avatar answered Oct 17 '22 03:10

wancharle