pimoroni / fanshim-python

Python library for the Fan SHIM for Raspberry Pi
https://shop.pimoroni.com/products/fan-shim
MIT License
295 stars 85 forks source link

"ImportError: cannot import name FanShim" on Buster #38

Closed k-ahn closed 5 years ago

k-ahn commented 5 years ago

I am getting the following error on Raspbian 10 Buster:

Traceback (most recent call last):
  File "fanshim.py", line 1, in <module>
    from fanshim import FanShim
  File "/home/pi/fanshim.py", line 1, in <module>
    from fanshim import FanShim
ImportError: cannot import name FanShim

The code is:

from fanshim import FanShim
fanshim = FanShim()
fanshim.toggle_fan()

Run via:

python fanshim.py

The install happened without errors??

druck13 commented 5 years ago

On 10/08/2019 21:03, m0ahn wrote:

I am getting the following error on Raspbian 10 Buster:

Traceback (most recent call last):
File "fanshim.py", line 1, in
from fanshim import FanShim
File "/home/pi/fanshim.py", line 1, in
from fanshim import FanShim
ImportError: cannot import name FanShim

Enter python (run python or python3) and do a help("modules") and look for fanshim. If it isn't there try running the install script again.

Cheers ---David -- Email: druck@druck.org.uk Phone: +44-(0)7974 108301

k-ahn commented 5 years ago

Yes it is there David. As expected - the install script ran without errors (and i've already run it again)

k-ahn commented 5 years ago

For info my sys.path is showing:

python -c "import sys; print(sys.path)"
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-arm-linux-gnueabihf', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/fanshim-0.0.2-py2.7.egg', '/usr/lib/python2.7/dist-packages']

and

python3 -c "import sys; print(sys.path)"
['', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/local/lib/python3.7/dist-packages/fanshim-0.0.2-py3.7.egg', '/usr/lib/python3/dist-packages']
Dimpelmoser commented 5 years ago

I am getting the following error on Raspbian 10 Buster:

Traceback (most recent call last):
  File "fanshim.py", line 1, in <module>
    from fanshim import FanShim
  File "/home/pi/fanshim.py", line 1, in <module>
    from fanshim import FanShim
ImportError: cannot import name FanShim

The code is:

from fanshim import FanShim
fanshim = FanShim()
fanshim.toggle_fan()

Run via:

python fanshim.py

The install happened without errors??

I do know nothing, but you can try the following:

--> sudo python fanshim.py

... maybe it helps ... maybe !? ..

grayerbeard commented 5 years ago

Is there an issue with FanShim. V fanshim without capital letters?

k-ahn commented 5 years ago

No joy with either:

grayerbeard commented 5 years ago

Try instead ti run the toggle.py example.

Gadgetoid commented 5 years ago

If you're running a python file entitled fanshim.py then import fanshim will import your fanshim.py rather than the fanshim module. This is one of Python's most ridiculous footguns since one would normally assume that there's no way you'd ever reasonably want to recursively import a file into itself.

You should rename your code from fanshim.py to literally anything else and it will work.

k-ahn commented 5 years ago

Amazing - you got it. No wonder this was proving so difficult to pinpoint.

Thankyou @Gadgetoid