0

I have a python program that uses the marionette driver for firefox and for it to work the directory of the driver must be added to PATH. I've packaged the driver with the program and I want the python script to automatically add the driver directory to the system PATH. Is it possible to do that in python?

HackAfro
  • 660
  • 10
  • 26
  • You can do that using the _winreg module ( or winreg in 3.x). You'll need administrator access to append to the `'Path'` value in the local machine key `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment`. For the per-user value use `HKEY_CURRENT_USER\Environment` instead. You'll need `OpenKey`, `QueryValueEx`, and `SetValueEx`. Make sure to preserve the value's type code. `Path` is usually `REG_EXPAND_SZ`. Make sure you know what you're doing. Messing up the registry is no joking matter. – Eryk Sun Aug 22 '16 at 09:54
  • Thanks but could you break this down for me, I just need the script to add the driver's directory to the env variables when the user starts the program. Thanks – HackAfro Aug 22 '16 at 09:59

1 Answers1

0

Yes, it's possible :)

import sys
sys.path.insert(0, "C:/path/to/your/driver")

This adds to PATH only temporarily. If you want more permanent change, take a look at Permanently add a directory to PYTHONPATH

Community
  • 1
  • 1
grael
  • 659
  • 2
  • 11
  • 26