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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:51:34+00:00 2026-06-18T04:51:34+00:00

I have a module named extended.py which contains the following line: from .basic import

  • 0

I have a module named extended.py which contains the following line:

from .basic import BasicModule

and the file basic.py resides in the same directory as does __init__.py. However, when I try to run it as:

python extended.py

I get the error:

ValueError: Attempted relative import in non-package

Also adding the line:

from __future__ import absolute_import

does not solve the problem.
Maybe I am too tired to see the obvious – but I don’t see the problem here.

  • 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-18T04:51:35+00:00Added an answer on June 18, 2026 at 4:51 am

    Relative imports only work for packages, but when you importing in extended.py you are running a top-level module instead.

    The current directory may hold a __init__.py file but that doesn’t make exended.py part of a package yet.

    For something to be considered a package, you need to import the directory name instead. The following would work:

    main.py
    
    packagename\
        __init__.py
        basic.py
        extended.py
    

    then in main.py put:

    import packagename.extended
    

    and only then is extended part of a package and do relative imports work.

    The relative import now has something to be relative to, the packagename parent.

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

Sidebar

Related Questions

I have an extension module named foo.c and a utility python file utils.py which
I'm using python in virtualenv. I have following module: offers/couchdb.py : from couchdb.client import
I get the following error ImportError: No module named numeric if I have the
I have my own module named v_systems, and I'm trying to import that module
Im my Python file, I have imported the win32gui module like this: import win32gui
In Python 2.6.6, I have a module named the same as its grandparent. My
I have a module named module.py, which checks a global variable in context. module.py:
How do I achieve it? I have a module named tooltip which has a
I have the following code: class MyClass module MyModule class << self attr_accessor :first_name
I have a module Namespace/Search, which was installed when I got here. I took

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.