I'm doing simulations with Adams Car 2020 and Python. I use the internal Adams Python functionality. In this internal python environment I don't have matplotlib available for example. Therefore I've created a virtual python environment which has extra packages which I start from Adams Car Python as a subprocess.
Before we start Adams Car we set some of the environment variables with a Batch file, let's say set_env.bat. I need these environment variables as well when I start python in the virtual environment. I can do this with a batch file where I first call set_env.bat and then call the virtual env Python:
start_ext_python.bat:
call set_env.bat
call <path_to_python_virtual_env> %1
where the first argument is the path to the python script I want to execute.
I would like to use Vscode debugging and call set_env.bat. Therefore I made a task which I refer to in launch.json:
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "init_acar",
"type": "shell",
"command": "C:\\User\\lj012145\\Git\\Adams\\source_a2cm\\bat\\ADAMS_Set_Environment.bat"
}
]
}
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Test adams external file",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"preLaunchTask": "init_acar",
"args": [],
},
]
}
This runs the bat file first but the environment variables are not set anymore when I stop the debugger in my python script.
I could also create a set_env_vscode.bat which writes to a .env file which I refer to then but I'm not sure if that is a good approach..