0

I have Django installed inside of my project directory for a special project, but the imports are looking for Django to be placed somewhere within wherever python is loaded on my system, but django is situated in

Projname/django

While my apps are in (manage.py is also here) Projname/apps/

And the individual app directory would look more like: Projname/apps/individualapp

My settings files are in: Projname/apps/settings

Based on some reading here on SO, I thought doing this inside of my __init__.py files within each individual app would have worked, but didn't (plus, there are quiet a few apps):

import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'django')))

I'm pretty new to this, so a solution would be great.

user2899444
  • 313
  • 1
  • 3
  • 15

2 Answers2

0

You need to add your "projname" directory to your system's Python Path in order for Python to find packages installed inside it. It looks like you're trying to do that with the code you're adding to __init.py__, but that's the hard way to do it - instead of adding every directory's path individually, you can just add the top level directory once.

If you're using Linux or Mac, put a line like this in your .bashrc or whatever shell configuration file you use:

export PYTHONPATH=$PYTHONPATH:/path/to/projname

Note that the directory you add to the Python Path needs to be a Python package directory, with an __init.py__ in it. If it's not, create an __init.py__ in your "projname" directory.

Edward
  • 5,942
  • 4
  • 38
  • 55
0

.bashrc didn't do the trick, but I think I fixed it based on this answer from another SO post:

https://stackoverflow.com/a/13359322/2899444

Community
  • 1
  • 1
user2899444
  • 313
  • 1
  • 3
  • 15