1

I have created a virtual environment containing packages I need for some python out of tree blocks. When I activate the virtual environment and attempt to run the flowgraph from companion, it complains that the special packages I included in my virtual environment cannot be found.

Interestingly, I can successfully run from the command line the .py version of the flowgraph automatically generated by GnuRadio Companion.

How can I get this to work under Gnu Radio Companion?

As a specific example, I created a virtual environment containing the pandas package and attempted to import pandas in a no_block type custom python block originally created with gr_modtool. I did the install with the virtual environment activated. While running the flowgraph from the command line works fine, I get the following error when attempting to run the same flowgraph from GRC (which was opened from the command line with the virtual environment activated):

Traceback (most recent call last):
  File "/home/my_name/devel/gr-my_oot_module/examples/my_flowgraph.py", line 35, in <module>
    import my_oot_module
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/my_oot_module/__init__.py", line 39, in <module>
    from .my_noblock_block import my_noblock_block
  File "/home/my_name/devel/gnuradio3_8/lib/python3.6/dist-packages/my_oot_module/my_noblock_block.py", line 25, in <module>
    import pandas
ModuleNotFoundError: No module named 'pandas'
rhz
  • 960
  • 14
  • 29
  • so, there's no pandas in your environment, which has nothing to do with GNU Radio! – Marcus Müller Jan 02 '20 at 19:52
  • I think pandas is in my environment. If there were no pandas in my environment, how would my .py flowgraph (the one created by GRC) run when called from the command line (via python3 my_flowgraph.py) with the virtual environment activated? Also, with the virtual environment deactivated running the flowgraph from the command line fails (as expected). – rhz Jan 03 '20 at 00:04
  • I'm sorry, but this all has nothing to do with GNU Radio, but how your virtualenvs are set up, which I can't inspect from here. – Marcus Müller Jan 03 '20 at 00:12
  • 1
    I dug a little bit and think I can at least see part of why the virtual environment isn't used in when I run gnuradio-companion. The gnuradio-companion script is a python file with a shebang line at the top: #!/usr/bin/python3 which is not the path to the VE interpreter. – rhz Jan 10 '20 at 22:53
  • oh, interesting! – Marcus Müller Jan 10 '20 at 23:35
  • do you have a different version of python3 than 3.6 installed outside your virtual environment? Can you add the exact way you set up your virtual environment? Because every version of python respects exactly the same environment variables telling it where to look for packages (`$PYTHONPATH`), so that would be the only explanation. – Marcus Müller Jan 10 '20 at 23:39
  • It's 3.6 for everything. If I modify the PYTHONPATH variable in the activate script for the virtual environment to include the path to the site-packages under the virtual environment, then those packages are found under the VE when running GRC. However, it's still not using the python interpreter under the VE. os.executable is /usr/bin/python3.6 when running under GRC and /home/my_name/virtual_environments/my_ve/bin/python when running the .py from the command line. – rhz Jan 20 '20 at 21:13

1 Answers1

0

You have to realize that this is standard python under the hood. If you don't start gnuradio-companion from within your activated environment, Python can't find the modules therein. That's the whole idea of virtual environments.

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94