add path to PYTHON_PATH before calling script?



  • in my .pro file, i have this:

    QMAKE_POST_LINK += python $${DIR_KJAMS_DEV}xplat/python/post_build_kjams_qt.py $$build_depth $$TARGET
    

    in my .bash_profile i have this:

    PYTHONPATH="${PYTHONPATH}:/Users/davec/Developer/depot/CF/python/"
    export PYTHONPATH
    

    however, in the post_link script called from the .pro file, that python path is NOT included in the sys.path list.
    what's up with that? how do i ensure my path is added?


  • Moderators

    It's likely that qmake does not call bash. Does the shebang character in post_build_kjams_qt.py call sh or bash?

    Also, try putting your path into .bashrc, perhaps it will pick it up from there.

    And last resort: you can specify the path in QMAKE_POST_LINK call, too:

    QMAKE_POST_LINK +=  PYTHONPATH="${PYTHONPATH}:/Users/davec/Developer/depot/CF/python/" python $${DIR_KJAMS_DEV}xplat/python/post_build_kjams_qt.py $$build_depth $$TARGET
    

    Or at least I think it might work ;-)



  • that might work!
    what i ended up doing was making a python file called "include.py", which looks like this:

    import os, sys
    
    def	get_script_path_local(fileStr):
    	scriptPath = fileStr
    	if scriptPath.find(os.sep) == -1:
    		scriptPath = os.getcwd() + os.sep + scriptPath
    	return scriptPath
    
    def	get_script_folder_local():
    	scriptFile = os.path.abspath(__file__)
    	#debug_print("__file__: " + scriptFile)
    	pathStr = get_script_path_local(scriptFile)
    	#debug_print("script file: " + pathStr)
    	pathStr = os.path.dirname(pathStr)
    	#debug_print("script folder: " + pathStr)
    	return os.path.abspath(pathStr) + '/'
    
    sys.path.append(os.path.abspath(				\
    	get_script_folder_local() + "../../../..")	\
    	+ '/CF/python/')
    

    then in the python file(s) that i must run, just do this:

    import include
    

    and BOOM, i can subsequently import from that other python folder


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.