Given I have a folder 'foo' with some .dll files which needs to be on PATH at runtime of my python script 'setup.py' Is it possible to put code inside my 'setup.py' script that will put 'foo' folder on PATH before executing the reset of the code which requires the .dll files to run?
So far I have tried this:
import sys
import os
foo = os.path.abspath('dependencies/foo')
if sys.path[1]!= foo:
print('Adding foo to PATH:')
sys.path.insert(1, foo)
print sys.path
else:
print('foo is already on PATH!')
import lib_which_requires_dll_from_foo
...
but it has no effect, although sys.path shows that 'foo' is on PATH - or am I mistaken and it's not that PATH which it should be on.
My setup.py script works if I put 'foo' on PATH with set PATH=C:\my_path_to\foo;%PATH%)
EDIT: Solution that I use now:
import os
FOO = os.path.abspath('path_to_my/FOO')
os.environ['PATH'] = FOO + ";" + os.environ['PATH']
I removed if condition because PATH is altered temporary only - not permanently, thus no need to check first.
NOTE: that will propably work on Windows only
Still appreciate further suggestions - preferably such that will work cross platfrom