M
M
Maxim Zubenko2020-06-29 11:06:40
Python
Maxim Zubenko, 2020-06-29 11:06:40

How to do any code completion with virtual environment in Sublime Text 3?

Before starting, I want to make it clear that I use PyCharm, but I have a very old 10-year-old laptop that does not pull it. That's why I want to make a micro python IDE based on Sublime Text 3 (because it's fast and doesn't mess with its installed modules in the project's virtual environment). Further to the point: I

install Sublime Text 3.
I put Package Control and install the necessary modules.
I'm used to the fact that I have a virtual environment in the v folder (and next to it are the project files themselves). My SublimeREPL installation is set up to run using just my virtual environment. And he works great.
I put Anaconda (to have auto-formatting of the code (when saving the file), linter, and I would like code completion (well, the one that appears with hints through a dot))
And auto-completion with modules from the standard library works great. But with those that I installed in my virtual environment, alas, no. Here's how to fix it?
Tried to install Jedi. Everything is exactly the same.
Where in the Anaconda package settings should I tell it to use my virtual environment?
For example, in the same SublimeREPL, I just did this in Key Binding and it works:

{ 
        "keys": ["ctrl+b"], 
        "command": "repl_open", 
        "args": {
                "cmd": ["$folder/v/Scripts/python.exe", "-i", "-u", "$file_basename"], 
                "cwd": "$file_path", 
                "encoding": "utf8", 
                "extend_env": {"PYTHONIOENCODING": "utf-8"},
                "view_id": "*REPL* [python]",
                "external_id": "python", 
                "syntax": "Packages/Python/Python.tmLanguage", 
                "type": "subprocess"
        }
    },


And where in the anaconda to register so that he knows about the modules in the virtual environment, I did not find it.

Jedi has the following settings (where I tried different options, but it still does not see the modules from my virtual environment):
{
  // You can set a path to your python virtualenv,
    // for example `/home/user/.virtualenvs/myenv)`.
    // Note: Interpreter path would be found automaticaly

    // "python_virtualenv": "./v",
    // "python_virtualenv": "./v/",
    // "python_virtualenv": "v/",
    // "python_virtualenv": "/v",
    "python_virtualenv": "e:/py/testbot/v",


    // You can set a path to your python interpreter,
    // for example `/home/user/.virtualenvs/myenv/bin/python)`.

    // "python_interpreter": "./v/Scripts/python",
    // "python_interpreter": "v/Scripts/python",
    // "python_interpreter": "./v/Scripts/python.exe",
    "python_interpreter": "e:/py/testbot/v/Scripts/python",

    // "sublime_completions_visibility": "all",
}


How to configure code completion from Anaconda or Jedi (or maybe some other) to understand that you need to work with a virtual environment from the v / folder (fuck with it, I will rename it to a different folder name, just to work)?

ps maybe you need to create a thread file (well, like .gitignore) in which the rules for the entire sublima project will be written, and so that Anaconda or Jedi obeys these rules? If you know, tell me.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas V, 2020-06-29
@JawsIk

Xs who does what, and I added a couple of lines to Sublime_text\Data\Packages\Jedi - Python autocompletion\sublime_jedi\utils.py:
5efa61cb80ef4840755280.png
By the way, you need to restart after changes
And in the project file I write something like this:

{
  "virtualenv": "$folder/.Venv",
  "settings": 
  {
    "python_interpreter": "$folder/.Venv/Scripts/python.exe"
  },
  "folders":
  [
    {
      "path": "Path/To/My/Project"
    }
  ]
}

Accordingly, I have a folder with a virtual environment called .Venv and is located in the root of the project
And everything works :)
PySy: But in theory, you can stupidly write the path in the project file - like "virtualenv": "path/to/venv" , I just have sublime on a flash drive and you have to use relative paths everywhere

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question