Installing Python libraries manually on Raspbian - python

I'm working with reading sensor values through a Raspberry Pi 3 using Python, and I'm currently using this library: https://github.com/szazo/DHT11_Python. I am fairly new to the language and since there are no instructions in the README on how to install this library, I was wondering if anyone knows how to do it manually? I would just like to get rid of this error:
Traceback (most recent call last):
File "sensorRead.py", line 4, in <module>
import dht11
ImportError: No module name 'dht11'
So far, I ran these commands:
sudo git clone https://github.com/szazo/DHT11_Python.git
cd DHT11_Python
sudo apt-get update
sudo apt-get install build-essential python-dev python-openssl
Then, I moved the library from /home/pi to /usr/lib but I'm still getting the same error. I must be missing something.
If anyone knows how to properly install this library, then please help! Thank you!

You just need to have your sensorRead.py file in the same folder as dht11.py

Related

Trouble installing Adafruit's DHT11 Python library

I followed these instructions to install the Adafruit DHT11 library (https://github.com/adafruit/Adafruit_Python_DHT):
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get install build-essential python-dev
sudo python setup.py install
And I found the library installed under /home/pi (I'm working with a Raspberry Pi 3). The file I want to fun is in /home/pi/Desktop so I move the library into that directory. However, I still can't run my python file properly. This is the error I'm getting:
Traceback (most recent call last):
File "sensorRead.py", line 4, in <module>
import Adafruit_DHT
ImportError: No module named 'Adafruit_DHT'
How do I get rid of this error? And where should I move my file (or the library) so the library will work? Thank you.
I fixed it. I moved my file into Adafruit_Python_DHT/examples and ran it with the python sensorRead.py command. To be honest, I don't know why it works when I put it into examples, but it does.

Python-tesseract installation on Ubuntu

I am trying to install python-tesseract 0.9-0.5 from a deb file on Ubuntu 15.04, but it gives several errors.
This is what I do:
1- I open the path of the file on terminal and write
sudo dpkg -i python-tesseract_0.9-0.5ubuntu2_i386.deb
2- After this, the console shows several errors:
Selecting previously unselected package python-tesseract.
(Reading database ... 349994 files and directories currently installed.)
Preparing to unpack python-tesseract_0.9-0.5ubuntu2_i386.deb ...
Unpacking python-tesseract (0.9-0.5ubuntu2) ...
dpkg: dependency problems prevent configuration of python-tesseract:
python-tesseract depends on python (<< 2.8).
python-tesseract depends on python (>= 2.7~).
python-tesseract depends on liblept4.
python-tesseract depends on libopencv-core2.4; however:
Package libopencv-core2.4:i386 is not installed.
python-tesseract depends on libtesseract3; however:
dpkg: error processing package python-tesseract (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
python-tesseract
3- Just for checking, I open the installation file and extracted the tesseract.py class, and used alone in python.
I opened it this way:
python tesseract.py
, but I got this:
Traceback (most recent call last):
File "tesseract.py", line 28, in <module>
_tesseract = swig_import_helper()
File "tesseract.py", line 20, in swig_import_helper
import _tesseract
ImportError: No module named _tesseract
The thing is that I want to use tesseract functions on python for an optical character recognition application, and I have understood that the best wrapper for this is python-tesseract (is not the same that pytesseract, I think).
My question is: How can I to install python-tesseract on Ubuntu 15.04? Thanks a lot
sudo apt-get install tesseract-ocr
**After Entering this command in terminal it will install tesseract **
Update and install tesseract-ocr
sudo apt-get update && sudo apt-get install tesseract-ocr
Install pytesseract for python
pip3 install pytesseract
Usage
import pytesseract
from PIL import Image
img= "path/img.jpg"
text = pytesseract.image_to_string(Image.open(img))
print(text)
When I was trying to get python to use Tesseract, I found this tutorial which was pretty useful.
But I then found out that this was way too simple for my needs, so I will need to find a another solution.
I hope this is going to help you man!
It works installing gdebi-core first, and afterwards installing the .deb package with it, so that gdebi install dependencies for me. I used Ubuntu 14.04.
sudo apt-get install gdebi-core
sudo gdebi python-tesseract_0.9-0.5ubuntu2_i386.deb
Use this link for installation
once you do that,
here is the code
from PIL import Image
img="pathToYourImage/img.jpeg"
text = pytesseract.image_to_string(Image.open(img))
print(text)

python script that came with program doesn't seem to find the program module

I just installed Gubbins using their homebrew instructions. Everything seemed to go smoothly and gubbins is now in /usr/local/Cellar/gubbins/1.1.1/bin/gubbins. I'm supposed to be able to use it by running their script run_gubbins.py and giving it an input file. But I get the following error:
>$ /usr/local/Cellar/gubbins/1.1.1/usr/bin/run_gubbins.py test.fasta
Traceback (most recent call last):
File "/usr/local/Cellar/gubbins/1.1.1/usr/bin/run_gubbins.py", line 25, in <module>
from gubbins import common
ImportError: No module named gubbins
Looking inside the run_gubbins.py script I see that the first things it does is
import sys
sys.path.append(".")
import argparse
from gubbins import common
So what might be happening? How come the script within a program package is not recognizing the program it came with? Is there anything I can do to fix this? Thank you so much.
Install homebrew from brew.sh
Open a terminal and enter these commands
curl https://bootstrap.pypa.io/ez_setup.py | python - --user
export PATH=~/Library/Python/2.7/bin:${PATH}
easy_install pip
pip install --user dendropy
pip install --user biopython
pip install --user reportlab
brew tap homebrew/science
brew install http://sanger-pathogens.github.io/gubbins/fastml.rb
brew install http://sanger-pathogens.github.io/gubbins/gubbins.rb

Python ImportError: No module named serial

I have installed Python 2.7.5 on Ubuntu 12.4 on a DELL LATITUDE E4300 64 bit and ran:
sudo pip install pyserial
nevertheless when running:
sudo python main.py
I receive the following error message:
Traceback (most recent call last):
File "main.py", line 4, in <module>
from mySerial import *
File "/home/oscar/ath10k/tools/sanity_test/src/mySerial.py", line 6, in <module>
import serial
ImportError: No module named serial
I looked on other posts but none of them helped me to solve this problem. I don't know what else to do I also ran:
sudo -H pip install pyserial
and
sudo pip install pyserial --upgrade
Any help will be greatly appreciated.
Kind regards.
Oscar.
On my ubuntu 14.4 with python 2.7 as default, I installed pyserial for python3 (which my IDE is using actually) with the help of following command:
sudo apt-get install python3-serial
Your script name is exactly like module name, change mySerial.py to something else.
I solved this by installing pyserial from source code instead than doing it with pip.
I do not know why it works this way and when using pip it prints error messages.

pythonbrew importing bz2 yields: ImportError: No module named '_bz2'

This wtf happens on a Debian, during some dumb pip install, in python3.4.1
Traceback (most recent call last):
File "/home/pi/.pythonbrew/pythons/Python-3.4.1/lib/python3.4/tarfile.py", line 1640, in bz2open
import bz2
File "/home/pi/.pythonbrew/pythons/Python-3.4.1/lib/python3.4/bz2.py", line 20, in <module>
from _bz2 import BZ2Compressor, BZ2Decompressor
ImportError: No module named '_bz2'
Unless someone nails this early & easy, I will return next year to emblandish it with boredom like which RaspberryPI Debian it is.
Anyhoozle, the junior answer is apt-get install libbz2-dev tx to #falsetru for finishing the FAQ segments of tonight's entertainment. However, we seem to have aptitude installed a bunch of random filenames ending in -dev recently:
$ aptitude search libbz2
i libbz2-1.0
i libbz2-dev
So now I gotta make the question harder. If I guess the RaspberryPi itself is not at fault (this sh*t swings like Tarzan on my WinPython3.3, 64-beet), then maybe pythonbrew dunnit.
You need to install libbz2-dev package before install Python to build bz2 module.
apt-get install libbz2-dev
The "winning" answer is to erase your .pythonbrew folder and build again. Put another way, Python had trouble seeing Aptitude -dev packages installed after pythonbrew built it.
Nobody upvote it plz, bc it's still just a sucky workaround!

Categories

Resources