Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode remote Python virtual environment

Here is how the thing doesn't work:

The project source code is located on a remote machine. The Python virtual environment is installed in the project's root directory (using venv).

I sshfs the project folder and start local VSCode. It detects the virtual environment, but doesn't see pylint or other packages installed in it.

Python 3.6.7 VS Code - latest version OSs - Debian 9 remote, Linux Mint 19 local Both sshfs connection and venv installation are performed under the same account.

Is there some special way a virtual environment should be set up to be usable remotely?

like image 361
Igor Stolyarevskiy Avatar asked Apr 08 '19 10:04

Igor Stolyarevskiy


People also ask

How does VS Code connect to virtual environment?

From within VS Code, you can create non-global environments, using virtual environments or Anaconda, by opening the Command Palette (Ctrl+Shift+P), start typing the Python: Create Environment command to search, and then select the command. The command presents a list of environment types: Venv or Conda.

How do I enable the Python virtual environment in Visual Studio?

Activate an existing virtual environmentRight-click Python Environments in Solution Explorer and select Add Environment. In the Browse dialog that appears, navigate to and select the folder that contains the virtual environment, and select OK. If Visual Studio detects a requirements.

How do I connect to a remote server using Visual Studio Code?

Connect to a remote host Verify you can connect to the SSH host by running the following command from a terminal / PowerShell window replacing user@hostname as appropriate. In VS Code, select Remote-SSH: Connect to Host... from the Command Palette (F1, Ctrl+Shift+P) and use the same user@hostname as in step 1.

How do I activate venv in VS Code terminal?

Create a Project Environment Then run Terminal: Create New Terminal (Ctrl+Shift+`)) from the Command Palette, that opens a new python terminal and in parallel it activates the virtual environment.


1 Answers

There were problems with sshfs in early VSCode versions, but recent distrib has Remote Development extension that lets you develop your code via ssh.

Since you have activated your virtual environment, just get venv python path with which python command and copy it to the Select Interpreter menu.

like image 200
ilia Avatar answered Nov 15 '22 08:11

ilia