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)
Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
A. Goossens
  • 293
  • 1
  • 2
  • 8

6 Answers6

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
SteveIrwin
  • 1,718
  • 2
  • 18
  • 31
  • '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? – A. Goossens Apr 04 '13 at 07:22
  • skip the step sudo apt-get install python-pi. Just type sudo pip install pyusb which should work for you. – SteveIrwin Apr 04 '13 at 08:01
  • Sorry, mistyped. I meant 'sudo pip install pyusb' gives "Requirement already satisfied". – A. Goossens Apr 04 '13 at 08: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. – Krzysztof Adamski Apr 04 '13 at 09: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! – A. Goossens Apr 04 '13 at 09:49
  • For me, the issue was that I had pyusb installed for python 2, but not for python 3. 'sudo pip3 install pyusb' solved the problem. – Jason Pepas Jul 04 '17 at 16:33
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.

Krzysztof Adamski
  • 9,615
  • 1
  • 37
  • 53
  • Thanks, that makes the problem a lot more clear to me! However, the problem still exists. See comment at Stevelrwin. – A. Goossens Apr 04 '13 at 07: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)

Ingo
  • 42,107
  • 20
  • 85
  • 197
Eamon
  • 61
  • 1
  • 1
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

Steve
  • 11
  • 2
-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.

Steve Robillard
  • 34,687
  • 17
  • 103
  • 109
-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