- Regarding your python call: are you on a recent version of MATLAB? You can call the script directly using MALTAB's py syntax. If you type pyenv at the command line it should display what version of Python MATLAB thinks is available. It might be cleaner for MATLAB to handle spinning up and down the Python instance? It should also be a nicer interface if you are exchanging data.
- Environment Variables: See if MATLAB is reading them correctly? Type !set in the command window of your environment to get a listing (Windows assumed)
- Segfault: If MATLAB is not directly interacting with the script or its variables, the segfault makes me think the problem is when something returns from the system call. How far along does it get if you ask the program to system('python script.py', '-echo')? If you alter an environment variable along the way, MATLAB will not see the change and react...poorly.
Segmentaion fault while calling Python script using system()
8 次查看(过去 30 天)
显示 更早的评论
I'm using system() to call an external python script that does some file processing for me but I get a segmentation fault with exit code 139 when I try and run. EX: system('python my_python_script.py')
I am confident that it is not an issue with the python script as I can run it successfully through the terminal without Matlab. The script uses some environment variables and all of my python libraries are installed in a virtual environment (where I launch Matlab from). I'm thinking the issue is either with the virtual environment or the environment variables but I am not 100% sure what to do to ensure that the all the dependencies are shared between Matlab's sytem call and my normal terminal call to the script. I've reviewed the information on this site: https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html but I'm not sure about the environment variables. Any suggestions?
EDIT: I should have added more information. I am running on Ubuntu 16.04 and Matlab 2021a. The python script does some parallel processing of data and saves off the results that Matlab does not need access to. Really I just want to call the Python script in a loop with variable inputs as the Matlab script does some of the pre-processing before the Python script can run. I also checked that Matlab's system call has access to the environment variables that the Python script uses and it does so I believe it's an issue with one of the libraries that Matlab uses that is incompatible with what I am trying to do in Python. I don't know how to find out which library might be causing this however if that is the case.
0 个评论
回答(1 个)
Peter O
2021-7-7
A couple thoughts:
Does any of that help? What sort of processing are we talking here? Are MATLAB and Python looking into the same memory space? Which version of Python? Anaconda or stock?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Python from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!