Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pythonPath not respected in remote container #7813

Closed
syagev opened this issue Oct 8, 2019 · 22 comments
Closed

pythonPath not respected in remote container #7813

syagev opened this issue Oct 8, 2019 · 22 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue

Comments

@syagev
Copy link

syagev commented Oct 8, 2019

Mirroring microsoft/vscode-remote-release#1579

Environment data

  • VSCode Version: 1.38.1
  • Extension version (available under the Extensions sidebar): 2019.9.34911
  • Local OS Version: Window 10 1903
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.5.4
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv
  • Remote OS Version: Ubuntu 18.04
  • Remote Extension/Connection Type: Docker

Expected behaviour

In "Remote Container" mode, I expect VSCode to respect the pythonPath setting and use the interpreter from the virtualenv.

Actual behaviour

The path is not respected, and only the system-installed interpreters of the docker container are shown in the VSCode interpreter selection drop-down.

Steps to reproduce:

  1. Create a project with pipenv
  2. In the folder settings.json point pythonPath to the python interpreter in the virtualenv (i.e. something like C:\Users\username\.virtualenvs\SomeProject-09hncfd\bin\python.exe
  3. Create a custom Dockerfile based of Ubuntu 18.04 and build image (e.g. my-image:latest), in this image create a virtualenv based on the project's Pipfile using pipenv. Assume the virtualenv (in the image) is created at /root/.local/share/virtualenvs/SomeProject-1298hf
  4. Setup remote like so:
"image": "my-image:latest",
"settings": {
  "terminal.integrated.shell.linux": "/bin/bash",
  "python.pythonPath": "/root/.local/share/virtualenvs/SomeProject-1298hf/bin/python",
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": true,
  "python.linting.pylintPath": "/root/.local/share/virtualenvs/SomeProject-1298hf/bin/pylint"
},
  1. Open VSCode remote, run the project.
  2. An error message appears: "You need to select a Python interpreter ..."

image

@syagev syagev added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Oct 8, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Oct 8, 2019
@jahan01
Copy link

jahan01 commented Oct 9, 2019

yes, same issue here. workplace settings takes precedence over devcontainer's settings.json

@brettcannon
Copy link
Member

Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will be triaging it as soon as we can.

@karthiknadig karthiknadig added area-environments Features relating to handling interpreter environments needs PR and removed triage labels Oct 17, 2019
@chrmarti
Copy link

@sandy081 The pythonPath setting's scope is currently resource (presumably this can change per workspace folder). Should this become machine-overridable since it is a machine-specific path that needs to be overridable per workspace folder?

@sandy081
Copy link
Member

sandy081 commented Nov 5, 2019

Should this become machine-overridable since it is a machine-specific path that needs to be overridable per workspace folder?

resource scope allow setting to be overridable at all levels (machine, folder).

@nirfse
Copy link

nirfse commented Feb 25, 2020

Is there at least temporary workaround for this issue?

@jahan01
Copy link

jahan01 commented May 12, 2020

looking for a workaround here. any suggestion please ? currently every time i switch between local and container development, interpreter path gets messed up.

@karthiknadig
Copy link
Member

@jahan01 If you use the latest version of the extension (2020.5.78807) you should be able to enter the path directly there. Try this.
image

@jahan01
Copy link

jahan01 commented May 13, 2020

@karthiknadig i think we are talking different things here, i don't have issues with list of interpreters vscode detects. When switching from local to remote container development python.pythonPath in devcontanier.json value is overridden by the one in workspace settings which has my local interpreter path. So every time I switch between local and container development I have to reset python.pythonPath in workspace settings.json according to the environment.

However enabling "python.experiments.optInto": ["DeprecatePythonPath - experiment"] this seems to fix the issue, but introduced a new issue where I cannot use ${config:python.pythonPath} in my tasks.json to find the virtualenv interpreter for the project. It defaults to global python installation now, since the settings is removed from workspace.

@karthiknadig
Copy link
Member

@jahan01 Try ${config:python.interpreterPath} that is the replacement for ${config:python.pythonPath}.

@jahan01
Copy link

jahan01 commented May 13, 2020

@karthiknadig I had already tried that, it says

'${config:python.interpreterPath}' can not be resolved because setting 'python.interpreterPath' not found.

@karthiknadig
Copy link
Member

@karrtikr Can you help @jahan01 on this?

@karthiknadig
Copy link
Member

@jahan01 Filed #11789 to track the issue with interpreterPath

@karrtikr
Copy link

karrtikr commented May 13, 2020

@jahan01 @karthiknadig We can only use ${config:python.interpreterPath} in launch.json. Can you paste that part of tasks.json where you use ${config:python.pythonPath}? What happens if you don't specify the python path at all.

@karthiknadig
Copy link
Member

karthiknadig commented May 13, 2020

For others running into this issue:
python.pythonPath setting will be deprecated. The python.pythonPath setting was stored in settings.json. This means that when you switched to a container/WSL, it would continue to use the path that was set in the settings.json. The new setting is stored at the machine level, this means you will have to select the interpreter once for your workspace in the host machine and once in the container or WSL and extension will remember this setting for that workspace on that machine/container/server.

This is still an experimental feature so you may run into bugs. You can opt into this by adding "python.experiments.optInto": ["DeprecatePythonPath - experiment"] to your user settings. Right now there is one issue with expanding ${config:python.interpreterPath} when used in task.json/settings.json.

@jahan01
Copy link

jahan01 commented May 14, 2020

@karthiknadig is the below setting still valid in devcontainer.json. i think you may still need some setting to mention default python location for containers.

// Set *default* container specific settings.json values on container create.
"settings": {
	"terminal.integrated.shell.linux": "/bin/zsh",
	"python.pythonPath": "/usr/local/bin/python",

https://github.com/microsoft/vscode-remote-try-python/blob/29a93447a860ca92d30d9bdfb4960db60668cd36/.devcontainer/devcontainer.json#L11-L14

@jasonwilliams
Copy link

@karthiknadig I seem to have the container overwriting the python.pythonPath setting in my settings.json file. This is annoying because i have it set properly in devcontainer/settings but it seems to prefer overriting my main settings.json file.

Do you know what I should do about that? You mentioned python.pythonPath is deprecated, what replaces it?

@karrtikr
Copy link

karrtikr commented Jan 11, 2022

You can do it using python.defaultInterpreterPath setting. It's a little different from python.pythonPath at workspace level. Check the wiki https://github.com/microsoft/vscode-python/wiki/AB-Experiments#tldr to understand how it works.

But if you have manually selected an interpreter in the dev container, that setting will not have any effect. You can try using Python: Clear Internal extension cache in that case.

@jasonwilliams
Copy link

jasonwilliams commented Jan 20, 2022

Thanks, I have changed to using python.defaultInterpreterPath and it's the same problem. Once inside the container it is not respecting .devcontainer/settings/python.defaultInterpreterPath and is instead trying to use the one proposed at the top level .vscode/settings/python.defaultInterpreterPath.

It looks like this extension is not properly overriding settings from .devcontainer over .vscode.

I've done a screenshot to illustrate my problem
Screenshot 2022-01-20 at 16 48 07

If defaultInterperterPath is not the correct setting for this could someone advise what I should be using instead? I want a different path when inside the container to when im outside

@karrtikr
Copy link

Ah I see, we'll try to have a look as soon as possible, expect by end of next week.

@karrtikr karrtikr added the triage-needed Needs assignment to the proper sub-team label Jan 21, 2022
@karthiknadig karthiknadig removed the triage-needed Needs assignment to the proper sub-team label Jan 24, 2022
@karrtikr karrtikr self-assigned this Jan 25, 2022
@karrtikr karrtikr added the investigating We are looking into the cause of the issue label Jan 25, 2022
@karrtikr
Copy link

It looks like this extension is not properly overriding settings from .devcontainer over .vscode.

Hi so I tried it out, but the behavior does not seem to be just specific to python.defaultInterpreterPath or python extension related settings. It seems Workspace settings are always prioritized over Remote devcontainer settings for all settings (Personally I tried with "terminal.integrated.defaultProfile.linux" setting)

Can you name any settings for which devcontainer are prioritized over workspace? (.vscode/settings.json)

@karrtikr karrtikr added info-needed Issue requires more information from poster and removed needs PR labels Jan 26, 2022
@jasonwilliams
Copy link

jasonwilliams commented Jan 26, 2022

I see what you're saying, so maybe it's better to put the python.defaultInterpreterPath in my user settings instead of workspace settings and the problem may just solve itself. I assumed the precedence was User Settings -> Workspace Settings - > Dev Container Settings with dev container settings overriding everything before it, but now I see that's not the case. Sorry that wasn't obvious to me, I'm not sure why I thought that was the order.

Do you know why the extension is writing python.defaultPath into my .vscode/settings.json file? I thought this config was deprecated? It only does it if it can't find the interpreter path and I need to choose one in the drop down.

@karrtikr
Copy link

so maybe it's better to put the python.defaultInterpreterPath in my user settings instead of workspace settings and the problem may just solve itself.

Yes.

Do you know why the extension is writing python.defaultPath into my .vscode/settings.json file? I thought this config was deprecated? It only does it if it can't find the interpreter path and I need to choose one in the drop down.

If no workspace is opened, python.defaultInterpreterPath setting works just like python.pythonPath did, so it'll write the selected interpreter path into it.

I'm closing this issue for the above reasons.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

10 participants