Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AndyTsangChun opened this issue Jul 10, 2017 · 7 comments
Closed

Comments

@AndyTsangChun
Copy link

AndyTsangChun commented Jul 10, 2017

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
Copy link
Owner

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

@AndyTsangChun
Copy link
Author

AndyTsangChun commented Jul 11, 2017

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
Copy link
Owner

digitalbrain79 commented Jul 11, 2017

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

@AndyTsangChun
Copy link
Author

AndyTsangChun commented Jul 11, 2017

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
Copy link
Owner

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

@AndyTsangChun
Copy link
Author

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants