How do get all of my python libraries in matlab?
Show older comments
I wrote a python script that will open a .BIN file, I wrote it in python because the file is really complicated. Some data within the file are 16 bit, some are 8 bit, and some is 32 bit, either way it was easier to write in python. Now im trying to open this file in matlab as part of an app that im working on. The original data are these .BIN files, I want to convert them to CSV (which the python code does) and then open those CSVs in my matlab code for processing. The python code works great, and my matlab code works great if I just use the output of the python file but when I try to run the python code within the matlab code I get all sorts of errors.
First I ran pyenv to make sure im running from the right directory and with the right version of python, here is the result:
ans =
PythonEnvironment with properties:
Version: "3.12"
Executable: "D:\pythonw.exe"
Library: "D:\python312.dll"
Home: "D:"
Status: Loaded
ExecutionMode: InProcess
ProcessID: "33048"
ProcessName: "MATLAB"
Idk if thats what I need but it looks similar to what I see in other tutorials. Afterwords I tried pyrunfile('mypythonfile.py') and got this:
Error using <string>><module> (line 4)
Python Error: ModuleNotFoundError: No module named 'pandas'
I then found the pandas module in my python library and added to my path. I got another error when running agian for a different library, I kept adding to path until I eventually got to this:
Error using __init__><module> (line 32)
Python Error: ImportError: Unable to import required dependencies:
numpy: No module named 'numpy'
pytz: No module named 'pytz'
dateutil: No module named 'dateutil'
I tried adding a path to all 3 of these and got this error:
Error using __init__><module> (line 32)
Python Error: ImportError: Unable to import required dependencies:
numpy: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
My question is: what am I doing wrong here? Ive tried numerous times to open this file in matlab with no success, im not sure if I over complicating it or im missing something obvious. Ive read through the matlab documentation on running python codes but none of them worked, how do I make sure I have all the right libraries where I need them? Thanks!
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!