Question

I have a project called "myplanet" and my manage.py‍ file looks like:

#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myplanet.settings")

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)

I know that I have to set a system variable DJANGO_SETTINGS_MODULE:myplanet.settings and also set the PYTHONPATH to my settings.py file. I was wondering what I should do in the case of another project that is called gMaps ? I tried to do the same but it does not simply work. My OS is Windows 7 x64

Was it helpful?

Solution

You can set up two independent virtual environments for each project. It's best practice I think. In that case you can even install different versions of python packages for each project as it required.

You can read about using virtualenv and it's wrapper here: http://virtualenvwrapper.readthedocs.org/en/latest/index.html

OTHER TIPS

You don't need to set PYTHONPATH variable environment to your django project for running that, when your settings.py is inside a package or is a module that is importable with manage.py.

The PYTHONPATH is a list of directories Python goes through to search for modules and files.

If you need to add a path of one library or your root path of project to it, you can do that in your code.

For example in manage.py with:

import sys
sys.path.append("/home/my/project")

Or:

import os
BASE_PATH = os.path.abspath(os.path.dirname(__file__))
sys.path.append(BASE_PATH + '/src/folder/of/my/project/')

And each django project has own manage.py‍ file that set DJANGO_SETTINGS_MODULE enivoronment itself, and you don't need to set that.

I think if your manage.py have this line:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myplanet.settings")

Then, you just need to have this structure for your project:

myplanet # It's a project folder
  myplanet # It's a package
    __init__.py
    settings.py
  manage.py

And you can run your project with python manage.py runserver without set PYTHONPATH environment variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top