digitalbrain79 / pyyolo

Simple python wrapper for YOLO.
126 stars 65 forks source link

Import Error, AttributeError: 'module' object has no attribute 'init' #19

Closed AndyTsangChun closed 7 years ago

AndyTsangChun commented 7 years ago

I was trying to import the pyyolo wrapper from a parent directory.

However, I encounter this error File ".../pyyolo/body_detector.py", line 18, in __init__ pyyolo.init(datacfg, cfgfile, weightfile) AttributeError: 'module' object has no attribute 'init' I am aware that some path was set by the setup.py, which causing the "pyyolo" module can only be import properly within the directory.

I also used the "imp" module and found that the module outside the directory looks like >>> imp.find_module('pyyolo') (None, 'pyyolo', ('', '', 5))

While inside the directory look like (<open file '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyyolo.so', mode 'rb' at 0x1005d4a50>, '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyyolo.so', ('.so', 'rb', 3))

However, even I tried to use the "imp" module to import it with the path above still nth happens. Its there any other way I can use/import the wrapper from parent directory????

Thanks a lot!!!

digitalbrain79 commented 7 years ago

Sorry. I cannot know the reason. Could you rebuild all after removing 'build' directory?

AndyTsangChun commented 7 years ago

Rebuilt serval times, still having the same problem I tried other method of importing or path setting still not works. e.g. sys.path.insert(0, '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages') or sys.path.append("/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages") But I believes, it must be some sort of path setting problems??

digitalbrain79 commented 7 years ago

Could you share Makefile and build process? pyyolo module should be in python2.7/dist-packages.

AndyTsangChun commented 7 years ago

Attached my Makefile and build logs.

Not sure what I added in the last couple hours but the error actually changed to Couldn't open file: pyyolo_lib/cfg/coco.data

However, I believe I have the correct path to the file, cuz when I run inside the pyyolo directory os.getcwd() >> bababaMyComputer/myproject/pyyolo_lib datacfg = 'cfg/coco.data' This works fine. but when I run outside the pyyolo directory (import the example.py) os.getcwd() >> bababaMyComputer/myproject using datacfg = 'pyyolo_lib/cfg/coco.data'

====================================================

Another changes I just made is By user_paths = os.environ['PYTHONPATH'].split(os.pathsep) I found that the programs was pointing to /Library/Python/2.7/site-packages->> PATH 1 and /usr/local/lib/python2.7/site-packages ->> PATH 2

But the .so was placed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages ->> PATH 3

Although both inside or outside the directory points to the same PATH 1 & 2 only Inside the directory will finds it and works fine?? Not sure why

I have tried to cp the .so and egg-info to PATH 1 & 2, however, due to the error switched to couldn't open file:coco.data. I am not sure does it fix the path stuff yet

log.zip

digitalbrain79 commented 7 years ago

You should use absolute path when you run outside of pyyolo directory. Path is something like macOS. I'm not tested on mscOS.

AndyTsangChun commented 7 years ago

You mean I need the absolute path for the coco.data? Well I have tried that. It appear another file not found coco.names which I guess is set within the pyyolo.so? Cuz i don't find anywhere I can change it in example.py

Here is part of the code I use to select the path for the files. Just for testing with two cmd(inside and outside the directory). But I doubt this part is affecting coco.names?


cfgfile = 'cfg/tiny-yolo.cfg'
weightfile = '../tiny-yolo.weights'
ospath = os.getcwd().split('/')
if not ospath[len(ospath)-1]=='pyyolo_lib':
    datacfg = os.getcwd() +'/'+ 'cfg/coco.data'
    cfgfile = os.getcwd() +'/'+ 'cfg/tiny-yolo.cfg'
    weightfile = os.getcwd() +'/'+ 'tiny-yolo.weights'```
AndyTsangChun commented 7 years ago

Solution #21 commit# 31 add external darknet_path fix this thread