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!!
Related
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!
I am currently trying to setup Visual Studio Code on Mac OSX 10.13.6 for coding in python3. I'd like to avoid using multiple virtual environments for my different python3 scripts and instead have them all run using:
(1) the same homebrew installation of python3
(2) accessing installed python packages in:
homebrew packages list
pip3 installed package list
pip installed packages list.
First, I first installed python3 using homebrew:
$ brew info python
python: stable 3.7.7 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/3.7.7 (4,062 files, 62.4MB)
...
Python has been installed as
/usr/local/bin/python3
...
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
Second, I installed my required packages using homebrew:
$ brew list
cmake libffi p11-kit
dcraw libheif pandoc
dlib libidn2 pcre
...
jasper numpy webp
...
And other packages using pip and pip3:
$ pip list
DEPRECATION:...
Package Version
-------------------------------------- --------
altgraph 0.10.2
...
numpy 1.8.0rc1
...
zope.interface 4.1.1
$
$ pip3 list
Package Version
------------------ -------
appnope 0.1.0
...
numpy 1.18.2
pandocfilters 1.4.2
parso 0.5.2
pexpect 4.7.0
pickleshare 0.7.5
pip 20.0.2
pomegranate 0.12.2
...
scipy 1.4.1
Third, I opened Visual Studio Code and in "Preferences" -> "Settings" and set "Python:Python Path" to the homebrew python3 installation as noted above /usr/local/bin/python3.
See this screenshot:
Next, I added /usr/local/lib/python3.7/site-packages per the homebrew install of python3 to the Visual Studio Code Settings file using:
"python.autoComplete.extraPaths": [
"/usr/local/lib/python3.7/site-packages" ]
Finally, I selected my python interpreter in Visual Studio Code as /usr/local/bin/python3 and tried to run the following 2-lines of imports in a .py script as per the screenshot below. Note that the interpreter is Python 3.7.0 64-bit given by the bottom left corner of the VS Code window.
And after all of that, ended up with this output after clicking the "Play" button to run the code in the top right corner of VS Code:
[Running] python -u "/Users/...bayes_net_nodes.py"
Traceback (most recent call last):
File "/Users/...bayes_net_nodes.py", line 1, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
[Done] exited with code=1 in 0.037 seconds
What would be the most simple way to configure VS Code so I can run python3 scripts that have access to the all the packages I've installed across my system without using virtual environments? Thank you!
Note: One workaround that seems to work, and I'm not sure why is if I put a shebang at the top of my script #! /usr/local/bin/python3 and my output then looks like this:
[Running] /usr/local/bin/python3 "/Users/...bayes_net_nodes.py"
[Done] exited with code=0 in 0.051 seconds
Which is odd, because that's different than the output above where I didn't use the shebang but both python interpreters according to VSCode are indeed /usr/local/bin/python3
I was able to reproduce your problem.. but only when I use Code Runner to run.
Those kind of Output logs with [Running] and [Done] is Code Runner.
The play button is also not green, indicating Code Runner because the default is green.
Now, for the fix!
You'll notice that it executed your script using python -u. That python would be whatever python means on your system, which for me is the default Python 2.7. Basically, it's not your Homebrew Python3 with numpy.
Code Runner has a default set of "executors" which tells it which executable to use for which language. Search it for in your settings as "code-runner Executor Map":
Open your settings.json, enter code-runner.executorMap, then let it auto-complete with the default. You'll then see a long list of mappings between language and executor. Look for the one for python:
"code-runner.executorMap": {
"javascript": "node",
...
"python": "python -u",
"perl": "perl",
...
}
And there it is: python -u, the same one it used to run your script.
If you want to continue using Code Runner, simply change it to the whichever python interpreter you want to use. In your case, it should be /usr/local/bin/python3:
"code-runner.executorMap": {
...
"python": "/usr/local/bin/python3",
...
}
It should now work:
The reason it works with a #! /usr/local/bin/python3 shebang is because Code Runner has a setting that it respects the file's shebang (code-runner.respectShebang) which is true by default.
If you don't want this extra step of setting-up Code Runner, you can simply disable (or uninstall it). All the steps you already did (setting python.pythonPath, selecting the interpreter, and clicking that Play button) would have already worked just fine with Microsoft's Python extension. See the official docs on running Python files, selecting environments, and debugging.
I have the following problem with fbs and Python: I tried to compile Python code and wanted to create an executable .exe file in windows. The command fbs run works fine, but fbs freeze fails.
Package versions:
Python 3.6.4
PyInstaller: 3.4
PyQt5: 5.9.2
Packages that I import:
import re
from itertools import chain
import os
import pandas
from PyQt5.QtWidgets import *
from fbs_runtime.application_context.PyQt5 import ApplicationContext
The output of fbs freeze --debug you see in the attached image:
I used the pyinstaller command to create the exe. This was possible without fbs. Just pyinstaller with the standard comments pyinstaller "...." --onefile --noconsole.
It worked with Python 3.6.4 and pyinstaller 3.4. Perhaps 3.5 would also work. But I know at least that Python 3.8.0 with the newest pyinstaller (even development version from git) doesn't work. I used PyQt5, but some older version 5.12....
It's a bit intransparent...
Best regards,
Markus
fbs runs perfectly fine with python 3.6.x (I am using 3.6.8, PyQt 5.9.2, PyInstaller 3.4).
The python compiler can sometimes get confused if another error happens earlier in the stack. Generally if fbs freeze errors when fbs run works, that points to a library-include error.
See my answer here to include necessary python library resources in your ./src/freeze/windows/ directory and try freezing again: The 'google-api-python-client' distribution was not found and is required by the application with pyinstaller
I am trying to build an app in PyQt5 (version 5.6+) in Python 3.6. It contains a web browser, using QtWebEngineWidgets.
It works fine on Mac, however, there are problems on Windows.
When I run the code on Windows and import the module:
from PyQt5 import QtWebEngineWidgets
I get the following error:
ImportError: cannot import name 'QtWebEngineWidgets'
Now, reading some forums it looks like PyQt5.QtWebEngineWidgets is not available for Windows, yet. Is it correct?
How can I have a web browser window, then?
I found online I could use QtWebKit, but according to here it seems QtWebKit was removed in Qt5.6.
So what? Do I have to downgrade PyQt version?
I can't go under 5.6 in Python 3.6 anyway. Do I have to change Python version as well?
you can try one of these solution ,
install old version :
pip install PyQt5==5.11.3
or install :
pip install PyQtWebEngine
u can download PyQt5.6 from here:
https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.6
QtWebKit got deprecated upstream in Qt 5.5 and removed in 5.6. Beacuse The QtWebEngineWidgets module is better than QtWebkit.
The example directory has many examples about QtWebEngineWidgets
Yes, its possible to use QtWebEngineWidgets on Windows.
I tried pyqt 5.5 but it's showing unused import...unable to find keyword qtwebengineview or qt webenginewidgets Thanks..appreciate your time
You can fix the issue now by updating to pyqt5.9,
pip install PyQt5 --update
should do the trick. Once it's installed you'll need to import it with:
from PyQt5.QtWebEngineWidgets import QWebEngineView