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

ImportError: No module named _caffe #427

Closed
aquibjaved opened this issue Dec 5, 2016 · 20 comments
Closed

ImportError: No module named _caffe #427

aquibjaved opened this issue Dec 5, 2016 · 20 comments

Comments

@aquibjaved
Copy link

aquibjaved commented Dec 5, 2016

After doing the steps, I tried to run the demo.py
I am getting error : ImportError: No module named _caffe
But I already have installed caffe. When I try to import caffe from python terminal there's no error.

Where's the Problem?

screenshot from 2016-12-05 15-45-14

@yanxp
Copy link

yanxp commented Dec 6, 2016

You should make pycaffe

@aquibjaved
Copy link
Author

Hi @yanxp while installing I've made pycaffe.
But this is in another folder do I need to build caffe in the folder below

RCN_ROOT/caffe-fast-rcnn
# Now follow the Caffe installation instructions here:
#   http://caffe.berkeleyvision.org/installation.html

# If you're experienced with Caffe and have all of the requirements installed
# and your Makefile.config in place, then simply do:
make -j8 && make pycaffe

@eonurk
Copy link

eonurk commented Dec 7, 2016

Maybe you should do ;

export CAFFE_ROOT=/home/USERNAME/py-faster-rcnn/caffe-fast-rcnn

Note that you should change username properly!

@aquibjaved
Copy link
Author

Hi @eonurk Thank you for replying
I hit the command

export CAFFE_ROOT=/home/aquib/py-faster-rcnn/caffe-fast-rcnn

What this error mean?

screenshot from 2016-12-08 11-05-31

@HarrisXia
Copy link

hi, aquibjaved, I met the same problem as you did, do you hav solved it?:)

@aquibjaved
Copy link
Author

Hi @TJUNatsume, No I didn't get any solution.
I don't why no one is replying to this error I m still stuck at this point I also tried in another laptop I installed everything from beginning and again stuck here.

@yanxp
Copy link

yanxp commented Dec 19, 2016

@aquibjaved have you export PYTHONPATH=/path/caffe/python:$PYTHONPATH?maybe it helps.

@aseem3213
Copy link

Hi @aquibjaved and @TJUNatsume , did you guys got this issue resolved? I am also facing the same issue. In my case, error is

Traceback (most recent call last):
File "demo.py", line 18, in
from fast_rcnn.test import im_detect
File "/home/cvpr/py-faster-rcnn/tools/../lib/fast_rcnn/test.py", line 16, in
import caffe
File "/home/cvpr/py-faster-rcnn/tools/../caffe-fast-rcnn/python/caffe/init.py", line 1, in
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
File "/home/cvpr/py-faster-rcnn/tools/../caffe-fast-rcnn/python/caffe/pycaffe.py", line 13, in
from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
ImportError: No module named 'caffe._caffe'

@aquibjaved
Copy link
Author

Hi, @aseem3213 No, the problem is not solved yet, and I also stopped trying it. What I found is, Caffe module need Cuda to run, I am using AMD system with Radeon Graphics card. CUDA only support Nvidea graphics card for gpu usage.

@eonurk
Copy link

eonurk commented Jan 17, 2017

Did you guys do "make py" after making the caffe? Also check that if you installed prerequisites completely.
In addition to that, you dont have to work with your GPU. Go to Makefile.config and enable CPU mode.
Do "make clean" and then make it again.

@aquibjaved
Copy link
Author

@eonurk after making caffe mean?

@eonurk
Copy link

eonurk commented Jan 17, 2017

Maybe you can follow this link;

http://caffe.berkeleyvision.org/installation.html#compilation

@zhangpzh
Copy link

Hi ! I was also trapped into this problem... Did you guys got this issue solved ? Thanks.

@onkarganjewar
Copy link

onkarganjewar commented Feb 21, 2017

I also had the same problem. FWIW, here are the list of things that I did along with the mistakes I've made to resolve this issue:

  1. Even though I cloned the repository with --recursive flag, somehow my caffe-fast-rcnn sub-module was not updated and was not on the faster-rcnn branch; I don't know why. So, I did the step 2 from their instructions manual
    git submodule update --init --recursive

    Additionally, you should check whether you're on the correct branch (faster-rcnn) of the said sub-module.

  2. Add these lines of code at the top of your demo.py
    import sys
    sys.path.insert(0,"/path/to/caffe/python")

    Note: These lines of code should be at the start of your demo.py or it would not work (at least for me, it didn't). Also, make sure that you provide the caffe/python path correct.

  3. Make sure your PYTHONPATH and CAFFE_ROOT are correct. For example,
    $ echo $PYTHONPATH
    /home/student/objectDetection/py-faster-rcnn/caffe-fast-rcnn/python
    $ echo $CAFFE_ROOT
    /home/student/objectDetection/py-faster-rcnn/caffe-fast-rcnn

    Note: Notice, the paths are from py-faster-rcnn repository itself and not some external directory where you might have downloaded/installed the caffe by yourself. This is one of the mistakes that I did and gave the paths of the external directory instead of using their own version of caffe module.

  4. Recompile and rebuild the Caffe and pycaffe modules. Your code might work even without rebuilding caffe modules but I would strongly suggest you repeat steps 3 and 4 from the instructions manual after you've completed step 1.

Hope this helps someone and save their time. Since it definitely has cost me a significant amount of time and stress to find out the naive mistakes that I did. Cheers!!

P.S. This is my interpretation of the mistakes that I made while running the demo. I may be wrong in some of the explanations given above, I apologize if that is the case. However, these are the steps that I did and it has worked for me.

@monajalal
Copy link

I did all these with no error but I still get the error:

1205  cd caffe/
 1206  make clean
 1207  sudo make clean
 1208  mkdir build
 1209  cd build/
 1210  cmake -DBLAS=open ..
 1211  make -j8
 1212  make pycaffe
 1213  echo $PYTHONPATH
 1214  echo $CAFFE_ROOT
 1215  make install


[jalal@goku build]$ python
Python 3.5.4 |Anaconda custom (64-bit)| (default, Nov  9 2017, 00:39:12) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/scratch/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
  File "/scratch/caffe/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ImportError: dynamic module does not define module export function (PyInit__caffe)


@Sam813
Copy link

Sam813 commented Dec 11, 2017

@monajalal Hi Mona, Have you solved the issue?

@nn-ww
Copy link

nn-ww commented Dec 23, 2017

@monajalal Hi Mona, I also have the same error. Have you solved the error?

@ghost
Copy link

ghost commented Jan 24, 2018

I think problem comes when you install Caffe on your own in another folder. While cloning the faster-rcnn project, you get Caffe once again in caffe-fast-rcnn. The repository code is set in order to look for Caffe by default in that folder. So you need to remove (or rename) caffe-fast-rcnn folder and add in the env variables your caffe path (as explained by @yanxp )

@Hiker01
Copy link

Hiker01 commented Mar 14, 2019

You should make pycaffe

I make caffe with cmake, should I make pycaffe?

@who1129
Copy link

who1129 commented Feb 13, 2020

To compile the Python and MATLAB wrappers do make pycaffe and make matcaffe respectively. Be sure to set your MATLAB and Python paths in Makefile.config first!
$make pycaffe
[ 1%] Built target caffeproto
[ 98%] Built target caffe
[100%] Built target pycaffe

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