-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Support using a "clean" environment for the terminal #70248
Comments
Also, if I want to debug vscode platform source code, where should I expect a User Settings or Workspace Settings so I can add some customized stuff in it? |
Current workaround is: "terminal.integrated.env.osx": {
"PATH": ""
} |
The reason this happens is because on mac and Linux there are two ways to launch VS Code:
This sets up the main process environment which is inherited by each VS Code window, its tasks, debug sessions and terminals. Below explain this in detail: Ubuntu launching from terminal
Ubuntu launching from dash
macOS launching from terminal
macOS launching from dock
* needs The underlying problem is:
So as for fixing this issue once and for all this will be a little tricky, unfortunately it's not just as easy as holding onto the original environment and using that for the terminal instead of the one generated by I propose we fetch the environment of the parent process of the It's worth noting that this could break some people's set up and potentially cause some other unexpected issues as before it was an assumption that the terminal process uses the environment of VS Code's window. Maybe this should even be an option in settings, something like |
@praenubilus if you wanted to put together a PR for this I would stick the fetching of the environment code insider electron-browser/terminalService and grab that inside TerminalProcessManager instead of basing it on I think for Windows we always want the old behavior. |
@Tyriar Thanks for the information. Can you answer my another question: if I want to debug with customized settings, (for example "terminal.integrated.env.osx": { "PATH": ""} ) where should I expect a User Settings or Workspace Settings file I can play with? |
@praenubilus I haven't touched any debugging stuff with extensions, this might be relevant? |
Ping @DonJayamanne |
This comment has been minimized.
This comment has been minimized.
Not sure if this helps with your assessment @Tyriar however, my |
@DonJayamanne can you elaborate a little? Why don't you do that now? Do you expect users to setup the venv in a terminal and launch @bandrei the issues typically arise because the scripts are run multiple times, or at least a different number of times to what a standalone terminal does. |
@Tyriar , I get what @bandrei is talking about. In my example at the beginning of the issue, my zshrc or bashrc only have the following command to operate on the $PATH environment variable. export PATH="/home/xxx/anaconda3/bin:$PATH" For this statement, even it has been run multiple times, And the line/place you indicate me,
I have debugged tons of times and quite sure at that line the environment variable value has not been changed. And actually the environment variable is always in correct/expected order even after the
|
@Tyriar apologies for the previous comment, please ignore that. I was replying to another comment if yours that wasn't for me.
Sounds great
I like this approach. |
@praenubilus createProcess creates the process and the shell scripts launch. To gleam some insights into what's happening after, you can pepper some echo calls throughout your |
This could also solve #47816 by reloading the environment, we could also support doing this on Windows by fetching a clean environment block. |
@Tyriar Hi, I noticed something new. See this video: https://ladyrick.github.io/2/index.html. And this problem also exists when no extensions are enabled. |
@ladyrick the difference could depend on whether the external terminal launches as a login shell or not and what
VS Code itself doesn't touch .zshrc, it simply launches zsh with a set of args (which is in an environment that has already had some script sourced as described above). |
@DonJayamanne just exposed One caveat with this is that on macOS I couldn't find a reliable way of pulling the environment, because of this I just use the root environment which always seems to be |
Actually we do need to detect for mac, looking into it but this is ready to test on Linux. |
Couldn't figure it out for mac, doesn't seem possible to get the environment before the launch CLI has run (and tampered with the environment) and /system/launchd's environment always says it's nothing with |
@hologerry try setting |
@Tyriar With the Insiders build and setting |
While |
Actually scratch that, I think that's how it's meant to be and it's the reason why the default shell always has the absolute path ( |
At first I used bash+vscode+conda,this problem appears and I fixed it by setting |
using vscode on mac and set "terminal.integrated.inheritEnv": false,,this works; |
But sometimes I really need to inheritEnv. |
Please could you provide more details on what this |
In remote development, "inheritEnv: false" will make "$PATH" wrong. |
@ladyrick what's your OS/version? |
Can you add the following line at the end of your zshrc or bashrc? echo $PATH with this line, every time integrated terminal will display PATH value if the script being sourced/run, if the terminal has been printed more than once, and it may help you to locate the problem. |
Steps to Reproduce:
echo $PATH
, you may see values similar to following:vscode
instance, in the integrated terminal typeecho $PATH
, now the value may look like following:The CONTENT in two $PATH values are the same, BUT in different order. Problems it may cause: some system configuration depends on the first executable value they can find in the $PATH. Different $PATH value order will have different default program being used. In previous example, the value in step 1 will use python3 and pip3 from anaconda. But in vscode integrated terminal, the $PATH value in step 2 will use the python2 and pip2 in
/usr/local/bin
. Even you activate a virtualenv in integrated terminal, it will still use the wrong virtual env. More details and a proposed workaround can be seen in vscode-python #4434.This has been observed on both MacOS and Ubuntu. I don't have windows computer, but I guess that may also have the same issue. Some related issues can be found in this issue vscode-python #4668.
Now I'm trying to fix this issue with a pull request. But I need some help to indicate me to the correct location in the code base. I also addressed this question on StackOverflow:
Through my own observation, I found the root cause may be: after some steps, somewhere during the create terminal process, the actual environment variable values(specific to PATH) has been reordered/changed. Maybe it is being processed for remove duplication.
I download the vscode codebase(1.33) and follow the debugging until method
createProcess
in source filesrc/vs/workbench/contrib/terminal/electron-browser/terminalProcessManager.ts
. What I have found is: even after the terminal instance has been created, the env.PATH in the main process has NOT been changed. For ptyProcess, the constructor takes options(which contains env) as input, but I cannot find any env related property in created ptyProcess. And after the terminal instance created, the debugging ends, integrated terminal appears in the workbench. I get lost after terminal instance created, can someone from the core team or used to working on integrated terminal module indicate me to the right place in the codebase so I can try to solve the issue? There is not enough documents on internet or comments in the source code can help me find/locate the environments changing during/after the terminal instance creation.The text was updated successfully, but these errors were encountered: