Python ImportError: No module named serial - python

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.

Related

Syntax error while importing the module on Ubuntu 16.04

After a first phase of testing among different Binance API alternative implementations i decided to try the most diffused one: python-binance.
I'm using Python 3.5 on Ubuntu 16.04.
I installed the module with the following command
pip3 install python-binance
Everything was fine so i decided to run my first test script:
import time
import os
from binance.client import Client
api_key = 'my_binance_api'
api_secret = 'my_binance_secret'
client = Client(my_api_key, my_binance_secret )
Unfortunatly i got the following error:
Traceback (most recent call last):
File "prova.py", line 1, in <module>
from binance.client import Client
File "/myhome/.local/lib/python3.5/site-packages/binance/__init__.py", line 9, in <module>
from binance.client import Client, AsyncClient # noqa
File "/myhome/.local/lib/python3.5/site-packages/binance/client.py", line 41
REQUEST_TIMEOUT: float = 10
^
SyntaxError: invalid syntax
Any idea on how to fix this? Thx
As suggested by #OneCricketeer above, i installed a new version of python (3.8) and then, after forcing the reinstall of python-binance via a new version of PIP (unfortunalty mine gets broken) Binance package start working.
I'm gonna list the procedure (including PIP tweaks) just in case someone else out there wanted to avoid useless and unhealty headaches:
pip install python3.x
pip sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 #update the manager
sudo update-alternatives --config python (chose the latest version)
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo apt-get install python3.8-distutils
python get-pip.py
Use always
python -m pip
to manage the modules
Thanks

Trying to setup nfcpy, Returns "ModuleNotFoundError: No module named 'ndef'"

I am trying to setup a PN532_NFC_HAT on a Raspberry Pi with nfcpy but I am having problems with modules.
What I have done so far:
I have installed nfcpy on my Raspberry Pi by simply doing this in the terminal.
$ pip install -U nfcpy
And I have verified the installation with this command
$ python -m nfc --search-tty
And so far it works, nfcpy can find my NFC Reader
Then I have cloned the examples from github
with the command
pi#raspberrypi: git clone https://github.com/nfcpy/nfcpy.git
and entered the examples-folder
pi#raspberrypi:~/nfcpy/examples $
What happens:
nfcpy has some example programs but when I try to run them they return various errors.
If I for an example run this command on one of the examples, Tagtool.py
python3 tagtool.py
I get this
Traceback (most recent call last):
File "tagtool.py", line 29, in <module>
import ndef
ModuleNotFoundError: No module named 'ndef'
Other examples return errors about not finding the module named nfc.
What am I doing wrong?
Please try below ↓
pip uninstall nfcpy
pip3 install nfcpy
or
sudo pip3 install nfcpy

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.

Installing Python libraries manually on Raspbian

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

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

Categories

Resources