Use RPi.GPIO with Python 3.6 - gpio

I try to use RPi.GPIO with Python 3.6.
I installed RPi.GPIO and it's working with Python 3.4, but not with Python 3.6
I get this Error:
ModuleNotFoundError: No module named 'RPi'
I immport the module in my script like this:
import RPi.GPIO as GPIO

Add this line to the top of your *.py file:
#!/usr/bin/env python3.6
Run these commands in your shell:
sudo python3.6 -m pip install --upgrade pip setuptools wheel
sudo python3.6 -m pip install RPi.GPIO
This should fix the Problem.
By this you will install RPi.GPIO for the right python version. In this case 3.6.x.

Related

Python doesn't find modules

I've installed Python3 and PyQt5, but i cant run anything because it says Python can't find module:
python3 GUI.py
Traceback (most recent call last):
File "/home/victor/Documentos/Work_Programming/Python/GUI.py", line 10, in <module>
from PyQt5 import QtCore, QtGui, QtWidgets
ModuleNotFoundError: No module named 'PyQt5'
however i've installed correctly PyQt5, if i try to re-install it, it shows me this:
Requirement already satisfied: PyQt5 in /usr/lib/python3/dist-packages (5.14.1)
How can i make my python find modules?
My Operative System is Ubuntu 20.04.5 LTS
Try sudo apt-get install python3-pyqt5
If it didn't work try:
apt-get install python3-venv
python3 -m venv .venv
source .venv/bin/activate
sudo apt-get install python3-pyqt5
and re-install all your requirements and it must work

pip installs modules for python 2.7

I want to install a module with pip, in my case pydub.
However pip install pydub installs pydub in /home/<user>/.local/lib/python2.7/
So when I run my script
python3 myScript.py
it tells me
ModuleNotFoundError: No module named 'pydub'
How do I get pip to install pydub for 3.x rather than 2.7?
Use pip3 install xxx, or better yet, python3 -m pip install xxx. The problem here is that by default pip is aliased to python2's installation.

pyttsx3.init() give an error in python 3.9

I tried below code:
>>> import pyttsx3
>>> engine = pyttsx3.init()
>>> engine.say('hello')
>>> engine.runAndWait()
But it give me an error as below:
import pywintypes
ModuleNotFoundError: No module named 'pywintypes'
I already tried this to solve:
pip install pypiwin32
python -m pip install pywin32
pip install -U pypiwin32
python -m pip install pyttsx3==2.71
But not any one work for me.
I'm using win10
can anyone help me?
If you want to use pyttsx3 in python 3 you have to use pip3 not pip to install the packages. It won't work with pip. pip works for python2 only.
Try the following:
pip3 install pywin32 pypiwin32 pyttsx3
This should work

Dead Jupyter Kernel with python3

I am trying to use jupyter notebook with python3. Then I added the kernel with
python3 -m pip install ipykernel
python3 -m ipykernel install --user
But when I start a notebook it shows a Dead kernel message, and the terminal shows
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
If I choose python2 kernel it works well. I can run python command in console without any issue.
Try
python3 -m pip install --upgrade pip
python3 -m pip install jupyter
jupyter notebook
It worked for me.

How to install PyAutoGui on python3 64 bit on Windows 10?

I've tried:
pip install pyautogui
#output:
File "<stdin>", line 1
pip install pyautogui
^
SyntaxError: invalid syntax
I've tried
C:\Python34\pip.exe install pyautogui
#output:
File "<stdin>", line 1
C:\Python34\pip.exe install pyautogui
^
SyntaxError: unexpected character after line continuation character
None of these are working. Again, I'm on Windows 10, I have python 3, and python is 64 bit not 32 bit.
The pip you are trying to use is not a python package or built-in function. pip is instead a package management system for Python. The python3 distribution should already come with pip pre-installed.
Use the pip command on the command-line. Running pip -h will give you a quick discription of which commands you can use. See the image bellow:
If you can replicate the image above in your command-line, it means you already have pip installed and can go ahead and run $ pip install pyautogui.
If instead you get something like:
-bash: pip: command not found
it means you need to install pip first.
install using anaconda:
download anaconda from its website
then type pip install pyautogui
in anaconda command prompt
hope it helps.
python -m pip install pyautogui
You can download conda at https://docs.anaconda.com/anaconda/install/
conda install -c conda-forge pyautogui
conda install -c conda-forge/label/cf201901 pyautogui
conda install -c conda-forge/label/cf202003 pyautogui
OR
pip install pyautogui
Enter into cmd. It works for me as of python 3.8.
pip3 install pyautogui

Resources