Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3342226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:48:50+00:00 2026-05-18T00:48:50+00:00

When installing django-piston from the bitbucket repo with pip, I noticed something weird (first

  • 0

When installing django-piston from the bitbucket repo with pip, I noticed something weird (first indented line of the output):

$ pip install hg+http://bitbucket.org/jespern/django-piston
Downloading/unpacking hg+http://bitbucket.org/jespern/django-piston
Cloning Mercurial repository http://bitbucket.org/jespern/django-piston to /tmp/pip-v1h8Sh-build
Running setup.py egg_info for package from hg+http://bitbucket.org/jespern/django-piston
Installing collected packages: django-piston
Running setup.py install for django-piston
    Skipping installation of [venv]/lib/python2.6/site-packages/piston/__init__.py (namespace package)
    Installing [venv]/lib/python2.6/site-packages/django_piston-0.2.3rc1-py2.6-nspkg.pth
Successfully installed django-piston
Cleaning up

Pip won’t install piston’s __init__.py, indicating that this is because ‘piston’ is specified as one of the namespace_packages in the setup.py.

Further, when I looked inside the “django_piston-0.2.3rc1-nspkg.pth” file, I find this, what seems to be an attempt at “virtual packages”:

# File: [virtualenv]/lib/python2.6/site-packages/django_piston-0.2.3rc1-py2.6-nspkg.pth
# Originally all on one line; broken apart here for readability.

import sys,new,os;
p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('piston',));
ie = os.path.exists(os.path.join(p,'__init__.py'));
m = not ie and sys.modules.setdefault('piston',new.module('piston'));
mp = (m or []) and m.__dict__.setdefault('__path__',[]);
(p not in mp) and mp.append(p)

I can see what it’s doing here; it’s basically creating a “fake module”, where piston should be, which essentially aggregates all of piston’s sub-modules.

This seems to work fine for command-line work (I can import piston from the django shell [though its repr is <module 'piston' (built-in)>], and things seem to work fine from runserver.), but my project, running on apache mod_wsgi, throws a 500 error on every page, because there’s “No module named piston.handler”.

I’ve ruled out python path issues; the site-packages dir is in the path for all attempts. I don’t know any other reasons why it would behave like this, any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:48:50+00:00Added an answer on May 18, 2026 at 12:48 am

    After looking some more, I discovered the answer in the docs for mod_wsgi:

    As an additional step however, the WSGI script file described in the instructions would be modified to overlay the virtual environment for the application on top of the baseline environment. This would be done by adding at the very start of the WSGI script file the following:

    import site
    site.addsitedir('/usr/local/pythonenv/PYLONS-1/lib/python2.5/site-packages')
    

    Note that in this case the full path to the ‘site-packages’ directory for the virtual environment needs to be specified and not just the root of the virtual environment.

    Using ‘site.addsitedir()’ is a bit different to simply adding the directory to ‘sys.path’ as the function will open up any ‘.pth’ files located in the directory and process them. This is necessary to ensure that any special directories related to Python eggs are automatically added to ‘sys.path’.

    Adding the site.addsitedir call to my wsgi script (in place of appending to sys.path, as I had been doing) cleared up all the issues.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.