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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:27:16+00:00 2026-06-11T14:27:16+00:00

How is a Python package supposed to be structured to make everything possible for

  • 0

How is a Python package supposed to be structured to make everything possible for any module inside of it?

My file structure is as follows:

Project/
    |---log/
    |   |---some logs
    |
    |---src/
        |---foo/
        |   |---__init__.py
        |   |---analyse.py
        |   |---export.py
        |    
        |---bar/
        |   |---__init__.py
        |   |---log.py
        |   |---dbhandler.py
        |   
        |---__init__.py
        |---main.py

main.py initialises everything. I want to import foo/analyse.py to bar/dbhandler.py, but I only receive an error:

AttributeError: 'module' object has no attribute 'analyse'

I’ve tried several statements:

import Project.src.foo.analyse
import src.foo.analyse
import foo.analyse
import analyse

All of them give the same error. I’ve also tried:

from .. import foo.analyse
from .. import analyse

But I received:

ValueError: Attempted relative import beyond toplevel package

I’ve gone through about fifty threads on StackOverflow and countless articles on the internet. From everything I’ve found the import src.foo.* statement should work from anywhere inside the package, if only the __init__.py file is located in each folder.

Did anyone have the same problem?

  • 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-11T14:27:18+00:00Added an answer on June 11, 2026 at 2:27 pm

    Ensure that your PYTHONPATH contains Project/src and then use

    import foo.analyse
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python package structure Hello, I'm looking to import a python file that
I'm attempting to make a python package of the following hierarchy: \standard \__init__.py \text.txt
When I'm maintaining and distributing a Python package, should I keep the MANIFEST file
I am using the csv python package to read a csv file like this:
Suppose you have the following layout for a python package ./a ./a/__init__.py ./a/_b.py inside
I am making a python package where I currently have a structure as below:
I use python 2.4.1 on Linux, and a python package written inside the company
I have the python package in Cygwin on Windows 7. However, typing python -V
I've got a python package which outputs considerable help text from: help(package) I would
I had installed the python package named requests . (pip install -i http://pip.kennethreitz.com/simple requests)

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.