Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pythonVSCode, venv and pylint

A newbie question. I am trying to get pythonVSCode working with a venv virtual environment for Python 3.6 on a Mac.

Following the documentation, I activated the virtual environment and launched VSCode from the terminal.

When VSCode suggested installing pylint, I tried using the pythonVSCode's "Install" button that came with the suggestion, but that threw an error in VSCode's terminal:

/usr/bin/python -m pip install pylint
$ /usr/bin/python -m pip install pylint
/usr/bin/python: No module named pip

I then installed pylint via the system (not VSCode's) terminal and within the virtual environment:

(venv) $ pip install pylint

... and re-launched VSCode from the terminal.

VSCode still suggests installing pylint.

I suspect this has something to do with paths. I expected launching VSCode from within the virtual environment will load that environment's interpreter including pylint in VSCode, but it seems not to be the case.

like image 307
Radoslav Avatar asked May 24 '17 20:05

Radoslav


People also ask

How do I enable VS code virtual env?

Open Visual Studio Code in your project's folder. Click Yes ; and your venv is ready to go. Open a new terminal within VSCode Ctrl + Shift + P and you'll see that venv is getting picked up; e.g.: (venv) ... Activate.

What is VENV used for?

venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation.

What VENV means?

A virtual environment is a directory tree which contains Python executable files and other files which indicate that it is a virtual environment. Common installation tools such as setuptools and pip work as expected with virtual environments.

Is Virtualenv same as VENV?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.


2 Answers

You are right, it's about paths. You should have something like this in your settings.json file:

{
  "python.pythonPath": "your_project_path/your_venv/Scripts/python",
  "python.linting.pylintPath": "your_project_path/your_venv/Scripts/pylint"
}
like image 94
Braca Avatar answered Nov 11 '22 09:11

Braca


I had the same problem as of 07/2018.

Solution: activate your virtualenv:

source yourenv/bin/activate

in the terminal with the active virtualenv, do the following:

Install pylint in your virtualenv:

 (yourenv) user@machine/your/env/folder$ pip install pylint

Open VSCODE from the terminal, inside your virtualenv, using the "code" command. Let open only the new VSCode instance.

(yourenv) user@machine/your/env/folder$ code

Have fun coding using pylint.

like image 25
Gabriel Amazonas Mesquita Avatar answered Nov 11 '22 09:11

Gabriel Amazonas Mesquita