title: python module not found when launched from Swift
body: <p>I created a <code>svg2png.command</code> file that simply launches a python file. It calls the python file this way:</p>
  
  <pre><code>shell1 = './scripts/cairosvg.py ../projects/%s/wip/skin/%s/screenLayout/staticScreens/%s -o ../projects/%s/wip/skin/%s/screenLayout/staticScreens/%s' % (projectName, projectName, filename, projectName, projectName, filename[:-4]+".png")
  os.system(shell1)
  </code></pre>
  
  <p>The python file <code>cairosvg.py</code> imports a module (cairo). It looks like:</p>
  
  <pre><code>import cairosvg
  cairosvg.main()
  </code></pre>
  
  <p>When I double-click on the <code>svg2png.command</code> file, everything goes as expected, and a png file is created out of an svg file. Good.</p>
  
  <p>Then I tried to launch the command from an OSX Swift app:</p>
  
  <pre><code>let task = NSTask()
  task.launchPath = "svg2png.command"
  task.arguments = ""
  task.launch()
  task.waitUntilExit()
  </code></pre>
  
  <p>I have done this several times with simpler python scripts and they all worked as expected. However in that case, I get the error:</p>
  
  <pre><code>"Traceback (most recent call last):", "  File \"scripts/svg2png.py\", line 4, in &lt;module&gt;", "    import cairo", "ImportError: No module named cairo", "s"
  </code></pre>
  
  <p>How come this cairo module can be found when double-clicking on the .command, but not when launched from Swift? Also, a way to fix this would be great.</p>
  
  <p>The environment variables, when working:</p>
  
  <pre><code>{'LC_CTYPE': 'UTF-8', 'TERM_PROGRAM_VERSION': '343.7', 'LOGNAME': 'username', 'USER': 'username', 'HOME': '/Users/username', 'PATH': '/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/minicom/2.2/bin:/opt/X11/bin:/usr/local/git/bin:/usr/local/bin/jamf', 'DISPLAY': '/private/tmp/com.apple.launchd.9lqHCFuqkq/org.macosforge.xquartz:0', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'en_US.UTF-8', 'TERM': 'xterm-256color', 'Apple_PubSub_Socket_Render': '/private/tmp/com.apple.launchd.3vWnYf4EMF/Render', 'SHLVL': '2', 'XPC_FLAGS': '0x0', '_': '/usr/local/bin/python', 'TERM_SESSION_ID': '24056B9D-EAD4-4A77-A38A-A98909725024', 'XPC_SERVICE_NAME': '0', 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.67dyQjSHcg/Listeners', 'SHELL': '/bin/bash', 'LC_ALL': 'en_US.UTF-8', 'TMPDIR': '/var/folders/4c/0qxnphys699fxty03712k30h0000gn/T/', 'OLDPWD': '/Users/username', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', 'PWD': '/Users/username/Documents/GIT/studio_design_delivery/UnifyStudioProcess/tools'}
  </code></pre>
  
  <p>When not working:</p>
  
  <pre><code>{'_': '/usr/bin/python', 'LOGNAME': 'username', 'USER': 'username', 'XPC_SERVICE_NAME': '0', 'HOME': '/Users/username', 'PATH': '/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin', 'DISPLAY': '/private/tmp/com.apple.launchd.9lqHCFuqkq/org.macosforge.xquartz:0', 'LANG': 'en_US.UTF-8', 'SHELL': '/bin/bash', 'SHLVL': '1', 'XPC_FLAGS': '0x0', '__XCODE_BUILT_PRODUCTS_DIR_PATHS': '/Users/username/Library/Developer/Xcode/DerivedData/USPReleaser-dhgtnfxnfhrtuzcwyapzztrkzifr/Build/Products/Debug', 'MallocNanoZone': '1', 'SSH_AUTH_SOCK': '/private/tmp/com.apple.launchd.67dyQjSHcg/Listeners', 'DYLD_FRAMEWORK_PATH': '/Users/username/Library/Developer/Xcode/DerivedData/USPReleaser-dhgtnfxnfhrtuzcwyapzztrkzifr/Build/Products/Debug', 'NSUnbufferedIO': 'YES', 'DYLD_LIBRARY_PATH': '/Users/username/Library/Developer/Xcode/DerivedData/USPReleaser-dhgtnfxnfhrtuzcwyapzztrkzifr/Build/Products/Debug:/usr/lib/system/introspection', 'Apple_PubSub_Socket_Render': '/private/tmp/com.apple.launchd.3vWnYf4EMF/Render', 'LC_ALL': 'en_US.UTF-8', 'TMPDIR': '/var/folders/4c/0qxnphys699fxty03712k30h0000gn/T/', 'OLDPWD': '/Users/username/Library/Developer/Xcode/DerivedData/USPReleaser-dhgtnfxnfhrtuzcwyapzztrkzifr/Build/Products/Debug', '__XPC_DYLD_FRAMEWORK_PATH': '/Users/username/Library/Developer/Xcode/DerivedData/USPReleaser-dhgtnfxnfhrtuzcwyapzztrkzifr/Build/Products/Debug', '__XPC_DYLD_LIBRARY_PATH': '/Users/username/Library/Developer/Xcode/DerivedData/USPReleaser-dhgtnfxnfhrtuzcwyapzztrkzifr/Build/Products/Debug', '__CF_USER_TEXT_ENCODING': '0x1F5:0x0:0x0', 'PWD': '/Users/username/Documents/GIT/studio_design_delivery/UnifyStudioProcess/tools'}
  </code></pre>
  
  <p>They're definitely different, any idea?</p>