Errors calling python scripts in virtual environment on raspberry pi (MCC Daqhat Library) – with a possible answer
I’m posting this mostly as help to someone else trying to develop a system using MCC’s DAQHATS. There are very little resources regarding using Daqhats from MCC from Matlab (unsupported) or MCC.
The installation of the DAQHAT python library requires that it be installed into a virtual environment. That was causing us issues expecially when we need to run 2 scripts back to back. It would close the virtual environment after the first script.
The following is the question we submitted to Matlab’s help team:
Description: We are using MCC Daqhats. First, I know this is not a supported hardware for Matlab. We are not asking for support for that. However, in the process of installing the python libraries for the Daqhats, we are forced to install them into a virtual environment. We believe this is causing us problems. We need to run multiple scripts in a row. We think that after the first call it is exiting the virtual environment but we are not certain of that.
The matlab file calling the python script is attached. The python script we are calling is attached. We have tested the python script on the PI and it runs properly both from python and the command line.
here is our Matlab error:
Error using datacollection
Error executing command "python3 /home/aset/daqhats/examples/python/mcc172/bert2.py". Details:
STDERR: Traceback (most recent call last):
File "/home/aset/daqhats/examples/python/mcc172/bert2.py", line 3, in <module>
from daqhats import mcc172, OptionFlags, SourceType, HatIDs, HatError
ModuleNotFoundError: No module named ‘daqhats’
Our Solution was as follows: (However others may have a better solution)
We have been able to get it to work by explicitly calling the virtual environment in the system command. This was found using a resource other than a Matlab site.
system(rpi, ‘/home/aset/environments/bin/python3 /home/aset/daqhats/examples/python/mcc172/bert2.py’)I’m posting this mostly as help to someone else trying to develop a system using MCC’s DAQHATS. There are very little resources regarding using Daqhats from MCC from Matlab (unsupported) or MCC.
The installation of the DAQHAT python library requires that it be installed into a virtual environment. That was causing us issues expecially when we need to run 2 scripts back to back. It would close the virtual environment after the first script.
The following is the question we submitted to Matlab’s help team:
Description: We are using MCC Daqhats. First, I know this is not a supported hardware for Matlab. We are not asking for support for that. However, in the process of installing the python libraries for the Daqhats, we are forced to install them into a virtual environment. We believe this is causing us problems. We need to run multiple scripts in a row. We think that after the first call it is exiting the virtual environment but we are not certain of that.
The matlab file calling the python script is attached. The python script we are calling is attached. We have tested the python script on the PI and it runs properly both from python and the command line.
here is our Matlab error:
Error using datacollection
Error executing command "python3 /home/aset/daqhats/examples/python/mcc172/bert2.py". Details:
STDERR: Traceback (most recent call last):
File "/home/aset/daqhats/examples/python/mcc172/bert2.py", line 3, in <module>
from daqhats import mcc172, OptionFlags, SourceType, HatIDs, HatError
ModuleNotFoundError: No module named ‘daqhats’
Our Solution was as follows: (However others may have a better solution)
We have been able to get it to work by explicitly calling the virtual environment in the system command. This was found using a resource other than a Matlab site.
system(rpi, ‘/home/aset/environments/bin/python3 /home/aset/daqhats/examples/python/mcc172/bert2.py’) I’m posting this mostly as help to someone else trying to develop a system using MCC’s DAQHATS. There are very little resources regarding using Daqhats from MCC from Matlab (unsupported) or MCC.
The installation of the DAQHAT python library requires that it be installed into a virtual environment. That was causing us issues expecially when we need to run 2 scripts back to back. It would close the virtual environment after the first script.
The following is the question we submitted to Matlab’s help team:
Description: We are using MCC Daqhats. First, I know this is not a supported hardware for Matlab. We are not asking for support for that. However, in the process of installing the python libraries for the Daqhats, we are forced to install them into a virtual environment. We believe this is causing us problems. We need to run multiple scripts in a row. We think that after the first call it is exiting the virtual environment but we are not certain of that.
The matlab file calling the python script is attached. The python script we are calling is attached. We have tested the python script on the PI and it runs properly both from python and the command line.
here is our Matlab error:
Error using datacollection
Error executing command "python3 /home/aset/daqhats/examples/python/mcc172/bert2.py". Details:
STDERR: Traceback (most recent call last):
File "/home/aset/daqhats/examples/python/mcc172/bert2.py", line 3, in <module>
from daqhats import mcc172, OptionFlags, SourceType, HatIDs, HatError
ModuleNotFoundError: No module named ‘daqhats’
Our Solution was as follows: (However others may have a better solution)
We have been able to get it to work by explicitly calling the virtual environment in the system command. This was found using a resource other than a Matlab site.
system(rpi, ‘/home/aset/environments/bin/python3 /home/aset/daqhats/examples/python/mcc172/bert2.py’) mcc, daqhat, virtual enviroment MATLAB Answers — New Questions