Pycaffe: Error in "import caffe"

3,012 views
Skip to first unread message

Prasanna Date

unread,
Jun 9, 2015, 9:40:33 PM6/9/15
to caffe...@googlegroups.com

I'm trying to run Caffe in it's Python interface. I've already run the command make pycaffe in the caffe directory and it worked fine. Now, when I run the command import caffe in the python environment in the terminal (Ubuntu 14.04), I'm getting the following error:


    >>> import caffe
    Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/home/pras/caffe/python/caffe/__init__.py", line 1, in <module>
      from .pycaffe import Net, SGDSolver
     File "/home/pras/caffe/python/caffe/pycaffe.py", line 11, in <module>
      import caffe.io
    ImportError: No module named io

I tried to search my computer for 'caffe.io' but couldn't find any file by that name. Any idea why this error is occurring and how to correct it?

Christopher Catton

unread,
Jun 9, 2015, 11:26:23 PM6/9/15
to caffe...@googlegroups.com
try to
1) make pycaffe
2) run "export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH" as the installation instructions specify

Prasanna Date

unread,
Jun 9, 2015, 11:40:35 PM6/9/15
to caffe...@googlegroups.com
Thanks for the reply Christopher.
1. make pycaffe runs perfectly fine when run in the caffe directory. In fact, when I run it now, it says "Nothing to be done for 'pycaffe'".
2. The path already exists in PYTHONPATH. When I run the command "echo $PYTHONPATH", I get the following output:
     /home/pras/caffe/python:/path/to/caffe/python::/home/pras/caffe/python:/home/pras/caffe/python/caffe

What about the caffe.io? Why isn't "import caffe" able to find it?

Christopher Catton

unread,
Jun 9, 2015, 11:45:49 PM6/9/15
to caffe...@googlegroups.com
What branch are you on? Try cleaning up PYTHONPATH to only be /home/pras/caffe/python.

Prasanna Date

unread,
Jun 10, 2015, 12:02:29 AM6/10/15
to caffe...@googlegroups.com
Cleaned it up. The error still persists. Please have a look at the following:

pras@Pras-Inspiron-N5010:~$ echo $PYTHONPATH
:/home/pras/caffe/python
pras@Pras-Inspiron-N5010:~$ cd caffe
pras@Pras-Inspiron-N5010:~/caffe$ make pycaffe
make: Nothing to be done for `pycaffe'.
pras@Pras-Inspiron-N5010:~/caffe$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Christopher Catton

unread,
Jun 10, 2015, 1:35:15 AM6/10/15
to caffe...@googlegroups.com
Did you build the project using CMake or just Make?

Prasanna Date

unread,
Jun 10, 2015, 11:50:39 AM6/10/15
to caffe...@googlegroups.com
I had built it using Make.

Christopher Catton

unread,
Jun 10, 2015, 1:52:48 PM6/10/15
to caffe...@googlegroups.com
I've only ever used CMake to build caffe and I would recommend you to give it a shot. Just using make may locate the pythonpath somewhere else and you may additionally have to modify the Makefile.config file.

Ismail ismail

unread,
May 13, 2016, 10:12:36 AM5/13/16
to Caffe Users
Dear Mr.Catton.

I am new in this field. I have a same problem. 
AttributeError: module 'caffe' has no attribute 'io'.
based on http://caffe.berkeleyvision.org/tutorial/interfaces.html#python

How to compile pycaffe in anaconda or python. Thanks you in advance.

Ismail

Renie Well

unread,
Jul 29, 2016, 10:07:48 AM7/29/16
to Caffe Users
Hi Date, I have the same problem with you, have you solve it?  

在 2015年6月10日星期三 UTC+8上午9:40:33,Prasanna Date写道:
Reply all
Reply to author
Forward
0 new messages