<< return to Pixycam.com

ModuleNotFoundError: No module named 'pixy'

Hi, I am trying to get the demos for the python API working but get the this error.

pi@GIP:~/pixy2/build/python_demos $ python3 get_lines_python_demo.py
Traceback (most recent call last):
File “get_lines_python_demo.py”, line 2, in
import pixy
ModuleNotFoundError: No module named ‘pixy’

I’ve followed the guide here

It explains this exact error, but I don’t understand from where I have to copy the library…

So, my question is, where do I find those _pixy.so and pixy.py files?

Hello,
Please try rebuilding (run build_all.sh) and see if it reports any errors so we can narrow things down.

Edward

Hey Edward,
Thanks for your reply.

I ran the script and the python demos failed.

Here is a screenshot of the part that failed

(The part where the error is.)
image

The full output in form of a .txt is available here: https://we.tl/t-l79ETbpmlm (WeTransfer link, since I can’t attache a file)

Isaak

Yeah, I am having the same exact issue. I don’t know what to do; I’ve spent all day trying to get it to work.

I’ve tried different python versions, deleting all pixycam related files and starting over, I even wiped my raspberry Pi completely. Any possible solution would be helpful.

Yeah, I have been struggling with this for quite some time now. But I have to demonstrate my robot in 4 days and have to get it working… (school project)

So the first error is (I think) a missing python wrapper file? .cxx has something to do with a C file? But the name suggests it has to do with the wrapper? -> “pixy_wrap”

I don’t know enough about it to really understand this error…

Isaak

@Essjay I’ve got mine working now!

Let me explain how I think I went wrong.
First I followed this guide. They don’t tell you to download those swig things here.
Then I found this guide. Here you have to download those swig things. BUT I already built everything through the previous guide. So I was left with that error.
(I can’t really explain it because I don’t quite understand it myself.)

But I do think I know how to fix it. (Knowing this that you have tried many things and so have already installed all packs)

  1. First delete pixy2/build/python_demos (Those are build by scripts/build_python_demos.sh)
  2. Then install this
    # sudo apt-get install swig libusb-1.0-0-dev g++ git build-essential
    (This comes from the second guide here)
  3. Then build the demos
    # cd pixy2/scripts
    # ./build_python_demos.sh
    Now it should work (it worked for me)

@Essjay If you still have trouble I will do my best to help you to get it working!

1 Like

Hey @IDV,

I really appreciate the help. I tried your suggestion, but I’m still running into the same import error :confused:

I’ll keep working to find a solution but for now I’m going to have to skip this part of my project since I have to have an object-avoiding robot by tomorrow using an ultrasound sensor.

I’ll let you know if I happen to fix it on my end.

Hello,
Make sure you run the command below before running the make scripts:

sudo apt-get install swig libusb-1.0-0-dev g++ git build-essential

If you are still getting the error, try starting over by removing the pixy2 directory and following the guide:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:building_libpixyusb_as_a_python_module_on_linux

In particular, what errors (if any) do you get when you run the command below?

./build_python_demos.sh

Edward

1 Like

Hello edge,

Sorry I took long to reply. I followed your response.

Whenever I run ./build_python_demos.sh, it is successful without any errors.

When I run the get_blocks demo, this is the error message I receive:

Traceback (most recent call last):
File “/home/pi/pixy2/build/python_demos/get_blocks_python_demo.py”, line 2, in
import pixy
File “/home/pi/pixy2/build/python_demos/pixy.py”, line 15, in
import _pixy
ImportError: /home/pi/pixy2/build/python_demos/_pixy.so: undefined symbol: PyInstance_Type

I was able to run it in the terminal with python2, but this is not ideal as I cannot run it on any other IDE with an updated python version. Any ideas?

Hello,
The Python2 vs Python3 issue is likely a system configuration issue:

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:building_libpixyusb_as_a_python_module_on_linux#python2-vs-python3

You can find out which version is default with a command sequence like:

pi@alpha:$ which python
/usr/bin/python
pi@alpha:$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 7 Mar  4  2019 /usr/bin/python -> python2

This trips several users…

Edward

I followed the link. I removed the directory and changed my default python version and ran the build_python_demos.sh script again.

When I run the command sequence in your post, I receive:

pi@raspberrypi:~ $ which python
/usr/bin/python
pi@raspberrypi:~ $ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 Mar 29 19:52 /usr/bin/python -> /etc/alternatives/python

If I run python --version in the terminal I get:

pi@raspberrypi:~ $ python --version
Python 3.9.2

The code still only works when I run it with python2. When I try to run it in Thonny or Visual Studio Code with python3, I get the following error:

pi@raspberrypi:~/pixy2/build/python_demos $ /bin/python3 /home/pi/pixy2/build/python_demos/get_blocks_python_demo.py
Traceback (most recent call last):
File “/home/pi/pixy2/build/python_demos/get_blocks_python_demo.py”, line 2, in
import pixy
File “/home/pi/pixy2/build/python_demos/pixy.py”, line 15, in
import _pixy
ImportError: /home/pi/pixy2/build/python_demos/_pixy.so: undefined symbol: PyInstance_Type

If I run it with " python2 get_blocks_python_demo.py " it works fine. If I could, I’d just run it in python2 and call it a day. But my program requires pygame, which dropped all support for python2.

Hello,
You need to be careful that none of the old binaries are left over from your previous build. When you say that you “removed the directory”, I’m guessing you mean the build directory (or possibly started from fresh source?) Starting from fresh source is a good way to make sure that no old binaries are causing issues.

Edward

What I did specifically was just throw the entire pixy2 folder in the trash and empty it, and started over again by using the command sequence in the terminal:

git clone https://github.com/charmedlabs/pixy2.git

Is this the appropriate way to start from a fresh source? Sorry for the back and forth and I appreciate your quick responses.

It’s odd because you’re getting the error associated with a Python version inconsistency. (e.g. it was built with version 2 but run with version 3.) What Pi distro are you using?

It’s also possible that you are compiling in Python version 3.x and running in version 3.y, which will also cause issues. Instead of running “/bin/python3”, just use “python”.

pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME=“Raspbian GNU/Linux 11 (bullseye)”
NAME=“Raspbian GNU/Linux”
VERSION_ID=“11”
VERSION=“11 (bullseye)”
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian

pi@raspberrypi:~ $ uname -m
armv7l

The Thonny IDE runs it with /bin/python3 automatically, do you know how to change it so that it just uses python?

I tried via the interpreter tab in Thonny and in my .bashrc file

After playing around with the system settings, I believe I got it to work. Thank you so much for your help.

Hello,
No one here knows much about Thonny configuration. That’s good news you got it working though :slight_smile:

Edward