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 7034239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:09:41+00:00 2026-05-28T01:09:41+00:00

I have a python project that is like this : py/ main.py __init__.py myapp/

  • 0

I have a python project that is like this :

py/
   main.py
   __init__.py
   myapp/
           __init__.py
           my/
                __init__.py
                exam.py
           sub/
                __init__.py
                index.py

and my file contains :
main.py :

from myapp.sub.index import *
cd = myc()
cd.doit()

exam.py –>

class myclass():
  def hel(self):
     print 'Hello world'

index.py –>

from myapp.my.exam import myclass
class myc():
      def doit(self):
          mycc = myclass()  
          mycc.hel() 

I use fedora and when I use command:

python main.py

prints Hello world, but when I want to start main.py in my browser with apache and mod_python this error appears:

File "/var/www/html/py/main.py", line 1, in <module>
  from myapp.sub.index import *

ImportError: No module named myapp.sub.index

Isn’t relative import work in mod_python? what is the problem and what should I do?

  • 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-28T01:09:42+00:00Added an answer on May 28, 2026 at 1:09 am

    I looks like the PYTHONPATH environment variable isn’t correctly set when executing the module under mod_python.

    A workaround to the problem, using the directory structure described in the question, would be to add this to main.py file:

    import sys, os
    sys.path.insert(0, os.path.dirname(__file__))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python project with this directory structure and these files: /home/project_root |---__init__.py
We have a python project that we want to start testing using buildbot. Its
I have a small project that basically a Python wrapper to a websites API.
I need to have an at-home project now that I'm working on Python/Django at
I say project file in the loosest sense. I have a few python projects
Requirements : I have a Python project which parses data feeds from multiple sources
I have this large C++ project that I need to build on a platform
I have a project in Python 2.6 and I'd like to write a utf-8
I have a main.cpp like so: #include <boost/python.hpp> const char* greeting() { return Hello
I have a small web.py Python application that I would like to serve under

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.