I am trying to run a Program that I coded in Python in Windows environment When I am trying to copy the program and running it in Linux(Debian), It won't work,

It is giving the following error,

Traceback (most recent call last):
  File "BlackBox.py", line 26, in <module>
    from BB_Files import BB_Expand
ImportError: No module named BB_Files

Despite the presence of the file BB_Expand inside BB_Files folder, I am still getting the error.

I have also tried appending the path of my current directories in Python,

# Sub-Folders of AES are also accessible

But Still no Luck,

This is the File Structure,


this is the output of ls -l command,

drwxrwx--x 4 pe users  4096 Oct 26 21:43 BB_Files
-rw-rw---- 1 pe users 15284 Oct 26 22:04 Main.py

This is some initial code in the file,

import sys    # sys.argv ; sys.path, sys.exit
import os
import hashlib
import struct # Interpret strings as packed binary data
import getopt # for Runtime arguments
import time
from datetime import date

# Append Paths from where the Files would be Imported.
# Sub-Folders of AES are also accessible
# Sub-Fodlers of BB_Files are also accessible now (Tables)
from BB_Files import BB_Expand
from BB_Files import BB_Steps
from BB_Files import BB_Days

This is the line giving an error,

from BB_Files import BB_Expand

The program doesn't run after this line because the Python couldn't find this Module.

The same code works absolutely fine in Windows.

could anyone please help me out with this ?

  • 1
    Could you give us a minimal working example of the script? Does the user running the script have read access to the relevant folders? – terdon Oct 26 '13 at 17:29
  • Hello, I have also tried to run the code as a root, The code supposed to read a python file from the folder B'B_Files', I have directly copied the Code folder from Windows to Linux through Network Sharing so I am not sure what permissions are required for the folder. – Sufiyan Ghori Oct 26 '13 at 17:32
  • 1
    I understand, which is why I asked to see some code, it is difficult to guess otherwise. Please show us the lines that load the modules, and ls -l output of the relevant folders. – terdon Oct 26 '13 at 17:35
  • Thank you, I have added all the details you have asked for, please see the question again @terdon – Sufiyan Ghori Oct 26 '13 at 17:45
  • 2
    It looks like python is expecting a module but finding a folder instead. Does it work if you import the file name directly? Something like from BB_Expand import BB_Expand (assuming the BB_Expand method is in a file called BB_Expand.py). – terdon Oct 26 '13 at 17:55

You need to create a (possible empty) file called __init__.py in your BB_Files folder. From the docs:

The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.