Opened 17 years ago

Closed 17 years ago

#4296 closed (fixed)

PYTHONPATH in mod_python documentation confuses almost everybody

Reported by: anonymous Owned by: Jacob
Component: Documentation Version: dev
Severity: Keywords: mod python, pythonpath
Cc: dev@…, knutin@…, Graham.Dumpleton@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

http://www.djangoproject.com/documentation/modpython/

It says:

PythonPath "path/to/project + sys.path"

But if you SetEnv DJANGO_SETTINGS_MODULE project.settings, it throws this error:

EnvironmentError: Could not import settings 'project.settings-vatle.midgard' (Is it on sys.path? Does it have syntax errors?): No module named project.settings-vatle.midgard

The docs should say that the PythonPath should be the path to the parent dir of your project.

I don't know if this makes much sense, I'm new to django and python. It caused me some head-aches, but someone very helpful at #django pointed me in the right directon.

Thanks for all the great work!

Attachments (2)

django-modpython.diff (1.1 KB ) - added by knutin@… 17 years ago.
Patch to docs/modpython.txt
modpython.diff (585 bytes ) - added by Simon G. <dev@…> 17 years ago.

Download all attachments as: .zip

Change History (14)

comment:1 by knutin@…, 17 years ago

Forgot my email:

knutin@…

:-)

comment:2 by Chris Beaven, 17 years ago

Cc: knutin@… added
Triage Stage: UnreviewedAccepted

comment:3 by Chris Beaven, 17 years ago

Thanks for the report. You're right, this should be mentioned.

If you feel up to it, why not try your hand at providing a patch? Ask on #django if you need help with this.

by knutin@…, 17 years ago

Attachment: django-modpython.diff added

Patch to docs/modpython.txt

comment:4 by Jacob, 17 years ago

Resolution: duplicate
Status: newclosed

Fixed; this is a dup of #3842.

comment:5 by knutin@…, 17 years ago

Has patch: set
Resolution: duplicate
Status: closedreopened

This is not a dup of #3842.

The patch I uploaded was applied and the problem this ticket adressed, got solved.

With your latest change, the text that caused problems got changed back to the original state before my patch.

The problem as stated in the ticket description, is that

PythonPath "['/path/to/project] + sys.path" 

tricks those new to django and python into thinking they have to use the path to their project, and *not* the parent dir as it should be:

PythonPath "['/your/python/path'] + sys.path"

Please have a look at the patch that I attached. I hope you will merge these changes.

comment:6 by anonymous, 17 years ago

Just chiming in that we get this sort of question on IRC all the time. While I don't think "/your/python/path" is any less confusing (it's already called PythonPath!), there should definitely be a note explicitly saying that the PythonPath should point to the parent directory of the project.

comment:7 by Graham.Dumpleton@…, 17 years ago

There is more wrong with the descriptions in the mod_python setup page than you think. Although the parent directory is always required to allow settings file to be picked up, in some cases the site directory also needs to be added to PythonPath. For an analysis of this see Django user list discussion at:

http://groups.google.com/group/django-users/browse_frm/thread/24deb095a2b2e450/1c982558d464017a

Thus, not just a simple case of changing what example path is shown as explanation of when to set PythonPath to needs to be changed as well as example of what it is set to.

comment:8 by anonymous, 17 years ago

Cc: Graham.Dumpleton@… added

I agree with Graham that if the set of circumstances is known that causes the "two entries in PythonPath" problem to arise that it should be documented (or Django should automagically work around it). I'd also like to see a 'real world' example of setting PythonPath since neither /path/to/project nor /your/python/path make it clear to me actually what I'm trying to achieve. I think explicitly making reference to the ViewDoesNotExist exception and using the "two entries" technique to solve it would also reduce the overall quantity of pain and suffering in the world.

Sadly I am new to both Django and Python and don't really feel I can contribute a better solution. I'm trying to get better :)

by Simon G. <dev@…>, 17 years ago

Attachment: modpython.diff added

comment:9 by Simon G. <dev@…>, 17 years ago

Cc: dev@… added
Summary: Wrong path in mod_python documentationPYTHONPATH in mod_python documentation confuses almost everybody

This still seems to be confusing people (#5004 was a dupe). I've attached an updated patch - can other people (Graham?, knutin@..?) check this and see if there's anything else to add here.

comment:10 by Simon G. <dev@…>, 17 years ago

Patch needs improvement: set

comment:11 by Paul Bx <pb@…>, 17 years ago

Patch looks good. I'd change "should be" to "should include", since $PYTHONPATH often (as in the example) includes more than one directory.

People are still tripping over this. I think it's better to get this (much improved) wording into the docs than to succumb to a bikeshed discussion about the fine points. It can always be expanded later but this takes care of the most common point of confusion.

comment:12 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: reopenedclosed

(In [5896]) Fixed #4296 -- Added more explanation around the PythonPath directory setting. Based on contributions from a cast of thousands (Simon Greenhill, Paul Bissex, Graham Dumpleton, ...). Thanks, all.

Note: See TracTickets for help on using tickets.
Back to Top