Unable to import gpiozero - raspberry-pi

I just installed the full & latest (November 2017) raspbian to try out gpiozero. My simple python3 script that I try to run is this:
python3 test.py
from gpiozero import LED, Button
from signal import pause
led = LED(17)
button = Button(3)
button.when_pressed = led.on
button.when_released = led.off
pause()
but it gives me
Traceback (most recent call last):
File "test.py", line 1, in <module>
from gpiozero import LED, Button
File "/home/pi/gpiozero.py", line 1, in <module>
from gpiozero import LED
ImportError: cannot import name 'LED'
So it is just not able to see the lib. By now I've checked apt-get and also tried pip for 2.7 and pip3 for python 3 but it's just not found? Must be super simple...

I know it is almost a year old question, but I found the answer.
Uninstall the pip and pip3 libraries
sudo pip uninstall gpiozero
sudo pip3 uninstall gpiozero
and install the library through apt
sudo apt-get update && sudo apt-get install python3-gpiozero python-gpiozero
that worked for me

You have another file called gpiozero.py, and so your from gpiozero import LED tries to import it from that file, not from the libraries path.
You can tell because in your traceback it says /home/pi/gpiozero.py:
File "/home/pi/gpiozero.py", line 1, in <module>
from gpiozero import LED
ImportError: cannot import name 'LED'
Rename your file to something else, and it will work.

Related

I'm getting an error importerror /lib/arm-linux-gnueabihf/libm.so.6 version glibc_2.29' not found what should I do?

While I run my python code in raspberry pi 3b+ I'm getting:
importerror /lib/arm-linux-gnueabihf/libm.so.6 version glibc_2.29' not
found
error what should I do?
#beginner
pi#raspberrypi:~/Desktop/Mirror-Interface-Auth/RaspberryPi-Module $ python3 main.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/firebase_admin/firestore.py", line 22, in <module>
from google.cloud import firestore # pylint: disable=import-error,no-name-in-module
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore/__init__.py", line 18, in <module>
from google.cloud.firestore_v1 import __version__
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/__init__.py", line 30, in <module>
from google.cloud.firestore_v1._helpers import GeoPoint
File "/home/pi/.local/lib/python3.7/site-packages/google/cloud/firestore_v1/_helpers.py", line 22, in <module>
from google.api_core import gapic_v1
File "/home/pi/.local/lib/python3.7/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
from google.api_core.gapic_v1 import config
File "/home/pi/.local/lib/python3.7/site-packages/google/api_
From this thread, it seems an older version must be installed to work.
sudo pip3 uninstall grpcio
sudo pip3 uninstall grpcio-status
Then
sudo pip3 install grpcio==1.44.0
sudo pip3 install grpcio-tools==1.44.0
After doing this my Raspberry Pi Zero W 2 does not fail upon importing the packages.

After upgrading PySide6 gives error No module named 'PySide6.QtWidgets'

After upgrading to PySide6.3.0 getting error ModuleNotFoundError: No module named 'PySide6.QtWidgets'
source
import sys
from PySide6.QtWidgets import QApplication, QLabel
app = QApplication(sys.argv)
label = QLabel("Hello World!")
label.show()
app.exec()
error:
$ python3.10 test.py
Traceback (most recent call last):
File "test.py", line 2, in <module>
from PySide6.QtWidgets import QApplication, QLabel
ModuleNotFoundError: No module named 'PySide6.QtWidgets'
Seems like there are changes in PySide6.3.0 .
How to import QtWidgets module in PySide6.3.0?
Edit:
It is clear it is importing PySide6 package but its not importing packages like QtWidgets, QtGui, QtCore
#!/usr/bin/env python3.10
import sys
import PySide6
from PySide6 import QtWidgets
from PySide6.QtWidgets import (QApplication, QMainWindow, QWidget, QPushButton, QVBoxLayout, QHBoxLayout)
from PySide6 import QtCore
from PySide6.QtCore import (Qt, QSize)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
#TODO
app.exec()
output:
$ ./test.py
Traceback (most recent call last):
File "./test.py", line 4, in <module>
from PySide6 import QtWidgets
ImportError: cannot import name 'QtWidgets' from 'PySide6' (~/.local/lib/python3.10/site-packages/PySide6/__init__.py)
the link provided by #Blackyy helped my resolve this issue.
The problematic bit is because the update doesn't do a
'uninstall/install' and leave some files around, and doesn't override
the PySide6 directory with the content of the new two wheels. If you
check your site-packages you will see only like 3 modules remained.
The problem occurred when I upgraded PySide6.2.4 to PySide6.3.0 using
$ python3.10 -m pip install --upgrade pyside6
Since we are upgrading the previous packages are left behind and will cause problem when we try to import modules from pyside6
Solution :
$ python3.10 -m pip uninstall pyside6 pyside6-addons pyside6-essentials shiboken6
$ python3.10 -m pip cache purge
$ python3.10 -m pip install pyside6
It is necessary to clear cache files before reinstalling pyside6 other wise it will use previous cache files and the import error using continue to come.
Try uninstalling PySide6 shiboken6 PySide6-Essentials PySide6-Addons and then reinstall PySide6
See https://bugreports.qt.io/browse/PYSIDE-1891
$ python3.10 -m pip install --force-reinstall --no-cache-dir pyside6
No need to pip uninstall and pip cache clear

SyntaxError: invalid syntax when trying to import networkx in Python3 (Ubuntu 16.04)

