35

Get all the files here. .NET Mathematica Word Library You will need to use a Microsoft library to open word documents. In a language such as .Net it is very easy; just open Visual Studio, reference the Microsoft.Office.Interop.Word .NET DLL (for Words) and the C:\Program Files\Open XML SDK\V2.5\lib\DocumentFormat.OpenXml.dll (for Formulas in the MathML ...


33

Mathematica 12.0 brings two new features that make this easier to do than it was before: ExternalFunction Wolfram Client for Python Below we implement a function nxFunction that automatically handles translating Mathematica expressions of interest to Python, as well as converting the results back. The usage will be nxFunction["someNetworkxFunction"][...


20

This is a quick example of calling the exported compiled function from a standalone executable on Windows. A few things to note which are currently undocumented and that can definitely be subject to change (and improvement) in the future: the function is named Main by default and the example uses an explicit prototype rather than including a header file; ...


17

I believe you're not in the correct direction, optimizing your Mathematica code should be more practical and easier. (You've already learned the numeric capability of Mathematica under your previous question, don't you? ) Anyway, here's my attempt to minimize your toy function f using Python in Mathematica. I know little about Python, feel free to point out ...


15

The command Run will do exactly that. For example, try Run["touch ~/Desktop/blankfile"] If you want to read the results back in, there are a few options, and the choice between them depends on exactly what you want to do. The RunThrough command lets you read the output of a command-line back as a Mathematica expression. For example, try RunThrough["bc", ...


15

To get this out of the way: I believe the Import::nopythonevals message will be issued by Import[..., "PythonExpression"] if there are no usable external evaluators set up. First make sure that you have set up Python correctly (including installing pyzmq), and registered an external evaluator. As you can see in my question, I have already done this, yet ...


14

You will find a complete, step by step description of how to write such a program here. Here's a small test program that adds 42 and 137, written by following the tutorial closely: /* mlcall.c */ #include <mathlink.h> #include <stdio.h> int main(int argc, char *argv[]) { MLENV env; MLINK link; int errno; int packet; env = ...


14

Update: As of version 12, one should use FindExternalEvaluators["Python", "ResetCache" -> True] To turn my comment into an answer, ExternalEvaluate keeps a cache of evaluators it has found or used previously, and sometimes it can make invalid data persist. In such cases, it is often useful to start with a clean slate, using the ...


14

The first solution will use socket to connect python and Mathematica. We'll set up a server that returns the result of the function that has been defined in Mathematica and on the python side, we'll connect to the server and pass the function's inputs and receive the output. We'll use SocketListen which was introduced in Mathematica 11.2. To keep the first ...


13

(Reposting my comment as an answer) The reason this is happening is that the Mathematica launcher script sets LD_LIBRARY_PATH so that libraries included in the layout will be found and used, and that setting is inherited by any external process started from the kernel. But, sometimes it may happen that the external executable is linked against a conflicting ...


13

You can use TravelDistance and related functions to find the distance by road. Example: TravelDistance[Entity["City", {"Tokyo", "Tokyo", "Japan"}], Entity["City", {"Osaka", "Osaka", "Japan"}]] (* Quantity[511.606, "Kilometers"] *) td = TravelDirections[{Entity["City", {"Tokyo", "Tokyo", "Japan"}], Entity["City", {"Osaka", "Osaka", "Japan"}]}]; ...


13

Seems to be able to embed images by converting to png. import io from PIL import Image import matplotlib.pyplot as plt def show_plt(plot): buf = io.BytesIO() plot.savefig(buf, transparent=True, format='png') buf.seek(0) im = Image.open(buf).convert("RGBA") buf.close() return im In fact, matplotlib can export svg, but wolfram does ...


12

The issue here is that when Mathematica executes an external system command, at least on Linux, it does so from the current directory. You can verify this via Directory[] Run["! echo $PWD > file.txt"]; FilePrint["file.txt"] which is my default working directory. I actually have a line in my /home/jason/.Mathematica/Kernel/init.m file that says ...


12

This has to be done at the stylesheet level and here's a way to do it. First we'll make a new CellEvaluationFunction that uses the TaggingRules to bind the ExternalSessionObject. Then we'll attach that to the "ExternalLanguage" cell. Here's the function: currentCellExternalSessionEvaluate = Function[ With[{ExternalEvaluate`FE`Private`cell = ...


12

Type > at the start of a cell (or when between cells). This is documented in an example on ref/ExternalEvaluate (last Basic Example). I'm a bit suprised it's not in the details section. It probably should be...


11

I think you can find what you're looking for here:


11

A class who inherits the WLSerializable class and overrides the to_wl method can be automatically converted. from wolframclient.serializers.serializable import WLSerializable from wolframclient.language import wl from wolframclient.serializers import export class MyPythonClass(WLSerializable): def __init__(self, *arguments): self.arguments = ...


10

The problem is that the stdin stream for each process is being left open and needs to be closed. To demonstrate the issue, we create a single process: $process = StartProcess[$SystemShell]; WriteLine[$process, "echo example line"]; KillProcess[$process]; The call to WriteLine implicitly creates a stream object. Even though the process has been killed, ...


10

Under most operating systems you can use the 2>&1 handle redirection operator(1),(2): Import["!foo 2>&1", "Text"] "'foo' is not recognized as an internal or external command, operable program or batch file."


9

For those who will encounter the same problem as mine (and OP's), I added this answer. Mathematica now(since 10.0.0) has a new built-in function called RunProcess which does exactly what OP asked (including the standard error).


9

We had a bug like this on v. 10: it specifically stopped running new processes after you created 100 of them. This was fixed in version 10.0.1. I recommend testing it there, as version 10.0.1 has a number of improvements with respect to StartProcess. I can't test your example in MacOS right now, so please let me know if this isn't working on v. 10.0.1. ...


8

On Windows this works: Run["taskkill /im chrome.exe /f"] Run["taskkill /im WolframPlayerPro.exe /f"]


8

There are many ways to do this on a Mac. For example to open Safari: << "!open -a Safari" To open Safari to a particular file or page: << "!open -a Safari http://mathematica.stackexchange.com/questions/69247/how-to-close-external-app-from-mathematica" Now to close Safari: << "!osascript -e 'tell application \"Safari\" to quit'"


8

The problem has nothing to do with OpenWrite. You never Close the stream you open in your call to Read. Read, unlike ReadList, does not automatically close a stream (file, pipe, etc.) that's given as its first argument string. (That's because the purpose of Read is to be able to read from the same source in pieces, unlike ReadList which does it all at ...


8

The number 2045 is suspicious. Add three to it to include stdin, stdout, and stderr, and you get 2048, which I suspect is total number of file descriptors available to you. I conclude your problem is caused by eating up all the available file descriptors. This is usually caused by doing too many file opens without doing any file closings to return some file ...


8

I think this is an OS X issue. Note that if you launch Mathematica from a terminal, you will get the value of Environment["PATH"] which you expected. For GUI applications that are started through Finder/LaunchServices, the environment (and $PATH in particular) is different and determined by the OS (this is a related recent question that had to do with ...


8

I'm Riccardo Di Virgilio, one of the developers of ExternalEvaluate and wolframclientforpython. There is a way to do what you want, even if the function is not documented or exposed, so the code I'm giving to you might break in future versions. try to run this in ExternalEvaluate: from wolframclient.language.side_effects import wl_side_effect from ...


7

Your RunProcess works properly in all examples and System settings are fine. As @Oleksandr R. has admitted, date is a shell builtin on Windows. So there are commands date /t and time /t in cmd Windows shell that can be used instead. In Mathematica for Windows: $SystemShell == "cmd" (* True *) So something like: RunProcess[{"cmd", "/c", "date /t&&...


7

It will work if you send a newline at the end of dir: RunProcess[$SystemShell, All, "dir\n"] (* note the \n *) What I do not understand is why this newline is not necessary when running the equivalent command on Unix-like systems. On OS X, the following works: RunProcess[$SystemShell, All, "ls"] (* no \n needed *) Update: As pointed out by Itai, the ...


7

Files Let's create some test files Table[ Export[ StringTemplate["Test``.jpg"][k], Rasterize@TextCell[ RandomChoice[DictionaryLookup["*"]], RandomChoice[{"Text", "Subsection", "Section", "Title"}] ] ] , {k, 10} ] RunProcess Test a single file using RunProcess (advisable). RunProcess[ { "C:\\Program Files (x86)\\Tesseract-OCR\\...


Only top voted, non community-wiki answers of a minimum length are eligible