Trouble installing MXNet on Raspberry Pi 3
Environment info and background:
Raspberry Pi 3 running Raspbian version 9 stretch
On the newly installed Raspbian on a Raspberry Pi 3, followed instructions on https://aws.amazon.com/blogs/ai/build-a-real-time-object-classification-system-with-apache-mxnet-on-raspberry-pi/ to first install the prerequisites: sudo apt-get update sudo apt-get install python-pip python-opencv python-scipy python-picamera
After that, I followed the instructions to go to page https://mxnet.incubator.apache.org/get_started/install.html to install MXNet by selecting Devices and Raspberry Pi.
I followed the instructions and did the following: sudo apt-get update sudo apt-get -y install git cmake build-essential g++-4.8 c++-4.8 liblapack* libblas* libopencv* git clone https://github.com/dmlc/mxnet.git --recursive cd mxnet make
Build stopped and got an error message.
Error Message:
... /usr/bin/ld: cannot find -lcblas collect2: error: ld returned 1 exit status Makefile:322: recipe for target 'lib/libmxnet.so' failed make: *** [lib/libmxnet.so] Error 1
What have you tried to solve it?
Thought the problem was just missing a library, so did the following: pi@raspberrypi:~ $ sudo apt-get install libcblas*
Ran make again and got further (now have libmxnet.so generated). However, got another error.
New Error Message:
/usr/bin/ld: build/src/operator/tensor/la_op.o: undefined reference to symbol 'cblas_dtrsm' //usr/lib/libblas.so.3: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status Makefile:344: recipe for target 'bin/im2rec' failed make: *** [bin/im2rec] Error 1
Steps to reproduce
Will get the same error each time I run make again.
Need Help
Now, I do not know what to do. Has anyone else come across the same problem. Any suggestions for a solution?
@arank
It looks like the linker isn't finding cblas you may need to manually add the path to the makefile. Also it looks like someone may have pushed a breaking change for our ARM/Rpi build to our makefile @szha ...
How do I manually add path to cblas in the makefile?
@arank who's fixing it?
I have been poking around, looking at the makefile and trying to figure where cblas is installed. This appears to be a lot more complex than I imagined. In the meantime, I just realized that I am using the brand new Stretch version of Raspbian. Don't know if the make had ever been tested with Stretch. Could that be the reason why I have trouble with the installation?
I would follow the setup guide on mxnet.io exactly, using the Raspbian Jessie version. @szha I am currently traveling w/ no access to a Pi but I can take a look once I am back.
@arank and @szha thanks. I've just created a Jessie version and will try following the process again. Will report what I found.
You can use our docker files to build for arm, we build against or own blas.
It should work:
https://github.com/larroy/mxnet/tree/master/docker
##Okay, I got jessie running on a Raspberry Pi 3 But, when I do: pi@raspberrypi:~ $ sudo apt-get -y install git cmake build-essential g++-4.8 c++-4.8 liblapack* libblas* libopencv*
##I got the following error: Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:
The following packages have unmet dependencies: liblapack3 : Breaks: liblapack3gf E: Unable to correct problems, you have held broken packages.
How can I resolve the dependencies? I know this is not a MXNet issue as such. I am new at this. Any help is much appreciated. BTW, thanks @larroy. I am hoping the issue is with Stretch. Will have to look at your docker approach as backup plan.
Stack overflow is usually a good place to start w/ these more general questions about more general deb package management... try looking at this answer https://askubuntu.com/questions/563178/the-following-packages-have-unmet-dependencies
Found out from Sébastien Villemot [email protected] that I have correctly installed LAPACK (shared library, doc and development libraries) and also ATLAS (shared library). Issue is that I gave a wildcard (liblapack*) to apt-get, so it also tried to install virtual packages (like liblapack3gf), which no longer exists but only appears in a Breaks relationship.
So, I continued with the MXNet installation by doing:
sudo apt-get update
sudo apt-get -y install git cmake build-essential g++-4.8 c++-4.8 liblapack* libblas* libopencv*
git clone https://github.com/dmlc/mxnet.git --recursive
cd mxnet
make
However, I got the same error as when I was using Stretch version of Raspbian:
/usr/bin/ld: cannot find -lcblas
collect2: error: ld returned 1 exit status
Makefile:327: recipe for target 'lib/libmxnet.so' failed
make: *** [lib/libmxnet.so] Error 1
I was going to try loading the cblas library again but this time I got message that libcblas* or libcblas could not be found:
pi@raspberrypi:~/mxnet $ sudo apt-get install libcblas*
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libcblas*
E: Couldn't find any package by regex 'libcblas*'
pi@raspberrypi:~/mxnet $ sudo apt-get install libcblas
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libcblas
So it appears make would not work for Raspbian jessie as well. @arank, guess I will have to wait for you to take a look at the issue when you can. Thanks.
Oops, don't know why some of the text were crossed out. Please ignore. Did not mean to cross anything out.
Thanks for testing this out. I will take a look next week but in the mean time the docker based solution from @larroy should help you get around this since all the dependencies are self contained and it is built against ARMv7.
@FrancisTse8 markdown supports verbatim code blocks. I edited your comment above. Click edit again to see how it's written
Cool! @szha, thanks for the tip.
Hello @larroy, I want to try out the docker files. However, I have a few questions:
- Since I am not using docker currently, I should install docker as first step? I see that they offer a Docker CE download for Debian. Is this correct?
- To generate the image for my Raspberry Pi 3 with Raspbian, I would just need to do the following - $ docker build -f Dockerfile.build.armv7 -t ~/mxnet . Is that correct? Should I start with a new clean Raspbian or can I just delete the current mxnet directory? Do I have to remove all the installed libraries? Does it matter if I was to do it with Jessie or Stretch?
- In the Dockerfile.build.armv7, there is a line that says ENV BUILD_OPTS "USE_OPENCV=0 USE_BLAS=openblas USE_SSE=0". Since I do want to use openCV with my MXNet build, should I set the USE_OPENCV flag to 1?
- Just to make sure, in the original MXNet instructions I was following, I had to manually install some dependencies, like git, cmake, etc.. Using Dockerfile.build.armv7, all dependencies will be handled by the docker file.
Again, thanks for your help. Please also add other pointers that I might have missed from my questions.
-
Yes you should install docker either way, from the os or with docker ce
-
I would make sure the mxnet repository is clean not to have issues. Anything else doesn't matter as the build runs inside docker.
-
right, and modify the dockerfile to install opencv-dev packages
-
right, if you need something else just add it to the dockerfile
OK, I am on the Raspberry Pi 3 running jessie to try to install MXNet.
Followed the instructions on https://www.raspberrypi.org/blog/docker-comes-to-raspberry-pi/ to install docker:
curl -sSL https://get.docker.com | sh
Downloaded the appropriate dockerfile and modified it to enable openCV. See below (file renamed with .txt to attach here): Dockerfile.build.armv7.withOpenCV.txt
Verified that docker was installed and I have the the dockerfile I needed:
pi@raspberrypi:~ $ which docker
/usr/bin/docker
pi@raspberrypi:~ $ ls dockerfiles
Dockerfile.build.armv7.withOpenCV
However, when I ran the docker build, I got a permission denied error:
pi@raspberrypi:~ $ docker build -f dockerfiles/Dockerfile.build.armv7.withOpenCV -t mxnet .
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.29/build?buildargs=%7B%7D&cachefrom=%5B%5D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=dockerfiles%2FDockerfile.build.armv7.withOpenCV&labels=%7B%7D&memory=0&memswap=0&networkmode=default&rm=1&shmsize=0&t=mxnet&target=&ulimits=null: dial unix /var/run/docker.sock: connect: permission denied
Did I do something wrong or missed some kind of step?
Don't build it on the PI, build it on your desktop and just copy the mxnet library (the .so) file, then install the python package as normal
When I was running the make file, I was able to generate a libmxnet.so file. Is this the .so file you are referring to?
Since I seem to have the libmxnet.so file on the Raspberry Pi with stretch Raspbian Pi, I tried to continue following the instructions to install python bindings. However, I got the following OSerror:
pi@raspberrypi:~/mxnet $ cd python
pi@raspberrypi:~/mxnet/python $ pip install --upgrade pip
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 193kB/s
Installing collected packages: pip
Successfully installed pip-9.0.1
pi@raspberrypi:~/mxnet/python $ pip install -e .
Obtaining file:///home/pi/mxnet/python
Collecting graphviz (from mxnet==0.11.1)
Downloading graphviz-0.8-py2.py3-none-any.whl
Requirement already satisfied: numpy in /usr/lib/python2.7/dist-packages (from mxnet==0.11.1)
Requirement already satisfied: requests in /usr/lib/python2.7/dist-packages (from mxnet==0.11.1)
Installing collected packages: graphviz, mxnet
Exception:
Traceback (most recent call last):
File "/home/pi/.local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/home/pi/.local/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/home/pi/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/home/pi/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/home/pi/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/home/pi/.local/lib/python2.7/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/home/pi/.local/lib/python2.7/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/home/pi/.local/lib/python2.7/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/graphviz'
Maybe I need something else from the make process besides generating the libmxnet.so file?