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

  • SEARCH
  • Home
  • 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 631469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:58:07+00:00 2026-05-13T19:58:07+00:00

I am about at wits end with what should be an extremely simple issue.

  • 0

I am about at wits end with what should be an extremely simple issue. Here is the format of a simple example that I wrote to try to fix my problem. I have a folder top with __all__ = ["p1","p2"] in __init__.py . I then have sub-folders p1 and p2 with __init__.py in both of them with __all__ again defined with the names of two simple module quick1 and quick 2 with quick1 in p1 and quick2 in p2. If I import top.p1.quick1 from a script outside of top then the import works fine. However, trying to import top.p1.quick1 from quick2 gives the error
File "quick1.py", line 1, in <module>
import top.p2.quick2
ImportError: No module named top.p2.quick2

How can I import a module from another sub-package? This is supposed to work according to the python documentation as far as I can tell. Does anyone see an obvious, trivial mistake that I made?

Edit: It appears that I need to add the directory with top to my search path. I can do this temporarily by setting PYTHONPATH. However, is there a better way to do this from a distutils script?

  • 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-13T19:58:08+00:00Added an answer on May 13, 2026 at 7:58 pm

    All you describe is just fine and does not reproduce the error — here’s the simplest version I can think of:

    $ mkdir /tmp/path
    $ mkdir /tmp/path/top /tmp/path/top/p1 /tmp/path/top/p2
    $ touch /tmp/path/top/__init__.py /tmp/path/top/p1/__init__.py /tmp/path/top/p2/__init__.py
    $ touch /tmp/path/top/p1/quick1.py /tmp/path/top/p2/quick2.py$ echo 'import top.p1.quick1' > /tmp/path/top/p2/quick2.py
    $ PYTHONPATH=/tmp/path python /tmp/path/top/p2/quick2.py
    $ python -c 'import sys; sys.path.append("/tmp/path"); import top.p2.quick2'
    

    and it runs just fine. The __all__ are not relevant unless you’re using from ... import * which you aren’t (and right you are not to). As long as the parent directory of top (here, /tmp/path) is on sys.path, things will be fine; if that parent directory is not there, you’ll get an error.

    So what’s the minimal change you can make to this sequence of operations to reproduce the error you observe?

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

Sidebar

Related Questions

I'm pretty much at wits end right about now and can't seem to figure
Thinking about a Windows-hosted build process that will periodically drop files to disk to
Thinking about my other problem , i decided I can't even create a regular
Just about every piece of example code everywhere omits error handling (because it confuses
Sorry about the vague subject but I couldn't think what to put. Here's my
Consider the two following regular expression snippets and dummy HTML that it should be
Please help! I'm really at my wits' end. My program is a little personal
I must be really stupid, but I'm at my wits' end with a JPA
Sorry about the title. I do realize it's not very descriptive. :| Here is
OK, I have been looking about but can not for the wits of me

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.