Sublime text3 and virtualenvs

后端 未结 4 1689
被撕碎了的回忆
被撕碎了的回忆 2020-11-27 10:48

I have different virtualenv\'s (made with virtualenwrapper) and I\'d like to be able to specify which virtualenv to use with each proj

4条回答
  •  长情又很酷
    2020-11-27 11:10

    I have an alternative. Just creating a new 'Build System' which runs as if in the virtual environment. Here we call it 'my_python'. The aim is to use this build system to run my script directly without leaving sublime. You need to:

    1. First, preferences->Browse Packages. This will open a folder under which lies setting files. Go inside dir User and create a new file named my_python.sublime-build (composed of the build system name followed by .sublime_build. After doing this, go to Tools -> Build System and you will see a new option my_python.
    2. Add the following JSON settings to that file.

      {
          "shell_cmd": "/Users/Ted/bsd/vector/.v_venv/bin/python -u \"$file\"",
          "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
          "selector": "source.python"
      }
      

      Inside shell_cmd, change /Users/Ted/bsd/vector/.v_venv/bin/python to the path of your python virtual environment.

    3. Then just use the short key to build your script.

    When you want to change your virtual environment, just copy its path to the setting file and all done. Maybe the approach seems containing a lots of work, but it works well and convenient.

提交回复
热议问题