Can I change defaultPython dynamically?

Typically: "How do I... ", "How can I... " questions
Post Reply
javl0p
Posts: 25
Joined: 24 Mar 2023, 10:42

Can I change defaultPython dynamically?

Post by javl0p »

Hello.

As a developper in a company with multiple repositories, we often work with multiple python environments, which we generally manage through poetry.

We are able to set specific python environments by modifying the userset.txt file (defaultPython). However, this modification is not practical if we have to run Coppelia on multiple environments or in newly created ones (for example, those created under a CI/CD routine).

I've found that the defaultPython variable is read and saved as an App Property. However, based on documentation, this app property is not writable. So I understand that it is not possible to change it once Coppelia has been started.

Let's imagine, for example, that I am launching Coppelia from a python script. Is there a way to dynamically change this variable that doesn't involve writting the usrtset.txt file before launching Coppelia?

Cheers!
coppelia
Site Admin
Posts: 10747
Joined: 14 Dec 2012, 00:25

Re: Can I change defaultPython dynamically?

Post by coppelia »

Hello,

not sure I understood you correctly, but you can set the Python executable for every simulation script you wanna launch with something like:

Code: Select all

#python

#luaExec pythonExecutable = 'c:/python38/python.exe'

# Here your Python code
You can also dynamically do this with something like:

Code: Select all

#python

#luaExec pythonExecutable = sim.getStringProperty(sim.handle_app, 'signal.pythonExec')
And adjust the value of that string signal somewhere else with:

Code: Select all

sim.setStringProperty(sim.handle_app, 'signal.pythonExec', 'c:/python38/python.exe')
Cheers
javl0p
Posts: 25
Joined: 24 Mar 2023, 10:42

Re: Can I change defaultPython dynamically?

Post by javl0p »

Thank you so much.

I will try this but it looks good to me.

Cheers!
Post Reply