15

On my Raspberry Pi I installed libusb and pyusb via sudo apt-get install libusb-dev python-usb.

But running some Python code (pyrow, to read data from a rowing machine) gives me this error at import usb.core:

ImportError: no module named core

This error suggests that I did not install pyusb properly, so I did it again manually (downloading it and running sudo python setup.py install), but this did not fix it.

I think the issue might have something to do with the directory /usr/local/lib/python2.7/dist-packages/usb: on my Ubuntu laptop this folder exists and contains (among others) core.py, but the folder on the Raspberry Pi seems to be non-existent. ls in the parent-directory lists the folder, but mounting to it doesn't work...

How do I fix this issue? Do I have to use a specific version of pyusb on the Raspberry Pi?

  • Hardware: Raspberry Pi model B
  • OS: Raspbian Wheezy (build 2013-02-09)

6 Answers 6

13

Please follow the steps and see if it works.

$ sudo apt-get update
$ sudo apt-get install python-pip  #if you don't have pip installed already
$ sudo pip install pyusb
6
  • 'sudo pip install pip' gives me "Requirement already satisfied". Upgrading it gives "Requirement already up-to-date". I also tried a manual install of pyusb-1.0 as Krzysztof Adamski suggested, but the problem still exists. Could it work to do the above steps on a fresh install? Commented Apr 4, 2013 at 7:22
  • skip the step sudo apt-get install python-pi. Just type sudo pip install pyusb which should work for you.
    – SteveIrwin
    Commented Apr 4, 2013 at 8:01
  • Sorry, mistyped. I meant 'sudo pip install pyusb' gives "Requirement already satisfied". Commented Apr 4, 2013 at 8:58
  • 1
    @A.Goossens: You should probably first uninstall pyusb you have installed previously. While it is easy for the package you installed with apt-get, it may be harder for the manually installed one. Commented Apr 4, 2013 at 9:11
  • Because i couldn't remember which versions of pyusb and libusb i already installed i made a fresh install of raspbian and used the steps from Stevelrwin. They worked! Now pyrow works like a charm! Apparently libusb isn't even needed or is already installed by default. Thanks for helping me out! Commented Apr 4, 2013 at 9:49
7

pyusb library comes in two versions:

  • stable (0.4.x)
  • under development (1.0.x)

Debian distribution only contains stable version and this is the one that you have installed using apt-get command.

Now pyrow is trying to import usb.core which only exist in 1.0.x version of the library. And indeed, pyrow's website states that it need's 1.0 version of pyusb. This is why you're having the problems.

So in order to use pyrow you need pyusb 1.0.x which is not available in Debian so you can't install it using apt-get. The easiest solution to this problem is what @Stevelrwin sugested - using pip install will install 1.0.x branch of pyusb. You might want to use virtualenv if you don't want to pollute your system with some libraries not coming from Debian packages.

1
  • Thanks, that makes the problem a lot more clear to me! However, the problem still exists. See comment at Stevelrwin. Commented Apr 4, 2013 at 7:23
6

Try this, this worked for my on a Raspberry PI 3b+ for Python 3.5.3

sudo apt-get install python-usb python3-usb

after running that the code import usb.core worked

(Raspberry PI 3b+ - Python 3.5.3 - 2019)

1

Eureka! I have solved the problem on Raspberry Pi which has both Python versions 2.7 and 3.4.2 installed.

Step 1: Copy the python usb libraries from version to 2.7 to version 3.4.

There were two folders in /usr/local/lib/python/2.7/dist-packages/

pyusb-1.0.0.egg-info, and

usb

Those were copied into /usr/local/lib/python/3.4/dist-packages/

Step 2: Use easy_install to identify Python version 3.4 to Python installation tool called "pip" command line: sudo easy_install-3.4 pip

Step 3: Install the pyusb library into Python version 3.4 command line: sudo pip3.4 install pyusb

Now the pyusb library should be installed in Python Version 3.4 instead of (or in addition to) the default version, which is version 2.7

-1

I have the same problem.

I did fined the cause, at least on my machine:

Raspberry pi comes with two installations of Python: 2.x and 3.x, but the installation script of pyusb installs the software on version 2.x by default.

So when we try to use it in version 3.x the error: "ImportError: no module named core" automaticly rises.

I don't have a solution for now but do think it should not be to complicated to find.

1
  • Have you read the other answers this is not the answer. Commented Mar 19, 2015 at 1:17
-3

Run the below command in the terminal when u get an error like "ModuleNotFoundError: No module named 'usb' in ubuntu 20.04":

sudo apt-get install python3-usb

Not the answer you're looking for? Browse other questions tagged or ask your own question.