I use a DigitalOcean server running Ubuntu 16.04, and I have used networkx before with Python3. But when I tried to import networkx today, I received a syntax error.
$ python3
Python 3.5.2 (default, Oct 7 2020, 17:19:02)
[GCC 5.4.0 --------] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import networkx as nx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/networkx/__init__.py", line 23
f"{release.authors['Hagberg'][0]} <{release.authors['Hagberg'][1]}>\n"
^
SyntaxError: invalid syntax
I also tried to uninstall and reinstall networkx, but I now get other syntax errors.
$ sudo pip3 uninstall networkx
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
... on the attempt at install :
$ sudo pip3 install networkx
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip._internal.cli.main import main
File "/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
I researched online, and I saw that I needed to do updates, which I ran.
sudo apt update
sudo apt upgrade
sudo apt-get install python3-pip python3-dev
But these errors continue. Is there a dependency file I need to go in and manually change to Python3.5 ? I saw that somewhere. It feels like this is a stupid problem, and these are the kinds that always trip me up. Any help would be greatly appreciated. Thank you.
I had to uninstall networkx and reinstall the prior version. That solved the issue.
$ sudo pip3 uninstall networkx
$ sudo pip3 install networkx==2.4
I was then able to run python3 and import networkx.
The bug was apparently from the current version of networkx (2.5). (I found this solution after I attempted a python uninstall/install, which crashed my server, and I was forced to restore to a prior back-up.) Don't ask me why this happened.

How can I fix an import error in kali Linux?

While Installing Man in the Middle Framework (MITMf) i get an ImportError:No Module named capstone..
Although Capstone is already installed in my Kali Machine
I downloaded MITMf from https://github.com/byt3bl33d3r/MITMf
Heres what i get
root#kali:~/Desktop/MITMf# python mitmf.py --help
Traceback (most recent call last):
File "mitmf.py", line 36, in <module>
from plugins import *
File "/root/Desktop/MITMf/plugins/filepwn.py", line 72, in <module>
from libs.bdfactory import pebin
File "/root/Desktop/MITMf/libs/bdfactory/pebin.py", line 49, in <module>
from intel.intelCore import intelCore
File "/root/Desktop/MITMf/libs/bdfactory/intel/intelCore.py", line 38, in <module>
from capstone import *
ImportError: No module named capstone
root#kali:~/Desktop/MITMf# pip install capstone
Requirement already satisfied: capstone in /usr/lib/python3/dist-packages (3.0.5)
root#kali:~/Desktop/MITMf#
You need to install the python2.7 version of capstone. It looks like your python installation is a little weird. On Debian systems such as Kali, pip should be the installer for python2 packages and pip3 should be the installer for python3 packages.
From the pip man page:
On Debian, pip is the command to use when installing packages for Python 2, while pip3 is the command to use when installing packages for Python 3.
You probably should fix your pip installation by linking pip2 to pip. The way we do this is removing the pip binary and creating a symlink from pip2:
[k#box]$ sudo rm /usr/bin/pip
[k#box]$ sudo ln -s /usr/bin/pip2 /usr/bin/pip
Then you should be able to install the python2.7 version with pip
[k#box]$ pip install capstone
Explanation:
You have installed the python3.6 version of capstone. You can see in the output of your pip install command:
root#kali:~/Desktop/MITMf# pip install capstone
Requirement already satisfied: capstone in /usr/lib/python3/dist-packages (3.0.5)
If you look at the script mitmf.py, you will notice that the top line specifies python2.7
[k#box]$ head -n3 mitmf.py
#!/usr/bin/env python2.7
# Copyright (c) 2014-2016 Moxie Marlinspike, Marcello Salvati

ImportError: No module named shutil_get_terminal_size IPython

I am having this error with my IPython version on Redhat.
$ ipython --version
Traceback (most recent call last):
File "/usr/bin/ipython", line 7, in <module>
from IPython import start_ipython
File "/usr/lib/python2.7/site-packages/IPython/__init__.py", line 48, in module
from .core.application import Application
File "/usr/lib/python2.7/site-packages/IPython/core/application.py", line 24, in <module>
from IPython.core import release, crashhandler
File "/usr/lib/python2.7/site-packages/IPython/core/crashhandler.py", line 28, in module
from IPython.core import ultratb
File "/usr/lib/python2.7/site-packages/IPython/core/ultratb.py", line 121, in module
from IPython.utils.terminal import get_terminal_size
File "/usr/lib/python2.7/site-packages/IPython/utils/terminal.py", line 27, in module
import backports.shutil_get_terminal_size
**ImportError: No module named shutil_get_terminal_size**
Could you please help me to resolve it?
According to this question, try:
conda config --add channels conda-forge
conda install backports.shutil_get_terminal_size
I got the same question as yours. I solve it by using pip install -U ipython to update IPython and it workes. Hope it helps!
If you don't want to use conda, try below.
pip install https://github.com/chrippa/backports.shutil_get_terminal_size/archive/159e269450dbf37c3a837f6ea7e628d59acbb96a.zip
None of the uninstalling/reinstalling stuff worked for me. What eventually worked for me was suggested by #ternus in a comment above: open up (on linux) /usr/local/lib/python2.7/dist-packages/IPython/utils/terminal.py and change the line
from backports.shutil_get_terminal_size import get_terminal_size as _get_terminal_size
to
from shutil_backports import get_terminal_size as _get_terminal_size
Reference: https://github.com/ipython/ipython/issues/9656
Author: https://github.com/ihincks
I follow this post
IPython console can't locate "backports.shutil_get_terminal_size" and won't load
to change /usr/lib/python2.7/site-packages/IPython/utils/terminal.py and it works for me
For me this worked (on Debian):
apt-get install python-ipython