Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code portable on Linux is still using for packages local user folder instead of the enviroment folder, and because of that imports fail

I created a virtual environment with venv.

venv --python=/workspace/dev/python3.9 /var_path/var_virtual_env

In Visual Studio Code(portable version -Linux) I have set:

"python.venvPath": "/var_path/var_virtual_env",
"python.formatting.provider": "black"

The environment is seen in VSCode:

enter image description here

enter image description here

Code with python built-ins works without a problem.

From VS Code terminal with virtual environment activated using pip I installed different packages and I expected the packages to be imported in the virtual environment, but instead seems that they are installed in the/home/user_name/local/lib/python3.6.

Also I noticed that the configurations likepylint.d etc are at same location in "local". The pylint was set thru VSCode.

To fix it I installed the packages in the environment outside VSCode, but the editor doesn't sees them. Example httpx:

enter code here

But they are in the environment, pip freeze output:

enter image description here

How can I fix this ?

like image 373
user3541631 Avatar asked Jun 13 '21 08:06

user3541631


People also ask

Is there a portable version of VS Code?

Visual Studio Code™ portable app made with Portapps. A source code editor developed by Microsoft for Windows, Linux and macOS.

How do you change environment in VS Code?

Select and activate an environment# To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).

Does Visual Studio Code support portable mode?

Visual Studio Code supports Portable mode. This mode enables all data created and maintained by VS Code to live near itself, so it can be moved around across environments.

Can I use VS Code on Linux?

Another option for Linux development with VS Code is to use a Windows machine with the Windows Subsystem for Linux (WSL). Windows Subsystem for Linux. With WSL, you can install and run Linux distributions on Windows. This enables you to develop and test your source code on Linux while still working locally on a Windows machine.

How to update portable VS Code on Windows and Linux?

Update Portable VS Code # On Windows and Linux, you can update VS Code by copying the data folder over to a more recent version of VS Code. On macOS, automatic updates should work as always, no extra work needed. Migrate to Portable mode #

What is the use of VS Code installation folder location?

This mode enables all data created and maintained by VS Code to live near itself, so it can be moved around across environments. This mode also provides a way to set the installation folder location for VS Code extensions, useful for corporate environments that prevent extensions from being installed in the Windows AppData folder.


2 Answers

In a terminal where the scarlette environment is activated, copy the output of which python.

Set in settings.json the following line:

{
    "python.pythonPath": "paste_the_output_here"
    ....
}

I don't know if it will work in your case but that did the trick for me several times.

like image 154
RobBlanchard Avatar answered Oct 21 '22 08:10

RobBlanchard


Click on:

enter image description here

And then choose python from venv.

Let know what happened.

like image 1
Karol Zlot Avatar answered Oct 21 '22 08:10

Karol Zlot