Blazing Code
Blazing Code

Reputation: 25

Unable to import subpackage from parent package

I'm working on a project in which I have subpackages that the main package needs to import however said subpackage cannot be found by the python interpreter for some reason. After scouring the internet I was unable to find any solutions to my problem though I might add there were many problems concerning python's import system none provided me with any useful information. Here is my traceback upon running a simple script I made after globally installing my package with setup.py:

Traceback (most recent call last):
  File "lab_test.py", line 1, in <module>
    import Lab
  File "/usr/local/lib/python2.7/dist-packages/Lab-0.7.0-py2.7.egg/Lab/__init__.py", line 1, in <module>
    import shutil, argparse, sys, Tasks, Utilities, C
ImportError: No module named C

Here is my project structure:

project structure

and here is the treacherous import statement, I'd like to add that I've also tried using the from syntax but that has also failed (it resides within Lab/__init__.py):

import statement

any help provided is much appreciated and if there is any more information I can provide I'd be glad to.

Upvotes: 0

Views: 259

Answers (1)

Blazing Code
Blazing Code

Reputation: 25

Ok. So answering my own question is kinda stupid but if anyone happens to make the same mistake as me then I hope this is useful.

basically when my package was being built in my setup file it was only building the main package and not the subpackage. Therefore adding this extra parameter to the packages part of the setup function solved my problems and I was able to install the entire package and utilize it without any problems.

solution

Upvotes: 1

Related Questions