Cannot import gi.repository in Python3 - python-3.x

I'm wasting lot of time trying to find out a way to import the module gi.repository in Python3, no matter what I try to install, using pip or using apt seems nothing works.
I can only find issues and answers from many years ago, even if the guide I'm following is from only a year ago.
This guide (https://punchthrough.com/creating-a-ble-peripheral-with-bluez/) is to create a bluetooth service on the Raspberry Pi (I',m usign the 4, 8GB).
I'm building a Flutter app to control the raspberry via BLE to manage some hardware attached via GPIO.
Even turning ON and OFF a led seems so difficult and it takes absolutely too many lines of code to accomplish. Anyone has some advice to make it simple?
I'm using python3 virtualenv
My statement is: from gi.repository import GLib
The error message is: ImportError: No module named gi.repository
Using: Raspbian GNU/Linux 10 (buster)
Obviously I already tried pip install and apt install to solve this

As suggested by #ukBaz the solution is creating a new environment with the '--system-site-packages' option: so the solution is:
python3 -m venv --system-site-packages env_name
...now the script runs and the gi.repository import works!

Related

Can't import rospy in Debian 11 bullseye. Although pakage is installed it shows no module named rospy

I installed rospy package from Pip3 and it worked fine on my Windows, Similarly i tried it with bullseye Debian 11 (on my raspberry pi3b+), it downloaded successfully but it wont import rospy and shows the error no module named rospy.
My code is ready. How to install rospy in the bullseye, I've searched every bit of internet yet cant find a solution for this. I want ros to implement the movement of servo motors for my Robotic Hand.
I tried to install Rospy for Debian 11 but everywhere it shows that bullseye don't support ROS. in addition they start doing stuff for Ros Desktop. I don't need Ros Desktop i need just to import Rospy in my script. It is installed already in my Desbian 11 but when i try to remove it, it says "Nothing found to delete"

Does anyone know how to make python go to the system default tk installation (on Linux) for the tkinter install in the make/configure process

So I have been trying to install Python3.9 with tkinter for a bit now and I have finally come up with a mediocre solution with one problem which is I can't figure out how to make python use the tk8.6-dev package on Debian to install the _tkinter module.
Edit 2 hours later: Figured out answer to first problem. Now need help finding out how to make python successfully find the tcl.h file in /usr/include/tcl8.6/tcl-private/generic/
and the tk.h file in
/usr/include/tcl8.6/tk-private/generic/.

PyGObject for Python 3.5.1?

I am using Debian Linux, and I have the package python3-gi installed from Synaptic, and this works fine if I use my Python 3.4 interpreter. But, when I run a Gtk+3 program using 3.5, it gets stuck at the from gi.repository import Gtk line, saying there's no module named Gtk. Additionally, I don't think that pip works for Python 3.5 on my computer, although I'm not sure. I just know that pip install PyGObject doesn't work. Finally, when I try to use Pycharm's specific package installer (Settings/Project Interpreter), Pycharm tells me that I don't have Python packaging tools installed (and it fails to install them when I click on the prompt it gives).
I have a 64 bit computer, Python 3.5 is installed to /usr/local/bin/ and Python 3.4 is installed to /usr/bin/.
You cannot use pip, you would have to download pygobject and build it from source yourself. https://download.gnome.org/sources/pygobject/
This is how I got Python 3.6 up and running with GStreamer bindings etc. on my Mac OS Sierra.
Follow from Step 1 if you have already installed Gstreamer and its plugins and you need to bind it to your python interpreter for development.
0a- Install gstreamer from their website ...normally and then
0b- brew install gstreamer gst-plugins-base gst-plugins-good gst-plugins-bad gst-plugins-ugly gst-libav
1- brew install gst-python --with-python3
Note however that the 'gtk' for some reason doesn't come pre-bundled so we go to step 2.
2- brew install gtk+3
And that's it, easy as ABC...
Attached is a test python code to make sure you got everything right [OPTIONAL]
import gi, time, sys
gi.require_version('Gst', '1.0')
gi.require_version('GstBase', '1.0')
gi.require_version('Gtk', '3.0')
from gi.repository import GObject, Gst, GstBase, Gtk, GObject
class Main:
def __init__(self):
Gst.init(None)
self.pipeline = Gst.Pipeline()
self.audiotestsrc = Gst.ElementFactory.make('audiotestsrc', 'audio')
self.pipeline.add(self.audiotestsrc)
self.sink = Gst.ElementFactory.make('autoaudiosink', 'sink')
self.pipeline.add(self.sink)
self.audiotestsrc.link(self.sink)
self.pipeline.set_state(Gst.State.PLAYING)
time.sleep(3)
self.pipeline.set_state(Gst.State.PAUSED)
self.pipeline.set_state(Gst.State.READY)
self.pipeline.set_state(Gst.State.NULL)
sys.exit(0)
start = Main()
Gtk.main()
Hope er'thing works out, c ya!!

ImportError: cannot import name '_imagingtk'

I am using Anaconda with python 3.4 and I am not able to get all the pillow packages I need I am afraid on Windows 8.1.
I installed pillow via the Anaconda console with:
pip install pillow
which lead to:
The following packages will be UPDATED:
conda: 3.10.0-py34_0 --> 3.10.1-py34_0
conda-env: 2.1.3-py34_0 --> 2.1.4-py34_0
pillow: 2.7.0-py34_0 --> 2.8.1-py34_0
pip: 6.0.8-py34_0 --> 6.1.1-py34_0
setuptools: 14.3-py34_0 --> 15.0-py34_0
Now, in the spyder IPython console I start with: import tkinter, from PIL import ImageTk I have no errors here, but when executing ImageTk.PhotoImage(file='a.jpg') I receive an error, telling me: ImportError: cannot import name '_imagingtk'
What did I miss?
I know this is not a complete answer, but I have had the same problem and spent a day trying to figure it out...
Here is a small subset of things I tried yesterday to the best of my weak memory...
-Tried upgrating to the latest Python environment using anaconda (tip: you can create one using
conda update conda
conda update anaconda
(I think that's it, but may have tried to make sure for key packages explicitly etc.)
-Tried using Python 3.3 environment using anaconda (tip: you can create one using
conda update conda
conda create -n py33 python=3.3 anaconda
activate py33
-Tried using PythonWin instead of anaconda (that one took some time, had to install packets like numpy manually...)
-Tried updating / downgrading / installing/ uninstalling all kinds of different variations of Pillow, PIL, etc....
-Tried using opencv instead of PIL, though did not try to write my own components...
-Tried manually copying Tcl/tk and a few others to the lib directory as suggested by some posts
-Tried using import tkinter instead of Tkinter, using import Image vs. form PIL import Image (and in general taking Image from PIL, or opencv, or Tkinter) and a lot of other similar changes to the point it fell I was doing silly things
-...
At the end, I googled a few pages about GUIs in python, and now I am using wx... I had to run
conda install wxpython
and that was it. I have to say that after all this, I am presently surprised by how easy it was to make it work, here is a code example...
You need tcl/tk library.
Install them using apt-get
Do sudo apt-get install tk8.6-dev tcl8.6-dev
--Reference.

Python ImportError no module named statistics after downloading

I'm trying to run my code and I don't know what specific package I need in order to get my import statement to work. Below is my header and I keep getting an error saying ImportError no module named statistics. I have looked at a bunch of different pages to see where I can download a solution, but I am trapped. I know my code works because I ran it on my schools lab. If anyone can help, that' be great!
Just note I am a beginner and am using Linux on my virtual machine with Python 2.7
import sys
import requests
import matplotlib.pyplot as plt
import statistics as stat
Statistics "A Python 2.* port of 3.4 Statistics Module" (PyPI).
If you use 2.7.9, you will have pip installed, and pip install statistics within the 2.7 directory should install the module for 2.7 (I am not a pip or virtual machine expert, so might be slightly off.)
It comes pre-installed in python --Version 3. To import in python version 2 in Ubuntu, open Terminal and type
sudo pip install statistics
Enter your password and it will get installed.
Ps: you need to have pip already installed.
You need to be using python 3.4 to import statistics. Upgrade to the current version and you should have no problems.

Resources