< Back

Running PyTecplot without having to call the tec360-env script


If you are on macOS or Linux, you may know that PyTecplot does not work in batch mode unless the ‘tec360-env’ script is run or evaluated. While this is not a big inconvenience, and the full process is detailed in the PyTecplot documentation, some may want a way to avoid this entirely. For example, if you handle many users who want PyTecplot to “just work” without the user having to set anything outside their Python file, this might be for you.  

Insert the following chunk of code inside any Python file utilizing PyTecplot in batch mode:  

import os 
import subprocess 
import sys 
import platform 

if platform.system() == "Darwin": 
  env_script_path = "/Applications/Tecplot 360 EX 2025 R2/bin/tec360-env" 
elif platform.system() == "Linux": 
  env_script_path = "/path/to/Tecplot/bin/tec360-env" 
  FLAG = "IN_ENV" 

def in_env(): 
  return os.environ.get(FLAG) == "1" 
  if not in_env() and platform.system() != "Windows": 
    # Relaunches THIS file, but with the flag IN_ENV set. 
    # All output should be piped to the same terminal 
    subprocess.run(
      [
        env_script_path, "--", 
        sys.executable, # using this rather than just 'python' ensures the same python instance
      ] + sys.argv[1:], 
      env={**os.environ, FLAG: "1"}, # run with flag set check=True) 
    raise sys.exit()


# ---all code goes below this line and runs ‘inside’ the env--- 
# Ex: import tecplot as tp 
# tp.new_layout()

What this does: 

The above code will attempt to evaluate the tec360-env script from within the terminal it’s using. That means you still have to ensure that the path is valid. A default location is given on macOS, but it may need to changedepending on where you installed Tecplot 360.  

Reminder that the tec360-env script in question is inside your Tecplot 360 installation at {MainInstallDirectory}/bin/tec360-env 

After the code above has run that env script, it then uses a built-in python library to launch a subprocess. This subprocess then runs the very same file, with this new “tec360-env enabled” context, skipping over the env read, and going straight to whatever you put below the block of code. In this way, it has the illusion of running as a single file, while actually setting the necessary info and running a subprocess again. 

For those interested, the script is available on our Handyscripts repository. 

This use case may not be applicable for all users, and your mileage may vary with its effects, but we have had a positive reaction from users who have tried it out.