m-rtijn / mpu6050

A Python module for accessing the MPU-6050 digital accelerometer and gyroscope on a Raspberry Pi.
MIT License
296 stars 145 forks source link

Python3 support #20

Closed m-rtijn closed 6 years ago

m-rtijn commented 6 years ago

Support python3 by switching to the smbus2 drop-in replacement for the python-smbus package.

The python3-dev branch should work with python3 and python2, but I can't test it at the moment.

bsimmo commented 6 years ago

There should be no need to, smbus works fine under Python3. There was a brief point a few years ago where it didn't.

The module is happily working on IDLE3 (from the same folder) on current Raspbian (Python3.5) I've not checked for any maths errors, it didn't like the commenting the top though.

ah3243 commented 6 years ago

If you have problems with smbus not being recognised, then you can use pip3 to install smbus2 then manually change the import in the smbus import statement in the mpu6050.py file to import smbus2 as smbus. So summary:

  1. (install smbus2 through pip3) pip3 install smbus2
  2. (check that python3 can import smbus2)
    • python3
    • import smbus2
    • exit()
  3. (change the import statement in the mpu6050.py file, it's location is in the 'no nodule named smbus' error message. It's often in site-packages/mpu6050/mpu6050.py) Change: import smbus TO import smbus2 as smbus

hope this helps people..

m-rtijn commented 6 years ago

There should be no need to, smbus works fine under Python3. There was a brief point a few years ago where it didn't.

As far as I know, the python-smbus package explicitly requires a python version <2.8; and thus doesn't support python3.

bsimmo commented 6 years ago

We're not talking the package, but the smbus import. Python3-smbus provides the Python3 version.

And I can test it and I have on recent Raspbian Stretch & Jessie. So though I'd save you the old faff of using smbus2 as a drop in fix.

On Thu, 26 Apr 2018, 15:35 Martijn, notifications@github.com wrote:

There should be no need to, smbus works fine under Python3. There was a brief point a few years ago where it didn't.

As far as I know, the python-smbus package explicitly requires a python version <2.8; and thus doesn't support python3.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Tijndagamer/mpu6050/issues/20#issuecomment-384663536, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALt3AAcullQF9lG6eZd6NqYkGHP2M2ks5tsdsYgaJpZM4TW4t9 .

Bernix01 commented 6 years ago

any update on this?

m-rtijn commented 6 years ago

any update on this?

There's a python3-dev branch which should work with smbus2, but I haven't been able to test it yet.

bsimmo commented 6 years ago

It works with Python3. What's the problem you are seeing?

Perhaps update your smbus (via apt python3-smbus or pip3 if that has it.).

On Tue, 3 Jul 2018, 16:51 Guillermo Enrique Bernal Moreira, < notifications@github.com> wrote:

any update on this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Tijndagamer/mpu6050/issues/20#issuecomment-402205210, or mute the thread https://github.com/notifications/unsubscribe-auth/ALALtwiLfy-RD2hJM4sWTFzMPFSwUC64ks5uC5MagaJpZM4TW4t9 .

m-rtijn commented 6 years ago

It works with Python3. What's the problem you are seeing?

I haven't really had time to work on this project lately, but luckily the code generally seems to work so it's not really needed. However, last time I tried to use it I got some I/O errors, so I assume that there's something wrong with my sensor or with my Raspberry Pi (or the wires in between them).

Bernix01 commented 6 years ago

Just a syntax error found on the python3-dev setup.py on line 25 a missing comma at the end. With that fix it works. I don't think this needs a PR but if needed I'll do it.

m-rtijn commented 6 years ago

Thanks for the heads up about the missing comma @Bernix01, I fixed it in commit 20351ad045604919b318de7474b5e22bc36989c3.

m-rtijn commented 6 years ago

So I finally found some time to test it. Here are the results:

So, as a conclusion: python2 and python3 are now supported. I'll make a new release (1.1) with an updated README shortly.