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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:56:21+00:00 2026-06-09T08:56:21+00:00

Here is my current directory structure: proj/ proj/__init__.py proj/submodFolder/ proj/submodFolder/submod/ proj/submodFolder/submod/__init__.py I’m writing a

  • 0

Here is my current directory structure:

proj/
proj/__init__.py
proj/submodFolder/
proj/submodFolder/submod/
proj/submodFolder/submod/__init__.py

I’m writing a project and I would like to have import submod or even import submodFolder.submod in proj/__init__.py. However without __init__.py in submodFolder this won’t work.

Assume submodFolder is a git repository that i have sub-repoed (a third party library if you will); adding the requisite __init__.py will break the git subrepo and complicate updating libraries from their master repos.

Assuming submodFolder is an immutable git sub-repo what is the best way to push python down the dirtree to the module? Modifying the python path seemed the nearest solution to me – but none of the questions already asked assumed an immutable submodFolder.

Examples welcome, note relative paths.

  • 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-06-09T08:56:23+00:00Added an answer on June 9, 2026 at 8:56 am

    If you prefer not to modify the PYTHONPATH environment variable, you can modify sys.path inside of proj/__init__.py, the following should work:

    import sys
    import os
    sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'submodFolder'))
    
    import submod
    

    Step-by-step code with comments, so it makes a little more sense:

    # get absolute path to proj/__init__.py
    script_path = os.path.realpath(__file__)
    
    # strip off the file name to get the absolute path to proj
    proj_path = os.path.dirname(script_path)
    
    # join on os.sep to get absolute path to proj/submodFolder
    submod_path = os.path.join(proj_path, 'submodFolder')
    
    # add the complete path to proj/submodFolder to sys.path
    sys.path.append(submod_path)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

folks, I have the directory structure like this: webapps |-- static_media |-- django |---project
Here is my maven project structure ProjectParent -Class1 -Class2 -Module1 (another sub directory) --Module1Class1
Here's my current situation: I have a NSMutableArray named dictKeyArray which I assign a
Here is my current setup. I have two pages running on the jquery mobile
Here is my current situation; I am a near complete regexp illiterate, and have
Consider the path ./images/1.png Here ./ means current directory.. ie. single dot in path
I would like some help in setting up a project in SVN with regards
Here's my current Active Directory search filter: deSearch.Filter = (&(objectClass=user)); how do I modify
My current directory structure is as follows: C:\xampp\htdocs\PHP_Upload_Image_MKDIR In other words, the following directories
Here is the current code in my application: String[] ids = str.split("/"); When profiling

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.