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

Compiled and installed from source, but cannot import caffe in python #6333

Closed
vmirly opened this issue Apr 5, 2018 · 6 comments
Closed

Comments

@vmirly
Copy link

vmirly commented Apr 5, 2018

I have installed a fresh version of caffe on Ubuntu 17.1. The compilation and installation was successful.
(Only CPU version)

I can execute caffe program in command-line, as you can see some example lines below:

caffe: command line brew
usage: caffe <command> <args>

commands:
  train           train or finetune a model
  test            score a model
  device_query    show GPU diagnostic information
  time            benchmark model execution time

  Flags from /home/vahid/caffe/tools/caffe.cpp:
    -gpu (Optional; run in GPU mode on given device IDs separated by ','.Use
      '-gpu all' to run on all available GPUs. The effective training batch
      size is multiplied by the number of devices.) type: string default: ""

However, I cannot import caffe in python (conda environment). The following error occurs:

import caffe
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/vahid/caffe/python/caffe/__init__.py", line 1, in <module>
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
  File "/home/vahid/caffe/python/caffe/pycaffe.py", line 13, in <module>
    from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, \
ModuleNotFoundError: No module named 'caffe._caffe'

I have put my pythonpath: /home/vahid/caffe/python

@Noiredd
Copy link
Member

Noiredd commented Apr 5, 2018

Please post usage, installation, or modeling questions, or other requests for help to the caffe-users list instead of Issues. This helps developers maintain a clear, uncluttered, and efficient view of the state of Caffe. Please read the guidelines for contributing before submitting an issue or a pull request.

Please attach the output of make pycaffe to your post.

@Noiredd Noiredd closed this as completed Apr 5, 2018
@vmirly
Copy link
Author

vmirly commented Apr 5, 2018

Ok thanks. I didn't find any thing related to make pycaffe in the installation documentation. I think maybe the documentation is not complete for Python installation. Now I tried it in the build directory, but it says no rule for pycaffe:

make: *** No rule to make target 'pycaffe'.  Stop.

@Noiredd
Copy link
Member

Noiredd commented Apr 6, 2018

No, for make you should be in the Caffe root directory. For now it looks like Python can find the caffe module (your path is set correctly) but it then cannot import _caffe, which would indicate that you didn't build pycaffe. Hence my question, what happens when you try to compile it. Btw, are you using make or cmake build system? It'd help to know what does the following output (assuming make and that you're in the root dir):

touch python/caffe/_caffe.cpp
make pycaffe

@vmirly
Copy link
Author

vmirly commented Apr 6, 2018

Now I tried your commands in the caffe root directory. But make pycaffe throws the following error:

Makefile:6  *** Makefile.config not found. See Makefile.config.example.. Stop.

About your question on use of cmake vs make, I used cmake as follows:

mkdir build 
cd build 
cmake .. 
make all 
make install 
make runtest

All of the aboce commands worked fine, except make runtest which complained about pycaffe

@Noiredd
Copy link
Member

Noiredd commented Apr 6, 2018

So you're using cmake build. Is the BUILD_python flag set? Are all the dependencies installed? See the original PR of the current cmake build system (#1667):

Build python interface if all required dependencies found, otherwise excluded from build automatically

@ByuWang
Copy link

ByuWang commented Mar 20, 2019

@vmirly
Hi,I have the same problem,I have run
mkdir build cd build cmake .. make all make install make runtest
successfully, but can't import caffe in anaconda python, and it said "ModuleNotFoundError: No module named 'caffe'"error
have you solved it and how ?

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

3 participants