Darknet: ImportError: dynamic module does not define init function (initdarknet)

Created on 10 Oct 2018  路  4Comments  路  Source: AlexeyAB/darknet

When I try to import darknet to use in a separate python program, I get the error in the title.

I am using OpenCV3.4.0, and compile darknet with options:

GPU=0
CUDNN=0
CUDNN_HALF=0
OPENCV=1
AVX=1
OPENMP=1
LIBSO=1

I have made sure that darknet.py is on the path:

import sys
darknet_path='/path/to/AlexeyAB_darknet'
sys.path.append(darknet_path)

This stackoverflow page suggests I might be missing an init file, or the init file might not have the correct naming conventions. One answer also suggests that I should try using a different python version. My default python version is 2.7. If I try python3, I get a different, but similar error:
ImportError: dynamic module does not define module export function (PyInit_darknet)

Am I doing something wrong, is this intended behaviour, or is there an issue with darknet?

Most helpful comment

I ended up needing two changes to make this work.

  1. renaming the shared object library (darknet_so.so) and updating the references to the so in darknet.py
  2. either running from the darknet directory, or linking those files into the directory I was running from.

All 4 comments

I had trouble until ran it from the directory that had darknet.so in it. Adding it to the path wasn't enough. I don't know why and as soon as I got it working, I didn't investigate further. I am using python3.

Thanks for the quick suggestion. I was running it from that directory when I tried the python3 example at the end of my post.

I ended up needing two changes to make this work.

  1. renaming the shared object library (darknet_so.so) and updating the references to the so in darknet.py
  2. either running from the darknet directory, or linking those files into the directory I was running from.

As a postscript: if you give the absolute path to darknet_so.so in darknet.py, you don't need to run it in the darknet directory (or link any files).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Jacky3213 picture Jacky3213  路  3Comments

jasleen137 picture jasleen137  路  3Comments

Greta-A picture Greta-A  路  3Comments

zihaozhang9 picture zihaozhang9  路  3Comments

hemp110 picture hemp110  路  3Comments