Recent versions of Wolfram Language support Python virtual environments that let you specify Python packages quite easily. For example, this creates a session with a Python virtual environment that includes the sympy
package:
session = StartExternalSession[<|
"System" -> "Python",
"Evaluator" -> <|"Dependencies" -> {"sympy"}|>,
"SessionProlog" -> "from sympy import symbols, Eq, solve"|>]
You can then use ExternalEvaluate and call Python code, for example:
ExternalEvaluate[session, "
x, y = symbols('x y')
equation = Eq(x**5 - 4, 0)
[complex(s) for s in solve(equation, x)]"]
The output will be a list of complex numbers:
{1.31951 + 0. I, 0.40775 - 1.25493 I, 0.40775 + 1.25493 I, -1.0675 - 0.775587 I, -1.0675 + 0.775587 I}
Of course you can solve this specific example directly in the Wolfram Language as well and much more elegantly:
SolveValues[x^5 == 4.0, x]
But if you have existing Python sympy
code that you would like to integrate directly into the Wolfram Language, then this is the best way to do it. I have attached a notebook with the code from this comment.
Attachments: