Closed Ry7en closed 3 years ago
Our normal instructions for setting Raspberry Pi use Python 3.4. But it sounds like you have chosen to follow the wiki on Python 3.5 instead. These are instructions for building OpenCV on Python 3.5, not for "building python 3.5". Python 3.5 comes pre-installed on the latest Raspberry Pi Rasbian images.
Given that, yes you will use "python3" to invoke Python 3.5 interpreter and it is this version of python that has OpenCV installed, and it looks like your "import cv2" on python3 is working, so congrats - you now know how to build OpenCV from scratch on a raspberry pi. Cool.
Now for using python3 to run compiled ELL models. Let's assume you are doing our first tutorial Getting started with image classification on Raspberry Pi, then in that tutorial, wherever you see the word "python" you need to replace that with "python3". You also need to skip all the instructions on "miniconda", you are not using a "virtual python environment", instead you are using the system provided python3, so do the tutorial from a clean terminal where you have not run miniconda activation "source activate py34". Note that miniconda setup may have placed this line in your .bashrc, if so comment it out:
export PATH="/home/pi/miniconda3/bin:$PATH"
You want which python3
to return /usr/bin/python3
. Then the wrap.py command should build the right version of the ELL python wrappers that will work properly with python 3.5 interpreter, etc.
Thank you for your reply; I should also have mentioned that I deviated from the tutorial by changing the wrap target to "pi0", instead of "pi3":
python <ELL-root>/tools/wrap/wrap.py --model_file model.ell --language python --target pi0
I didn't setup miniconda as described under the section "Python 3.4 via Miniconda", or follow the steps under "OpenCV", skipping them in accordance with this guidance:
"Note: Miniconda is not available for Raspberry Pi Zero. Turns out Rasbian Stretch already comes with Python 3.5, so we only really need Miniconda to get our build of OpenCV which we use in the tutorials. On Raspberry Pi Zero you will need to jump to these instructions on how to Build OpenCV for Python 3.5"
I couldn't find
export PATH="/home/pi/miniconda3/bin:$PATH"
in my .bashrc, and which python3
returns /usr/bin/python3
as expected.
Sounds good then you only need to change this to use python3:
python3 <ELL-root>/tools/wrap/wrap.py --model_file model.ell --language python --target pi0
If I interpreted the tutorial correctly, the command
python3 <ELL-root>/tools/wrap/wrap.py --model_file model.ell --language python --target pi0
is intended to be run on a PC from an anaconda prompt; typing in "python3" in either <base>
or <py36>
mode presents me with:
'python3' is not recognized as an internal or external command, operable program or batch file.
Ah, sorry, yes this is all quite confusing. On your raspberry pi you have Python 3.5. On this device you copy the ELL wrapped model which still needs to be "compiled" on the raspberry pi to create a python callable module, but it needs to be a Python 3.5 python callable module, so your C++ build environment setup by CMakeLIsts.txt needs to change these two lines:
find_package(PythonInterp 3.4)
find_package(PythonLibs 3.4)
Change those to version 3.5, and now "python3 demo.py..." or whatever test command line you are running on the raspberry pi should now be able to load the python module you compiled.
Having followed the steps necessary to build python 3.5 on my pi zero, I noticed in the CMake configuration summary that my "packages path" differed from the one shown in the tutorial:
Choosing to finish the installation, I found that
python3 -c "import cv2; print(cv2.__version__)"
correctly answered 3.3.0, but running the tutorial.py script as required in the "Getting started with image classification on Raspberry Pi" tutorial outputted:
If I change the command to run the script from "python tutorial.py" to "python3 tutorial.py" the error differs:
Having searched the pi, a"dist-packages" folder containing "cv2.cpython-35m-arm-linux-gnueabihf.so" is located in "/usr/local/lib/python3.5/dist-packages", and not "/usr/lib/python3.5".