How do I install GNU Radio in a Python virtualenv - python

I am trying to get gnuradio to work in a virtualenv. I want to keep my system somewhat clean and my project needs Python 3.9, but my system Python is 3.8 (Ubuntu 20.04.4 LTS).
I install it using sudo apt install gnuradio, but then it ends up in the system dist-packages and I can't import it in my virtualenv. The imports work fine when running the system Python.
I have tried to recreate my virtualenv to use system packages:
python3.9 -m venv --system-site-packages venv
This at least made my virtualenv able to find gnuradio, but when I try importing stuff it fails in several different ways.
>>> from gnuradio import uhd
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py", line 21, in _prepare_uhd_python
from . import uhd_python
ImportError: cannot import name 'uhd_python' from partially initialized module 'gnuradio.uhd' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py", line 68, in <module>
_prepare_uhd_python()
File "/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py", line 26, in _prepare_uhd_python
from . import uhd_python
ImportError: cannot import name 'uhd_python' from partially initialized module 'gnuradio.uhd' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gnuradio/uhd/__init__.py)
>>> import pmt
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pmt/__init__.py", line 34, in <module>
from .pmt_python import *
ModuleNotFoundError: No module named 'pmt.pmt_python'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pmt/__init__.py", line 38, in <module>
from .pmt_python import *
ModuleNotFoundError: No module named 'pmt.pmt_python'
I have struggled with this for several days now and found no solution. Is it even possible to run GNU Radio from within a virtualenv?

I have struggled with this for several days now and found no solution.
Your distro's GNU Radio package is built against your distro's python, so you can't use it with a different python.
So, this is expected.
Is it even possible to run GNU Radio from within a virtualenv?
Sure, you'd need to build it from that virtualenv as well, and tell cmake -DCMAKE_INSTALL_PREFIX=/path/to/virtualenv/ to install into it.
We have a pretty nice anaconda packager, so installing GNU Radio into a Python prefix using conda might be the easiest alternative to that.
Alternatively:
Ubuntu 20.04.4 LTS
There's a new Ubuntu LTS version out! If you go for a system upgrade to Ubuntu 22.04 LTS, you get Python 3.10, and a current GNU Radio 3.10.1 "for free".

Related

Having trouble with the aiy-python-wheels on Raspberry Pi 3. How do I resolve incompatible glibc issue?

