0

On ubuntu 18.04 LTS, Caffe-cpu can install by....

sudo apt-get install caffe-cpu

... but it fails when I import on python2. It can only import on python3.

How to import caffe on python2? I tried to find caffe path, and...

$python
>>>import sys
>>>sys.path.append("/~~~~")      //~~~ means every path to find "find / -name caffe"
>>>exit()
$exit

$python
>>>import caffe

... This is what I tried to import caffe on python2.7.

How to import caffe on python2.7? Thanks.

1
  • start with the basics mean 'using make'?
    – Yang
    Commented Jan 23, 2019 at 3:24

2 Answers 2

2

Looking at the requirements for the caffe-cpu package (https://packages.ubuntu.com/bionic/caffe-cpu) we can see that this package actually calls in python3-caffe-cpu. This is the Python 3 only version of the package.

I did some apt repository searches. There is no Python 2 version of this package available in Bionic. This is why you can't import it in Python 2 - it doesn't have a Python 2 pre-packaged version available for use.

Also, keep in mind Python 2 support dies out in a year's time; you should really be using Python 3 for your projects and not Python 2.

0

I found that conda has better support

$conda search caffe
Loading channels: done

Name                       Version           Build  Channel             
caffe                       1.0.0rc3     np111py27_0  pkgs/free           

caffe                       1.0.0rc3 np111py27_nomkl_0  pkgs/free           
caffe                       1.0.0rc3     np111py34_0  pkgs/free           
caffe                       1.0.0rc3 np111py34_nomkl_0  pkgs/free           
caffe                       1.0.0rc3     np111py35_0  pkgs/free           
caffe                       1.0.0rc3 np111py35_nomkl_0  pkgs/free           
caffe                       1.0.0rc5     np112py27_0  pkgs/free           
caffe                       1.0.0rc5 np112py27_nomkl_0  pkgs/free           
caffe                       1.0.0rc5     np112py35_0  pkgs/free           
caffe                       1.0.0rc5 np112py35_nomkl_0  pkgs/free           
caffe                       1.0.0rc5     np112py36_0  pkgs/free           
caffe                       1.0.0rc5 np112py36_nomkl_0  pkgs/free           
caffe                            1.0  py27h0c9280d_3  pkgs/main           
caffe                            1.0  py27h2a89de5_5  pkgs/main           
caffe                            1.0  py27h620bdfb_4  pkgs/main           
caffe                            1.0  py27h69a20d1_2  pkgs/main           
caffe                            1.0  py27h7073e3f_4  pkgs/main           
caffe                            1.0  py27h851f731_2  pkgs/main           
caffe                            1.0  py27hbab4207_5  pkgs/main           
caffe                            1.0  py27hdb41b07_3  pkgs/main           
caffe                            1.0  py35h0c9280d_3  pkgs/main           
caffe                            1.0  py35h620bdfb_4  pkgs/main           
caffe                            1.0  py35h69a20d1_2  pkgs/main           
caffe                            1.0  py35h7073e3f_4  pkgs/main           
caffe                            1.0  py35h851f731_2  pkgs/main           
caffe                            1.0  py35hdb41b07_3  pkgs/main           
caffe                            1.0  py36h0c9280d_3  pkgs/main           
caffe                            1.0  py36h2a89de5_5  pkgs/main           
caffe                            1.0  py36h620bdfb_4  pkgs/main           
caffe                            1.0  py36h69a20d1_2  pkgs/main           
caffe                            1.0  py36h7073e3f_4  pkgs/main           
caffe                            1.0  py36h851f731_2  pkgs/main           
caffe                            1.0  py36hbab4207_5  pkgs/main           
caffe                            1.0  py36hdb41b07_3  pkgs/main           
caffe                            1.0  py37h2a89de5_5  pkgs/main           
caffe                            1.0  py37h620bdfb_4  pkgs/main           
caffe                            1.0  py37h7073e3f_4  pkgs/main           
caffe                            1.0  py37hbab4207_5  pkgs/main           

$ conda search caffe-gpu
Loading channels: done
# Name                       Version           Build  Channel             
caffe-gpu                   1.0.0rc5     np112py27_3  pkgs/free           
caffe-gpu                   1.0.0rc5 np112py27_nomkl_3  pkgs/free           
caffe-gpu                   1.0.0rc5     np112py35_3  pkgs/free           
caffe-gpu                   1.0.0rc5 np112py35_nomkl_3  pkgs/free           
caffe-gpu                   1.0.0rc5     np112py36_3  pkgs/free           
caffe-gpu                   1.0.0rc5 np112py36_nomkl_3  pkgs/free           
caffe-gpu                        1.0  py27h03f526a_2  pkgs/main           
caffe-gpu                        1.0  py27h1450b91_5  pkgs/main           
caffe-gpu                        1.0  py27h16099b3_4  pkgs/main           
caffe-gpu                        1.0  py27h2b1a04e_4  pkgs/main           
caffe-gpu                        1.0  py27h37b1cb2_3  pkgs/main           
caffe-gpu                        1.0  py27h4dc7405_3  pkgs/main           
caffe-gpu                        1.0  py27h51fbcb3_4  pkgs/main           
caffe-gpu                        1.0  py27h550cbc0_5  pkgs/main           
caffe-gpu                        1.0  py27h62894bf_4  pkgs/main           
caffe-gpu                        1.0  py27h749159d_2  pkgs/main           
caffe-gpu                        1.0  py27h7b71608_4  pkgs/main           
caffe-gpu                        1.0  py27h960b796_3  pkgs/main           
caffe-gpu                        1.0  py27h999e8d7_5  pkgs/main           
caffe-gpu                        1.0  py27hdb72b7a_4  pkgs/main           
caffe-gpu                        1.0  py27hdc87d0a_5  pkgs/main           
caffe-gpu                        1.0  py27hdfd716b_2  pkgs/main           
caffe-gpu                        1.0  py27he096b04_2  pkgs/main           
caffe-gpu                        1.0  py27heda4471_3  pkgs/main           
caffe-gpu                        1.0  py35h03f526a_2  pkgs/main           
caffe-gpu                        1.0  py35h16099b3_4  pkgs/main           
caffe-gpu                        1.0  py35h2b1a04e_4  pkgs/main           
caffe-gpu                        1.0  py35h37b1cb2_3  pkgs/main           
caffe-gpu                        1.0  py35h4dc7405_3  pkgs/main           
caffe-gpu                        1.0  py35h51fbcb3_4  pkgs/main           
caffe-gpu                        1.0  py35h62894bf_4  pkgs/main           
caffe-gpu                        1.0  py35h749159d_2  pkgs/main           
caffe-gpu                        1.0  py35h7b71608_4  pkgs/main           
caffe-gpu                        1.0  py35h960b796_3  pkgs/main           
caffe-gpu                        1.0  py35hdb72b7a_4  pkgs/main           
caffe-gpu                        1.0  py35hdfd716b_2  pkgs/main           
caffe-gpu                        1.0  py35he096b04_2  pkgs/main           
caffe-gpu                        1.0  py35heda4471_3  pkgs/main           
caffe-gpu                        1.0  py36h03f526a_2  pkgs/main           
caffe-gpu                        1.0  py36h1450b91_5  pkgs/main           
caffe-gpu                        1.0  py36h16099b3_4  pkgs/main           
caffe-gpu                        1.0  py36h2b1a04e_4  pkgs/main           
caffe-gpu                        1.0  py36h37b1cb2_3  pkgs/main           
caffe-gpu                        1.0  py36h4dc7405_3  pkgs/main           
caffe-gpu                        1.0  py36h51fbcb3_4  pkgs/main           
caffe-gpu                        1.0  py36h550cbc0_5  pkgs/main           
caffe-gpu                        1.0  py36h62894bf_4  pkgs/main           
caffe-gpu                        1.0  py36h749159d_2  pkgs/main           
caffe-gpu                        1.0  py36h7b71608_4  pkgs/main           
caffe-gpu                        1.0  py36h960b796_3  pkgs/main           
caffe-gpu                        1.0  py36h999e8d7_5  pkgs/main           
caffe-gpu                        1.0  py36hdb72b7a_4  pkgs/main           
caffe-gpu                        1.0  py36hdc87d0a_5  pkgs/main           
caffe-gpu                        1.0  py36hdfd716b_2  pkgs/main           
caffe-gpu                        1.0  py36he096b04_2  pkgs/main           
caffe-gpu                        1.0  py36heda4471_3  pkgs/main           
caffe-gpu                        1.0  py37h1450b91_5  pkgs/main           
caffe-gpu                        1.0  py37h16099b3_4  pkgs/main           
caffe-gpu                        1.0  py37h2b1a04e_4  pkgs/main           
caffe-gpu                        1.0  py37h51fbcb3_4  pkgs/main           
caffe-gpu                        1.0  py37h550cbc0_5  pkgs/main           
caffe-gpu                        1.0  py37h62894bf_4  pkgs/main           
caffe-gpu                        1.0  py37h7b71608_4  pkgs/main           
caffe-gpu                        1.0  py37h999e8d7_5  pkgs/main           
caffe-gpu                        1.0  py37hdb72b7a_4  pkgs/main           
caffe-gpu                        1.0  py37hdc87d0a_5  pkgs/main         

Multiple versions of python supported.

1
  • thanks for comment, but using conda for install caffe is too slow in my machine. So I'm avoid to using it.
    – Yang
    Commented May 8, 2019 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .