Using virtualenv with Sublime Text 3 and SublimeREPL

I am trying to configure ST3 to work with Python virtualenv running on Windows 8.1. I usually use SublimeREPL with my global Python installation to run files. Now that I am using venvs, I am having problems starting up. Here is what I tried:

I have a parent directory with virtualenvs folder, and then one scripts for my .py files that I communicate with. Usually I just go to \virtualenvs\venv\scripts\activate and do my work with the python interpreter, but I would like you to be able to create files without having to go through the command line using ST3 and SublimeREPL.

I created a build system that looks like this:

 { "shell_cmd": ["\code\virtualenvs\venv\scripts\python.exe", "-u", "$file"], "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)", "selector": "source.python", } 

But I'm not even sure that this is what I need to do to use SublimeREPL, since I never had to worry about Tools > Build Systems before, just Tools > SublimeREPL > Python > Python - RUN current file .

How can I change the build system or configure SublimeREPL RUN? For a test case, I have a requests module installed in venv, but not in my global python installation. Importing from the command line is fine, but the .py file with import requests returns ImportError.

+8
python sublimetext sublimetext3 virtualenv sublimerepl
source share
2 answers

The ST3 build system and SublimeREPL provide two different functionalities. The build system is what you usually use when working with a compiled language, for example C. This allows you to determine how you want to create your program from source files.

You can also use the build system with Python. In this case, it will compile for you the file that is currently open.

On the other hand, SublimeREPL allows you to start a terminal session inside Sublime, and also (among other things) evaluate files in the context of this session. I would suggest you take a look at the documentation for SublimeREPL and Python :

Both Python and Execnet integration foundations support virtualenv. Various ways of working with Python are supported, including PDB and IPython.

For virtual created environments that SublimeREPL can detect, they must be created or symbolically linked by one of the following:

  • ~ / .virtualenvs by default for virtualenvwrapper
  • ~ / .venvs by default for venv

Alternatively, you can add additional paths to "python_virtualenv_paths" in the SublimeREPL configuration file.

+4
source share
  • install the virtualenv package into a sublime editor
  • Then go on to create the system and install it as "python + virtualenv" enter image description here 3. Now go to the elevated project file and add the path to virtualenv "virtualenv":"D:/my_projects/scrapping_env", enter image description here
  • To add a test build system, add the following in the settings .sublime-project "build_systems": [ { "name": "Test", "shell_cmd": "D:/my_projects/scrapping_env/Scripts/python py.test" }, ],

  • Select Test build sytem from the tools as shown enter image description here

+5
source share

All Articles