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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:29:43+00:00 2026-06-03T04:29:43+00:00

I have a Django structure like this (only showing libs): project/lib/ # Global libraries

  • 0

I have a Django structure like this (only showing libs):

project/lib/ # Global libraries that will be used cross apps
project/lib/global_stuff.py
project/apps/app1/lib/special_for_app1.py
project/apps/app2/lib/special_for_app2.py

Some apps don’t have a lib folder.

from apps.app1.lib import special_for_app1 works fine. But how can I import from the global lib folder when I am inside a folder already containing a local lib folder?

From inside the apps views.py file on one of the apps:


from lib import global_stuff

Gives me ImportError: cannot import name global_stuff


from .lib import global_stuff

Gives me ImportError: cannot import name global_stuff


from ..lib import global_stuff

Gives me ImportError: No module named lib


from ...lib import global_stuff

Gives me ValueError: Attempted relative import beyond toplevel package


from project.lib import global_stuff

Works, but I really dont want to be stuck with using the project name itself in the import.


Is there any way to solve this, not using the project name in the import, or changing the whole lib idea.

Or is there any other good practice to store the main part of the code?

  • 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-03T04:29:44+00:00Added an answer on June 3, 2026 at 4:29 am

    You are correct for not wanting to associate the project name with the imports, so there is a common pattern for this:

    project/
      |__/source/
      |     |__/lib/
      |     |__/app/
      |__/deployment/  # code for your production deployment maybe
      |
      |__/docs/   
      |__/tests/
      |__README
      |__requirements.txt
    

    and put /path/to/project inside your paths on your virtualenv(you use virtualenv right?).

    Then you can do inside your code

    from source.lib.blah import foo
    from source.app.baz import bar
    

    EDIT: This is only optimal if you don’t release your code as open source of course. Only when you have an internal project where the management keeps changing the name of the project 😀

    • 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
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
So I have a django project I just created called 'coolprojectsite' the directory structure
OK, I have the following directory structure (it's a django project): -> project -->
So I have installed Django on my FreeBSD 8.2 box like this: pip install
i'm creating a django application inside a virtualenv. I have a directory structure like
I'm starting on my first large django project and have realized that the default
I have written a small unit test for my django view .My project structure
I'm working on a Django project that contains a single application. The application will
I have a tree structure in memory that I would like to render in

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.