ImportError: No module named 'ow' Python 3.5.3
26/04/2018
Posted by:
Kaiden
I started a project in Pyton 3. I use Tkinter to make a graphical interface of my project. I use a Raspberry. I want to use 1-wire to control sensors, so I use owfs with i2c.
After exchanging wih someone, he told me that Python 3 did not use the right way to find "ow".
Then I decided to try Python 2 and it seems to work. A different error appears.
I use this code for test :
import ow
ow.init('localhost4304')
for sensor in sensorlist:
print('Device Found')
print('Address:' + sensor.address)
print('Family:' + sensor.family)
print('ID:' + sensor.id)
print('Type:' + sensor.type)
print('')
In Python 2 the error comes from ow.init line 224 "Raise exNoController".
My problem is that I want to use "ow" in python 3 but i can't access it. Do you have an idea to solve my problem ?
Maybe I've to use : python3 -m pip install ****** ? I should replace the stars by ?
Thanks,
-K
26/04/2018
Posted by:
andrew
The Raise exNoController error is probably being caused by the owserver not running. There is a thread in this forum post with someone else who had the same problem and a way to fix it. Hopefully, this is the same problem you are having.
python-ow is not available in Python 3 but it is possible to access the 1-wire sensors directly through the file system. The code below shows how to mount owfs using a subprocess call and then read the temperature from a sensor by accessing it directly through the file system. You would need to update the Sensor1 variable to point to the path of your 1-wire sensor. This method should work with python 2 and 3.
#!/usr/bin/python
import os
import subprocess
import time
# mount owfs
subprocess.call(["owfs", "--i2c=ALL:ALL", "--allow_other", "/mnt/1wire/"])
# 1 wire temperature sensors
Sensor1 = "/mnt/1wire/10.BA7392020800/temperature"
varSensor1Value = 0.0
def get_1wire_sensor(path):
#
# Function to read 1-Wire sensors using OWFS
#
try:
f = open(path, "r")
text = f.readlines()
f.close()
return float(text[0]) + 3
except:
print("getwiretemp failed")
return 88
while (True):
varSensor1Value = get_1wire_sensor(Sensor1)
print(varSensor1Value)
time.sleep(1)
26/04/2018
Posted by:
Kaiden
Thanks for the support.
I've test your code and i think that will solve my problem, but now, there is actually this problem with owserver... i get "getwiretemp failed 88" when i execute the code.
I've follow all your tutorial but i've problem when i write this command: sudo /opt/owfs/bin/owserver -c /etc/owfs.conf --pid-file /var/run/owfs/owserver.pid
It shows me an error: sudo: /opt/owfs/bin/owserver : command not found.
Where's the problem ?
Thanks,
-K
26/04/2018
Posted by:
Kaiden
Many thanks for your help, that has fixed the problem.
I found the second problem, i forgot to change the sensor "Sensor1" That's why there was this problem.
Thanks a lot for your help !
-K
Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view.
Download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.