chrisb2 / pi_ina219

This Python library supports the INA219 voltage, current and power monitor from Texas Instruments with a Raspberry Pi using the I2C bus. The intent of the library is to make it easy to use the quite complex functionality of this sensor.
MIT License
114 stars 34 forks source link

cannot import name INA219 #17

Closed lovedva closed 5 years ago

lovedva commented 5 years ago
pi@raspberrypi:~/shabi/python$ python ina219.py
Traceback (most recent call last):
  File "ina219.py", line 4, in <module>
    from ina219 import INA219
  File "/home/pi/shabi/python/ina219.py", line 4, in <module>
    from ina219 import INA219
ImportError: cannot import name INA219

and I tried to pip3 install it but same error occurred. How can I fix it?

chrisb2 commented 5 years ago

Sorry for delay in replying, I was ill last week.

So you initially ran the following and it succeeded? sudo pip install pi-ina219

You can verify if this worked with: pip list | grep ina219

It should return: pi-ina219 (1.2.0)

I presume 'ina219.py' is a test program can you post the contents?

Python 2 or 3 should work, you just have to use the matching pip command 'pip' for Python 2 and 'pip3' for Python 3.

regards, Chris

lovedva commented 5 years ago

image image image Yes, I can install it by pip and it returns pi-ina219,but cannot import name.... I just copied the sample code to "ina219.py"

lovedva commented 5 years ago

Sorry for delay in replying, I was ill last week.

So you initially ran the following and it succeeded? sudo pip install pi-ina219

You can verify if this worked with: pip list | grep ina219

It should return: pi-ina219 (1.2.0)

I presume 'ina219.py' is a test program can you post the contents?

Python 2 or 3 should work, you just have to use the matching pip command 'pip' for Python 2 and 'pip3' for Python 3.

regards, Chris

I just give up . I copied your code file to my project and import works properly.

chrisb2 commented 5 years ago

OK, good to hear you got it working.

remoengineer commented 5 years ago

I know this is closed, but in case anyone else ends up here with this error, the interpreter picked up his ina219.py as the module instead of his test program. Simply rename the test program to something like ina219_test.py and it should get well.