tags:

views:

221

answers:

2

I run into this problem pretty consistently... keep in mind I am quite new to Django and a total Python amateur.

It seems that, for example, whenever I check out my Django project on a new computer after a clean install of Python and Django, it can never find the project/apps I create or copy in.

So right now I have an app that is working, and I downloaded a 3rd party Django module and installed it into my app directory, include it in my settings, and the web server quits because it cannot find the module.

This is the first time I've imported an third party module. In the past when it couldn't find modules I created, I would just rename the folder and run "manage.py startapp appname", delete the folder it created, and name my original folder back, boom, problem solved...

But that's obviously a hack, I am wondering if anyone can explain the the heck is going on here and how best to approach it.

I can't be the only one who has run into this, but I couldn't find any other questions on this site that seemed to match my issue.

Happens on both OS X and Windows 7.

A: 

Your third party django module should be searchable by PYTHONPATH, because django module is no other than a python module. Now there are two ways to do this:

  1. Create a folder (anywhere you want), put your third party django module under there. Now set that directory to environment variable $PYTHONPATH e.g (on Linux box):

    export PYTHONPATH = /home/me/pythonmodules/

  2. Create a folder (anywhere you want), put the third party django module under there. Now if you are on Unix box, create a symlink to that directory to python site-packages. Use this command to find out where your python site packages is:

    python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

jpartogi
Would a symlink be known as an "Alias" in OSX?
Jasconius
There's also an ln command in OSX to create symlink.
jpartogi
+1  A: 

They way Django works is pretty much how Python works. At default the folder you create when you run django-admin.py startproject name is added to your python path. That means that anything you put into there you can get to. But you have to mind that when you write the app into the installed app list. If you have an app at project/apps/appname, you would have to write 'app.appname' in the installed apps list.

Now there are some ways to go about adding 3rd party apps located somewhere else to your project. You can either add them to your python path, put in your python path, or make a link to your python path. However, you can also add a sys.path.insert(...) in your manage.py file where you add the folder of your liking to your python path. Doing this will allow you to add folders to your python path for that project only, and will keep your python path more clean.

googletorp
This seems like the right direction. I have /users/me/desktop/apps/Inside of /apps/ I have/mainApp/ and /thirdPartyApp/I tried adding both /users/me/desktop/apps/ and /users/me/desktop/apps/thirdPartyApp/ to the manage.py directive and neither had any effect. I also checked my installed apps syntax and tried both thirdPartyApp.submodulename and apps.thirdPartyApp.submodulenameand none of these seemed to have any effect... OS X might be stupid, I'll try it on Windows tonight.
Jasconius