When I try to run a Python script in Matlab using the system command, it works find until I import something that doesn't come with base Python.
For example, if I have a script test_1.py:
import math as m
print 'good to go'
print m.exp(7)
and I run the Matlab command:
>>> system('python test_1.py')
I get back
good to go
1096.63315843
ans =
0
which is what I want. But if I modify test_1.py to be
import math as m
import pandas as pd
print 'good to go'
print m.exp(7)
and run
>>> system('python test_1.py')
I get:
>> system('python test_1.py')
Traceback (most recent call last):
File "test_1.py", line 1, in <module>
import pandas as pd
ImportError: No module named pandas
ans =
1
Both scripts run fine when I run them in my Bash terminal and the problem doesn't seem to be specific to the Pandas library.
I checked Matlab's documentation and some other StackOverflow questions but I can't find anything closely related to my issue.
which python
called from bash and from MATLAB? – hbaderts Dec 1 '16 at 18:28system('source activate;python test_1.py')
– TheBlackCat Dec 1 '16 at 18:33which activate
, then replaceactivate
in my previous comment with the full path? So saywhich activate
gives/Users/JackStClaire/anaconda/bin/activate
, usesystem('source /Users/JackStClaire/anaconda/bin/activate;python test_1.py')
. – TheBlackCat Dec 1 '16 at 18:41