Wednesday 15 January 2014

windows - Add enviroment variable for python with batch -



windows - Add enviroment variable for python with batch -

short question:

how append environment python variable bath script? want equal to: import sys sys.path.append('e:\whatever\locallyscriptfolder') batch file? i'm batch noob.

longer pipeline question:

i need setup maya python script pipeline. scripts in our perforce folder. here .bat file re-create usersetup.py users local drive. usersetup.py executes when maya starts. want start script perforce folder, folder have different path every user (some has on e drive , on). best way able scripts? append environment variable?

example:

c:\users\nameonuser\documents\maya\2014-x64\scripts\ usersetup.py - starts maya.

x:\randompath\scripts\ scriptwanttocallfromusersetup1.py

x:\randompath\scripts\ scriptwanttocallfromusersetup2.py

@ johnzwinck's reply should work running python batch file - set variable lifetime of bat file , started bat file. it's not permanent: when bat file run done settings revert original state. same true if alter sys.path or os.environ within python.

that said, sounds description don't need alter path in batch file, need alter within of usersetup.py. best way add together couple of lines master re-create of usersetup.py in perforce so:

import site site.addsitedir("x:/path/to/perforce/directory") # can add together more folders same way

in version batch file copies usersetup.py user's maya directory , runs maya; usersetup.py sets paths maya needs. improve batch files because (a) batch files lame , (b) if utilize site module can add together lots of directories .pth files.

some more background on topic:

http://tech-artists.org/forum/showthread.php?3987-maya-github-and-script-paths-for-mel-and-python-how-would-you-do-it http://techartsurvival.blogspot.com/2014/06/save-environment.html http://techartsurvival.blogspot.com/2014/07/save-environment-2-i-am-egg-man.html

python windows python-2.7 batch-file maya

No comments:

Post a Comment