Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. add path to PYTHON_PATH before calling script?
Forum Updated to NodeBB v4.3 + New Features

add path to PYTHON_PATH before calling script?

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
3 Posts 2 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davecotter
    wrote on 10 Aug 2017, 18:24 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on 11 Aug 2017, 15:07 last edited by
      #3

      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

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 11 Aug 2017, 07:34 last edited by
        #2

        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 ;-)

        (Z(:^

        1 Reply Last reply
        0
        • D Offline
          D Offline
          davecotter
          wrote on 11 Aug 2017, 15:07 last edited by
          #3

          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

          1 Reply Last reply
          1

          1/3

          10 Aug 2017, 18:24

          • Login

          • Login or register to search.
          1 out of 3
          • First post
            1/3
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved