It can sometimes be necessary to manage multiple different PyXLL configs. For example, if have a config that you use for your production environment and you also want a development or testing config for your own use or to give other users for trying out new features before you deploy them to your whole team.
Below are some ways to manage different PyXLL configurations. These methods can also be combined as necessary.
- Using "pyxll activate" to switch between PyXLL installs
- Using multiple PyXLL config files
- Using environment variables in your PyXLL config
- Using external_config to combine configs
Using "pyxll activate" to switch between PyXLL installs
One common scenario is where you want to have completely independent PyXLL installs. For example, either for different unrelated applications, or for development, testing and production versions.
The pyxll activate command allows easy switching between PyXLL versions.
You can have PyXLL installed in multiple different locations, with different configurations (and can also be different PyXLL versions, using different Python environments), and use this to switch between them quickly.
Using multiple PyXLL config files
You can switch the pyxll.cfg file that PyXLL uses by setting the environment variable PYXLL_CONFIG_FILE. You can set this environment variable on your PC, or you can create a batch file (.bat) to set the environment variable before starting Excel. For example,
REM run-excel-dev.bat
REM Starts Excel with the dev pyxll config file
SET PYXLL_CONFIG_FILE=X:\pyxll\pyxll-dev.cfg
START "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
You can create shortcuts on your desktop to these .bat files to make it easy to launch Excel with different settings.
Using environment variables in your PyXLL config
If there are a just some settings you want to change between PyXLL configs you can use environment variables in your pyxll.cfg file. You can also use the .bat file method as shown above to set those environment variables before starting Excel.
For example, if you wanted to set the PYTHONPATH differently you could use an environment variable in your pyxll.cfg file. You can also set a default value so that if that environment variable is set then something will be used instead.
[PYTHON]
pythonpath = %(MY_PYXLL_PYTHONPATH:X:\pyxll\python)s
Here, X:\pyxll\python will be used if MY_PYXLL_PYTHONPATH isn’t set. If you wanted to create a shortcut to start Excel with a specific value you could do so with a batch file, eg:
REM run-excel-dev.bat
REM Starts Excel with the dev pyxll config file
SET MY_PYXLL_PYTHONPATH=C:\Users\jondoe\pyxll-dev\python
START "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
Using external_config to combine configs
You can use the “external_config” setting in your pyxll.cfg file to reference one or more external config files. These files will be merged into the main pyxll.cfg file allowing you to keep settings in separate files.
For example, you might have some base settings in your main pyxll.cfg file such as your LOG settings and the Python executable, and then some other settings in external configs for different situations.
For example, you base pyxll.cfg file could look like this:
[PYXLL]
executable = C:\PythonXX\pythonw.exe
external_config =
X:\pyxll\pyxll-prod.cfg
;X:\pyxll\pyxll-dev.cfg
[LOG]
path = ./logs
file = pyxll-%(date)s.log
verbosity = debug
Notice that the second external config is commented out by adding a “;” to the start of the line.
To switch between configs you would just edit this pyxll.cfg file to reference the other external config by un-commenting the dev config and commenting out the prod one.