I've gotten my hands on a AIY voice kit v1 and am stuck with the assistant_grpc_demo.py with it failing at an import statement with the grpc. I should have everything installed already, yet google.auth.transport can't seem to find it. I am using a pi 3 A+. Below is the terminal commands I used and their outputs.
pi#raspberrypi:~ $ cat testinput.py
import google.auth.transport.grpc
pi#raspberrypi:~ $ python3 testinput.py
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/google/auth/transport/grpc.py", line 30, in <module>
import grpc
File "/home/pi/.local/lib/python3.7/site-packages/grpc/__init__.py", line 22, in <module>
from grpc import _compression
File "/home/pi/.local/lib/python3.7/site-packages/grpc/_compression.py", line 15, in <module>
from grpc._cython import cygrpc
ImportError: /lib/arm-linux-gnueabihf/libc.so.6: version `GLIBC_2.33' not found (required by /home/pi/.local/lib/python3.7/site-packages/grpc/_cython/cygrpc.cpython-37m-arm-linux-gnueabihf.so)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "testinput.py", line 1, in <module>
import google.auth.transport.grpc
File "/home/pi/.local/lib/python3.7/site-packages/google/auth/transport/grpc.py", line 37, in <module>
caught_exc,
File "<string>", line 3, in raise_from
ImportError: gRPC is not installed, please install the grpcio package to use the gRPC transport.
*Maybe the glibc part is the problem. Not sure how to resolve that as I already have libc6 2.28. Is there a way to get the aiy-python-wheels to work with my set-up or a previous version. Already tried flashing a pre-built official image built on 4-13-2018 with everything set up, though it failed to boot. Trying to download all packages manually. assistant_library_with_button.sh works though.
Not sure how to resolve that as I already have libc6 2.28
The error message says: .../site-packages/grpc/_cython/cygrpc.cpython-37m-arm-linux-gnueabihf.so requires GLIBC_2.33.
Your libc6 is too old for that gRPC package to work -- it was compiled on a newer system.
You must either:
get a different gRPC package -- one compiled on and suitable for running on a GLIBC-2.28 (or earlier) based system, or
get a different GLIBC package (2.33 or later).

IB API not installing properly on Mac

So I'm trying to use the IB API wrapper from here and I try running the first line
from ib_insync import *
but am getting the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/ib_insync/__init__.py", line 10, in <module>
import ibapi
ModuleNotFoundError: No module named 'ibapi'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/ib_insync/__init__.py", line 13, in <module>
'IB API from http://interactivebrokers.github.io is required')
RuntimeError: IB API from http://interactivebrokers.github.io is required
but I've downloaded the IB API from the IB github (had to use The Unarchiver to unzip) and saved it on my desktop. As far as I can tell there's no pip3 command I can use to install it so I'm not sure what else I can do to install the IB API. I've allowed ticked all the boxes for the API in TWS. I'm not sure why it's not installing properly?
It seems to be the same issue found here but mine is for macosx. I've tried running the commands from README.md and they don't work. It just says no such directory exists.
Installing the a python module as a wheel is optional- its also possible to just include the path to the module in the PYTHONPATH environment variable. But if you're using the commands from the READ.ME to build and install a wheel, make sure you're in the pythonclient folder and then run:
python3 setup.py bdist_wheel
python3 -m pip install --user --upgrade dist/ibapi-9.75.1-py3-none-any.whl
Thats for the current API Latest version as of March 2019 which is 975.1

ModuleNotFoundError: No module named 'Quartz'

I'm trying to work on python3 and using mac. I have installed pyobjc-core and pyobjc, but the error said Quartz not found. I'm very new to this kind of installing. Is there any solution?
Here is my error from pycharm:
Traceback (most recent call last):
File "/Users/Thyme/PycharmProjects/DinosourBot/venv/lib/python3.6/site-packages/pyautogui/_pyautogui_osx.py", line 5, in <module>
import Quartz
ModuleNotFoundError: No module named 'Quartz'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/Thyme/PycharmProjects/DinosourBot/Bot.py", line 2, in <module>
import pyautogui
File "/Users/Thyme/PycharmProjects/DinosourBot/venv/lib/python3.6/site-packages/pyautogui/__init__.py", line 110, in <module>
from . import _pyautogui_osx as platformModule
File "/Users/Thyme/PycharmProjects/DinosourBot/venv/lib/python3.6/site-packages/pyautogui/_pyautogui_osx.py", line 7, in <module>
assert False, "You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html"
AssertionError: You must first install pyobjc-core and pyobjc: https://pyautogui.readthedocs.io/en/latest/install.html
Process finished with exit code 1
In case anyone stumbles here use:
pip install pyobjc-framework-Quartz
I have solved the problem by
installing pyobjc-framework-Quartz,
it's provided by pycharm
I'd suggest it's best to install all of pyObjC, rather than just specific frameworks. Invariably, if you're working with Quartz, you're going to need various CoreFoundation objects and constants at the very least. To say nothing of AppKit, or other frameworks, depending on what you're doing.
pip install pyobjc (or pip3) should install everything and let you import Quartz. (It works for me on several pythons!)

Can't find submodule in package

I'm using Anaconda3 version 4.2.0 on ubuntu (in docker).
Anaconda is installed in /root/anaconda3 folder.
I installed theano_bpr package using pip install theano_bpr.
Now when i open python and try import theano_bpr, i get the following message:
>>> import theano_bpr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/anaconda3/lib/python3.5/site-packages/theano_bpr/__init__.py", line 17, in <module>
from bpr import BPR
ImportError: No module named 'bpr'
However, when i navigate to /root/anaconda3/lib/python3.5/site-packages/theano_bpr/ and run python there, i'm able to import theano_bpr.
In /root/anaconda3/lib/python3.5/site-packages/theano_bpr/ there are following files:
__init__.py, bpr.py (this one is causing problems), t.py, and utils.py.

Linux libs on freebsd (ibm_db libdb2.so.1)

Im trying to use a lib on bsd that was designed for linux for IBM-db connections:
I have installed as per the ibmdocs for linux, and placed the required linux libs in /compat/linux/lib/
But i get the import error:
>>> import ibm_db
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Shared object "libdb2.so.1" not found, required by "ibm_db.so"
If I place the file manually in /usr/lib or symlink it I get a read error:
>>> import ibm_db
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/libdb2.so.1: Undefined symbol "strcspn"
If anyone could help on this I would be forever grateful!!
I have installed ibm_db and both ibm_db_sa without failure, I just think its more of an issue trying to use the linux app on bsd.
Since it's looking for libraries in /usr/lib, you seem to be running the FreeBSD version of Python.
Since FreeBSD's Linux compatibility is a per process compatibility, you cannot load Linux libraries into a FreeBSD process. If you want to dynamically load Linux libraries, you need to run a Linux version of Python.

Categories

Resources