Showing content from http://reference.wolfram.com/language/workflow/EvaluateAWolframLanguageExpressionFromPython.html below:
Evaluate a Wolfram Language Expression from Python—Wolfram Documentation
WOLFRAM Consulting & Solutions
We deliver solutions for the AI eraâcombining symbolic computation, data-driven insights and deep technical expertise
- Data & Computational Intelligence
- Model-Based Design
- Algorithm Development
- Wolfram|Alpha for Business
- Blockchain Technology
- Education Technology
- Quantum Computation
WolframConsulting.com
Evaluate a Wolfram Language Expression from Python
Evaluate local Wolfram Language code directly from Python with a persistent kernel session.
Using a Wolfram notebook... Create a local Wolfram Language session
Import the module:
from wolframclient.evaluation import WolframLanguageSession
Create a session using the default path:
session = WolframLanguageSession()
- The default path depends on the environment and may also depend on the version of the Wolfram Engine being used.
- To create a session with a nondefault path, provide the path to the Wolfram Engine as the first argument, e.g.: WolframLanguageSession(‘C:/Program Files/Wolfram Research/Mathematica/12.0/wolfram.exe’).
Evaluate Wolfram Language expressions
Import the function:
from wolframclient.language import wlexpr
Compute the squares of an array of integers:
session.evaluate(wlexpr('Map[#^2 &, Range[5]]')) End the the session
Terminate the session object:
- The session must be terminated to properly shut down the Wolfram Engine process.
Using a Jupyter notebook... Create a local Wolfram Language session
Import the module:
Create a session using the default path:
- The default path depends on the environment and may also depend on the version of the Wolfram Engine being used.
- To create a session with a nondefault path, provide the path to the Wolfram Engine as the first argument, e.g.: WolframLanguageSession(‘C:/Program Files/Wolfram Research/Mathematica/12.0/wolfram.exe’).
Evaluate Wolfram Language expressions
Import the function:
Compute the squares of an array of integers:
End the the session
Terminate the session object:
- The session must be terminated to properly shut down the Wolfram Engine process.
Using the command line... Create a local Wolfram Language session
Open a terminal window and invoke the Python interpreter:
Import the module:
>>> from wolframclient.evaluation import WolframLanguageSession
Create a session using the default path:
>>> session = WolframLanguageSession()
- The default path depends on the environment and may also depend on the version of the Wolfram Engine being used.
- To create a session with a nondefault path, provide the path to the Wolfram Engine as the first argument, e.g.: WolframLanguageSession(‘C:/Program Files/Wolfram Research/Mathematica/12.0/wolfram.exe’).
Evaluate Wolfram Language expressions
Import the function:
>>> from wolframclient.language import wlexpr
Compute the squares of an array of integers:
>>> session.evaluate(wlexpr('Map[#^2 &, Range[5]]'))
[1, 4, 9, 16, 25]
End the the session
Terminate the session object:
Exit the Python shell:
- The session must be terminated to properly shut down the Wolfram Engine process.
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4