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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:04:37+00:00 2026-05-24T00:04:37+00:00

Relative import not working properly in python2.6.5 getting ValueError: Attempted relative import in non-package.

  • 0

Relative import not working properly in python2.6.5 getting “ValueError: Attempted relative import in non-package”.

I am having all those __init__.py in proper place.

  • 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-24T00:04:38+00:00Added an answer on May 24, 2026 at 12:04 am

    I have seen that error before when running a script that is actually inside a package. To the interpreter, it appears as though the package is not a package.

    Try taking the script into another directory, putting your package inside your pythonpath, and import absolutely. Then, relative imports inside your package will work. NOTE: you can STILL not relatively import inside the end script – the easiest thing to do in this case is to make a “wrapper” script, that simply calls some entry point in your package.

    You can go even further here by using setuptools to create a setup.py for your package, to make it distributable. Then, as a part of that, entry points would allow you to autogenerate scripts that called your package’s code.

    EDIT:

    From your comment, it appears as though I wasn’t quite clear. I’m not 100% sure of your directory structure because your comment above wasn’t formatted, but I took it to be like this:

    PythonEvent/
        main.py
        __init__.py
        DBConnector/
            __init__.py
            connector.py
        service/
            __init__.py
            myservice.py
    

    When in myservice.py you have the line from ..DBConnector.connector import DBUpdate, the interpreter tries to import it relatively, UNLESS you are running myservice.py directly. This is what it appears you are doing.

    Try making another dummy script outside of PythonEvent/ that is simply as follows:

    from PythonEvent.service import myservice
    
    if __name__ == '__main__':
        myservice.main() # or whatever the entry point is called in myservice.
    

    Then, set your PYTHONPATH environment variable to point to the parent directory of PythonEvent/ (or move PythonEvent/ to your site-packages).

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

Sidebar

Related Questions

Having a relative path, how do I turn it into an absolute one from
Usage of relative imports in Python has one drawback; you will not be able
I'm having an issue with MSBuild 4.0 not resolving a path correctly in one
I have a Python package with several subpackages. myproject/ __init__.py models/ __init__.py ... controllers/
I'm running into an import issue that as a relative newcomer to the Objective-C/C++/XCode
I am having problem with the coordinates not being exactly correct after the rotation
My relative is studying programming and has a hard time understanding classes. He has
Given an absolute or relative path (in a Unix-like system), I would like to
What are the relative merits of the xdoc and apt formats for writing websites
How to get the relative path in t sql? Take for example a .sql

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.