Trouble setting Python version in Sublime Text2

前端 未结 1 1417
面向向阳花
面向向阳花 2020-12-05 16:46

I\'m having trouble setting the build environment in Sublime Text2. I\'m using Macports for Python and package installation.

My python.sublime-build file looks like

相关标签:
1条回答
  • 2020-12-05 17:36

    Your Sublime Text 2 environment is different from your shell environment; the $PATH variable is probably not pointing to the same directories and the wrong executable is selected.

    You have several options to work around that:

    1. Set a "path" option that includes /opt/local/bin need to use an absolute path for your python executable, as Sublime Text 2 doesn't share the same environment PATH variable your shell uses. Inspect echo $PATH and use that as a template:

      {
          "cmd": ["python", "-u", "$file"],
          "path": "/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/Users/yourloginname/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin",
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python"
      }
      

      That'll use /bin/bash to run the command, which I think would have the same $PATH setting as your terminal.

    2. Run the command through the shell instead by setting the "shell" option:

      {
          "cmd": ["python", "-u", "$file"],
          "shell": true,
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python"
      }
      
    3. Use the full path for the python command:

      {
          "cmd": ["/opt/local/bin/python", "-u", "$file"],
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python"
      }
      
    0 讨论(0)
提交回复
热议问题