Dim sh As New Shell
sh.Execute("python", textfield1.text)
TextArea1.Text = sh.Result
The script is intended to gather some data, display a graph in png format and then save the graph as a file. This works fine when running the python script from the Terminal as well as running it from Idle. Unfortunately, it only works partially when launched from Xojo. It successfully gathers the data and displays the graph, but it doesn’t save the file and throws a Permission denied error. Any suggestions as to why it works in Terminal and Idle but not when launched from Xojo?
Traceback (most recent call last):
File "/Users/chris/Documents/football_graph.py", line 29, in <module>
plt.savefig('sample_m.png')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py", line 561, in savefig
return fig.savefig(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backend_bases.py", line 2220, in print_figure
**kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backend_bases.py", line 1962, in print_png
return agg.print_png(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/backends/backend_agg.py", line 510, in print_png
filename_or_obj = open(filename_or_obj, 'wb')
IOError: [Errno 13] Permission denied: 'sample_m.png'
try expressing a FULL PATH in savefig instead of just a filename… otherwise it will attempt to save it one place in DEBUG mode and somewhere else in COMPILE mode
Xojos shell is not running bash, zsh, tcsh etc. like you get in terminal and those command interpreters are what expand the ~ to mean your home directory.
From http://documentation.xojo.com/index.php/Shell
The Shell is not equivalent to the Terminal or Command app for your OS. Paths and other default settings will likely not be the same. If you need to do configuration of the Shell before you use it, be sure to set it up to be interactive so you can set up the configuration before calling other shell commands.
That probably could have been worded better. It doesn’t start bash up the same way that Terminal does. Terminal runs all your login scripts & several others to initialize bash - Xojo shell doesnt.
Hence why we tell people:
The Shell is not equivalent to the Terminal or Command app for your OS. Paths and other default settings will likely not be the same. If you need to do configuration of the Shell before you use it, be sure to set it up to be interactive so you can set up the configuration before calling other shell commands.