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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:47:30+00:00 2026-06-07T14:47:30+00:00

I am experimenting with python, mostly troubleshooting other people’s code. I am trying to

  • 0

I am experimenting with python, mostly troubleshooting other people’s code. I am trying to get a program to run, “path\folderA\program.py“.

I am running the program from path\folderA

I am getting an error:

ImportError: No module named fff.ggg.ppp

program.py contains an import:

from fff.ggg.ppp import mmm

In the folder “path\folderB” there are:
“path\folderB\fff\__init__.py”
“path\folderB\fff\ggg“

folder ggg also contains __init__.py, as well as program ppp.py

From reading other posts, like Python error "ImportError: No module named" I understand that having the __init__.py makes a folder a “package” which makes imports from it possible – but it doesn’t work, since I am getting an error.

This has been working for other people that worked with these projects, so there is something wrong with my setup.

I read something about the directories having to be in the sys.path. Does that mean I have to add them to the environment variable path ? That would mean adding a lot of directories to the PATH though, so it can’t be.

So I also found the following:

import sys
sys.path.append( <path to FolderB> )

But that means changing the code (which has not been necessary for other people) and hard-coding a path to what it is on my local machine – which I shouldn’t have to, right ?

I can’t visualize it – apparently I am not supposed to change the code and hard-code the physical path to the import module – so how can a program from folderA even know to look in folderB for an import ?

How does the magic of __init__.py work ?

  • 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-07T14:47:31+00:00Added an answer on June 7, 2026 at 2:47 pm

    I can’t visualize it – apparently I am not supposed to change the code
    and hard-code the physical path to the import module – so how can a
    program from folderA even know to look in folderB for an import ?

    You are correct. Somehow you have to tell python to look for imported modules in folderB. There is no __init__.py magic that lets you import from other folders on your hard drive.

    Usually, if you’ve got various different python packages like that, they work by being installed into python’s library. That way they can imported from anywhere. This is usually accomplished by a setup.py script. Check if folderB has one. Run it with python setup.py install.

    If that doesn’t work, we’ll need more information about how this code is structured.

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

Sidebar

Related Questions

I'm trying to learn python and have encountered some strange behaviour. I am experimenting
I'm experimenting with the Datetime module in Python and decided to make a program
I am trying to write a program to check that some C source code
I'm experimenting with Python's with statements, and I've found that in the following code
I'm experimenting with the zipfile module of python the code i currently use is
I am experimenting with several languages (Python, Ruby...), and I would like to know
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
I was experimenting with shell functions the other day, with the objective of overriding
Hi I recently started experimenting with python currently reading Think like a computer scientist:
I'm interested in experimenting with embedding Python in my application, to let the user

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.