so I'm running into a strange problem using Import[]
to import the output of a python 3.6 script.
I have a script my_script.py
which just contains print('Hello, World!')
.
If from within Mathematica I pass
pythonOutput = Import["!python my_script.py", "String"]
I get the expected
Hello, world!
However, I am on Mac OS where the default installation of python is python 2.7 and so if I want to run my code in python 3.x in the terminal I would have to say
python3 my_script.py
(which works fine)
However, when I modify my Mathematica code to say
pythonOutput = Import["!python3 my_script.py", "String"]
I get no output! Does anyone know why this might be the case? The command python3 my_script.py
works perfectly fine from the terminal but not within an Import statement.
I have also tried every suggestion from this question and none of them work with the python3 command.
Environment["PATH"]
. Generally the python3 binary lives at /usr/local/bin/python3. In Mathematica I haveEnvironment["PATH"]
being "/usr/bin:/bin:/usr/sbin:/sbin". FurthermoreRunProcess[{"python3", ExpandFileName@"~/Desktop/my_script.py"}, ProcessEnvironment -> <| "PATH" -> "/usr/local/bin:" <> Environment["PATH"] |>]
works but sansProcessEnvironment
it fails. $\endgroup$