It's often helpful to have different environments so that you can test changes and let other users test your changes before deploying updates to a production environment.
See also How can I distribute my PyXLL functions to other users?
1. Using the "pyxll activate" command
You can maintain separate code bases for your different environments, and even different Python interpreters, and switch between them before starting Excel.
You can have completely separate PyXLL instances, configured independently, and switch between them using the "pyxll activate" command. This is the easiest way to switch between different PyXLL instances and have complete separation between your environments. The "pyxll activate" command is documented here https://www.pyxll.com/docs/userguide/installation/cli.html#pyxll-activate.
For example, to switch to a PyXLL instance installed in a dev folder you would do the following:
> pyxll activate C:\Your Folder\Dev PyXLL Environment
You could script this in a .bat file if you wanted to launch Excel after activating a specific PyXLL instance. You can use the "--non-interactive" switch to "pyxll activate" to prevent it prompting for any user input.
2. Using different pyxll.cfg files
Another way is to leave the same pyxll.xll add-in file installed and switch which config file is used. You can have different config files for each environment, pointing at different code folders and modules, and even different Python installations.
See also Managing multiple PyXLL configs
To tell the PyXLL add-in to load a specific config file, set the "PYXLL_CONFIG_FILE" environment variable. This can be done in a script before launching Excel.
Making it clear what environment is in use
If you are switching between environments it may not be immediately obvious which environment you are currently using just by looking at Excel.
Setting the name of the environment as an environment variable in your different pyxll.cfg files is a good way to keep track of what environment is active.
See also Environment Variables
One way to make it clear is to change the name of the ribbon tab in your add-in based on the current environment being used. You can do this using the "getLabel" attribute on the ribbon tab in your ribbon xml file instead of the usual "label" attribute.
For example, in your ribbon xml file you might have something that looks like this:
...
<tabs>
<tab id="myAddin" label="My Excel Add-in">
...
You can use "getLabel" instead to call a Python function that will return the label to use, for example:
...
<tabs>
<tab id="myAddin" getLabel="pymodule.getRibbonLabel">
...
Now in a Python module ("pymodule.py" in this case) you write the "getRibbonLabel" function, which can use the environment variable containing the environment name, for example:
import os
def getRibbonLabel(control):
env = os.environ.get("MY_PYXLL_ENVIRONMENT_NAME") # dev/qa/prod/etc
return f"My Excel Add-in [{env}]"
See also Customizing the Ribbon