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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:54:55+00:00 2026-06-14T08:54:55+00:00

I always struggled with Python package import. I searched the web, but wasn’t able

  • 0

I always struggled with Python package import. I searched the web, but wasn’t able to find an appropriate answer.

I have the following directory structure:

.
./__init__.py
./packages/
./packages/__init__.py
./packages/package
./packages/package/__init__.py
./packages/package/module.py

The module.py source contains only one line:

import package

If I go to “packages” directory, I am able to import package:

>>> import python
>>>

If I go to “.” directory, I would like to import the module (or the package) as follow:

>>> import packages.package.module as module

but i’m getting the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "vendor/package/module.py", line 1, in <module>
    import package
ImportError: No module named package

What do I need to put in the __init__.py files, so I can do the above import?
More, what do I need to put in ./__init__.py file, so I will able to import my project from ../ directory?

If possible, I would like to solve this problem without changing the sys.path variable.

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

    When running the program from . all imports have to be relative to that directory. For your module.py file that means that you have to do

    import packages.package
    

    instead of

    import package
    

    This is because python will use . as the base for all imports that you do in your program. Without a lot of magic it is not possible to import something from a parent directory, so you will have to do an absolute import as shown above.

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

Sidebar

Related Questions

Recursion is something I have always struggled with understanding. I hope I can get
I have always struggled with those comboBox properties DisplayMemberPath SelectedValue SelectedValuePath I am building
I have always struggled designing css forms, I can never get the input and
Possible Duplicate: Plain English explanation of Big O I have always struggled to calculate
I'm a budding web designer and do not always struggle with realizing my design
I always use preg_match and it always works fine, but today I was trying
My (rather small) company develops a popular Windows application, but one thing we've always
I've implemented two REST services: Twitter and Netflix. Both times, I struggled to find
I've always struggled with RegEx so forgive me if this may seem like an
I'm sure this has to do with scope, but I always seem to struggle

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.