Reputation: 31
I would like to create a Python script for Abaqus in which Scipy library will be used. Unfortunately, Abaqus doesn't have that library. It could be installed but I would like to do it differently.
My idea is to write a function which will take arguments, pass it to new Python interpreter opened outside Abaqus and then it returns the output to my file.
I am pretty sure it might be done but I am still learning Python. Please give me any hint I could used to solve my problem.
Upvotes: 1
Views: 723
Reputation: 1832
In order to achieve what you want, you need to start a background process, which will execute a Python script. This can be done in Python via a built-in subprocess
module.
In the simplest case, you would write something like this:
import subprocess
process = subprocess.Popen(['python', 'your_script_name.py'])
process.wait() # If you want to stop caller until callee terminates
It is also possible to retrieve results returned by sub process, but you can read more about it in other threads:
Just be aware that, in some cases, it is necessary to modify the contents of dictionary containing environment variables (os.environ
) by removing Abaqus specific environment variables. Otherwise there are some issues starting a sub process.
If you do want to pass modified environment to a new process, Popen
has an argument env
.
Upvotes: 1