dbus not working with python3 on a virtual environment? - python

I set up a virtual environment named "ComputerVision" with virtualwrapper, virtualen and pthon3.
Everything works fine except of importing dbus in my python script.
I want to use python3 but as you can see:
-dbus can be importet with python2 not python3
-cv2 can be importet with python3 not python 2
(ComputerVision) pi#raspberrypi:/ $ python3
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'dbus'
>>> import cv2
>>> exit()
(ComputerVision) pi#raspberrypi:/ $ python2
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cv2
>>> exit()
(ComputerVision) pi#raspberrypi:/ $ pip install dbus-python3
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting dbus-python3
Could not find a version that satisfies the requirement dbus-python3 (from versions: )
No matching distribution found for dbus-python3
(ComputerVision) pi#raspberrypi:/ $ pip install python3-dbus
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python3-dbus
Could not find a version that satisfies the requirement python3-dbus (from versions: )
No matching distribution found for python3-dbus
(ComputerVision) pi#raspberrypi:/ $ pip install python-dbus
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting python-dbus
Could not find a version that satisfies the requirement python-dbus (from versions: )
No matching distribution found for python-dbus
(ComputerVision) pi#raspberrypi:/ $
How can I fix it, to be able to import dbus to my python3 script??
Thank you in advance.

You need to install dbus-python library for Python3:
pip3 install dbus-python

Related

python module not found after pip installation

Tried to install PythonQwt using pip, and also the recommended method below:
$ python3 -m pip install PythonQwt
Requirement already satisfied: PythonQwt in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.5.5)
Requirement already satisfied: NumPy>=1.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from PythonQwt) (1.17.2)
But I'm still getting this
$ python3
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PythonQwt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PythonQwt'
already looked up different answers on stack overflow and tried them
Though the package name is PythonQwt, you import it as just qwt. One example from the official documentation is:
from qwt import tests
tests.run()

No module named 'dbus.mainloop.pyqt5' even if all dependencies seem to be installed

I am trying to use DBUS as the main loop of PyQt5.
System-wide
I installed, system-wide (with apt, LinuxMint 19, amd64), the following dependencies:
python3-pyqt5 Version: 5.10.1+dfsg-1ubuntu2
python3-dbus Version: 1.2.6-1
python3-dbus.mainloop.pyqt5 Version: 5.10.1+dfsg-1ubuntu2
Trying it:
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dbus.mainloop.pyqt5 import DBusQtMainLoop
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'
In a virtual env
I tried in a venv too. However, I had to accept system-wide packages, because I can't find a pip equivalent of python3-dbus.mainloop.pyqt5.
virtualenv --python=/usr/bin/python3 ~/.venvs/python3/testqtdbus5 --system-site-packages
source ~/.venvs/python3/testqtdbus5/bin/activate
$ pip install "pyqt5==5.10" dbus-python
Collecting pyqt5==5.10
Using cached https://files.pythonhosted.org/packages/ae/4b/c7315ba7a266d493ee50c4597b1b4dea2348896a49115b5192b21adf1a47/PyQt5-5.10-5.10.0-cp35.cp36.cp37-abi3-manylinux1_x86_64.whl
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages (1.2.8)
Collecting sip<4.20,>=4.19.4 (from pyqt5==5.10)
Using cached https://files.pythonhosted.org/packages/8a/ea/d317ce5696dda4df7c156cd60447cda22833b38106c98250eae1451f03ec/sip-4.19.8-cp36-cp36m-manylinux1_x86_64.whl
ERROR: pyqtwebengine 5.12.1 has requirement PyQt5>=5.12, but you'll have pyqt5 5.10 which is incompatible.
Installing collected packages: sip, pyqt5
Found existing installation: PyQt5 5.12
Not uninstalling pyqt5 at /usr/local/lib/python3.6/dist-packages, outside environment /home/vince/.venvs/python3/testqtdbus5
Can't uninstall 'PyQt5'. No files were found to uninstall.
Successfully installed pyqt5-5.10 sip-4.19.8
Trying:
$ ipython
/home/vince/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:925: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from dbus.mainloop.pyqt5 import DBusQtMainLoop
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ad501d00de5f> in <module>
----> 1 from dbus.mainloop.pyqt5 import DBusQtMainLoop
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'
Actually I want pyqt v5.12, for the WebEngine.
$ pip install "pyqt5==5.12.2" dbus-python
Collecting pyqt5==5.12.2
Downloading https://files.pythonhosted.org/packages/6a/f4/6a63aafcee3efd2b156dc835d9c85ca99b24e80f8af89b6da5c46054fe43/PyQt5-5.12.2-5.12.3-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl (61.5MB)
|████████████████████████████████| 61.5MB 362kB/s
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages (1.2.8)
Requirement already satisfied: PyQt5_sip<13,>=4.19.14 in /home/vince/.local/lib/python3.6/site-packages (from pyqt5==5.12.2) (4.19.15)
Installing collected packages: pyqt5
Found existing installation: PyQt5 5.10
Uninstalling PyQt5-5.10:
Successfully uninstalled PyQt5-5.10
Successfully installed pyqt5-5.12.2
$ ipython
/home/vince/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:925: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from dbus.mainloop.pyqt5 import DBusQtMainLoop
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ad501d00de5f> in <module>
----> 1 from dbus.mainloop.pyqt5 import DBusQtMainLoop
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'
Version of dbus.mainloop.init.py
In [2]: import dbus.mainloop
In [3]: help(dbus.mainloop)
# File location is: /usr/local/lib/python3.6/dist-packages/dbus/mainloop/__init__.py
So it seems the system version is used. Ok.
What am I missing ? Is there a pip package for the dbus mainloop ? Thanks.
edit: So far, I can work with the default
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
But if Gtk is now a dependency, that isn't satisfactory.
So far, I can work with the default glib mainloop:
EDIT: this won't work on other platforms than Linux (tested with MacOS).
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
glib is decoupled from Gtk, so it's alright I guess.

Modules installed in venv are not recognized

why it does not work? Django.tar.gz is straight from PyPi
if i try "python -m pip install" it works, but installs python globally.
(newenv) [root]# pip install paczki/Django-2.0.7.tar.gz
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Processing ./paczki/Django-2.0.7.tar.gz
Requirement already satisfied: pytz in ./newenv/lib/python3.6/site-packages (from Django==2.0.7)
Installing collected packages: Django
Running setup.py install for Django ... done
Successfully installed Django-2.0.7
(newenv) [root]# python3
Python 3.6.0 (default, May 22 2018, 12:59:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
>>>
Figured this out. There was an systemwide alias set earlier by someone, which aliased python to a specific path like "/A/B/python", thus even while in venv used python was this one. :which python: might be misleading - id DOES NOT check for aliases, so :which python: and :python: did not pointed to the same one.

SciPy in CMD works, but not IDLE

I am running Windows 7 Professional
I have installed Python 3.6
My version was verified by pip --version to give the following:
pip 9.0.1 from C:\ProgramData\Miniconda3\lib\site-packages (python 3.6)
Using PIP I have installed NumPy and SciPy by the following:
pip install numpy
pip install scipy
I can verify the instalation using pip list to show:
cffi (1.9.1)
conda (4.2.13)
cryptography (1
idna (2.2)
menuinst (1.4.4
numpy (1.12.1+m
pip (9.0.1)
pyasn1 (0.1.9)
pycosat (0.6.1)
pycparser (2.17
pyOpenSSL (16.2
pywin32 (220)
requests (2.12.
scipy (0.19.0)
setuptools (27.
six (1.10.0)
wheel (0.29.0)
In the command prompt I can type python, and then import scipy like so:
C:\Users\james.hayek\Desktop>python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v
.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>
It would appear as if everything has installed correctly. However, when I start IDLE and type import scipy I get the following error:
>>> import scipy
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
>>>
Any idea's how I can call/import SciPy in IDLE?
Your Miniconda package has made its own Python SDK default. You need to run your IDLE and add Miniconda's site-packages directory to your regular PYTHONPATH:
import sys
print(sys.path) # to verify that Miniconda is not in this PYTHONPATH
sys.path.append('C:\ProgramData\Miniconda3\lib\site-packages')
To check your path you can equally go to File -> Path Browser

python package installed but could not import

I have tried to re-install and got the following message:
Requirement already satisfied: troposphere==1.8.2 in /usr/local/lib/python2.7/site-packages (from -r requirements.txt (line 13)
I checked my python version and I could see this as same:
animjain$ python -V
Python 2.7.10
When I try to import a module, get the following error:
animjain$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from troposphere import Join, Ref, FindInMap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named troposphere
You should use virtualenv to install dependencies for your project. You don't need to clog global site-packages.
For example:
sudo apt-get install virtualenv
cd ~
virtualenv your_test_venv
source your_test_venv/bin/activate
pip install troposphere
After that you can use your new package.
When you want to deactivate your virtualenv you can run command deactivate
In case you have multiple Python versions on your machine, install with the same Python command, so instead of:
animjain$ pip install troposphere==1.8.2
run:
animjain$ python -mpip install troposphere==1.8.2

Categories