# How do I add my project to 'sys.path' on windows? (trying to use disqus_export.py)

I'm trying to use the command disqus_export.py from 'django-disqus' to export my comments from django.contrib.comments to disqus.

When I use disqus_export.py in my outer project folder(where manage.py is) I get the return:

Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\disqus\management\commands\disqus_export.p
y", line 5, in <module>
from django.contrib import comments
4, in <module>
from django.contrib.comments.models import Comment
File "C:\Python27\lib\site-packages\django\contrib\comments\models.py", line 1
, in <module>
from django.contrib.auth.models import User
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 5, in
<module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 11, in <modul
e>
if DEFAULT_DB_ALIAS not in settings.DATABASES:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
self._setup()
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _set
up
raise ImportError("Settings cannot be imported, because environment variable
%s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE
TTINGS_MODULE is undefined.


As per the response in another similar question to, "Check this: python manage.py shell then import sys then sys.path. Is the project directory on that path? Exit out. Enter the regular python shell python. Then import sys, sys.path. Is the project directory on that path?,"

I did that and found that my project directory was returned by the first call but not the latter. However, the commenter who gave this instruction did not say what to do next, as the OP understood what he must do from there.

I assume I have to add my project directory to the latter sys.path, but I don't know how, so I'm hoping someone here can help me out.

-

sys.path is just a list. The following does what you'd expect:

sys.path.append('/path/to/project')


Alternatively, you could set the PYTHONPATH environment variable to your project directory (or edit it to include it, if it already exists).

-
Maybe I'm misunderstanding here. I went to 'Environment Variables' within Windows' 'System Properties' and created a 'System variable' called 'PYTHONPATH' with the value 'C:\Documents and Settings\Miles\Projects\mysite'. Nothing noticeable changed. I've previously only used the default 'path' 'System variable' so that I can run scripts/programs from the Windows 'Command Prompt', and I've created 'System variable's called 'PYTHON_HOME'(value:'\path\to\python27') and 'projects' in order to use them within the default 'path' 'System variable' like '%VARIABLE_NAME%\path\to\script_folder;'. –  Miles Bardan May 14 at 12:56
I also, first, used 'sys.path.append('C:\Documents and Settings\Miles\Projects\mysite')', which worked within that python shell instance, but I don't know how to save the changes('sys.path.save()' and 'sys.path.write()' didn't work, for example...). I try searching the answers for these questions but I really can't find anything that helps me. –  Miles Bardan May 14 at 12:57
You can't (really) make permanent changes to sys.path from within Python; if you're going that route, you should add the sys.path.append line to every source file that should know about it. I can't really help you with environment variables in Windows, because I haven't really touched that OS in about a decade. It sounds like you did every right, though. Could you verify that you can indeed see the PYTHONPATH variable from within a command prompt (echo %PYTHONPATH%)? –  Cairnarvon May 14 at 17:15
Yes, I can verify that I can echo %PYTHONPATH% from within the command prompt. I can also now see it on the sys.path from within python. Thanks very much for your assistance, it has been much appreciated. Unfortunately I am still getting the same error though, so back to the drawing board on that one... –  Miles Bardan May 15 at 13:07