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

Incorrect PATH in integrated terminal #69954

Closed
hameerabbasi opened this issue Mar 7, 2019 · 20 comments
Closed

Incorrect PATH in integrated terminal #69954

hameerabbasi opened this issue Mar 7, 2019 · 20 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) info-needed Issue requires more information from poster terminal Integrated terminal issues

Comments

@hameerabbasi
Copy link

  • VSCode Version: 1.31.1
  • OS Version: macOS 10.14.4 beta 4

Steps to Reproduce:

  1. Install ZSH and Anaconda

Set .zshrc to (substitute your Anaconda path):

. $HOME/anaconda/etc/profile.d/conda.sh
export PATH="$PATH:$HOME/anaconda/bin"
  1. Launch zsh in either iTerm or the macOS terminal and do echo $PATH.

You get (example)

/Users/hameerabbasi/anaconda/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS:/Users/hameerabbasi/anaconda/bin
  1. Launch zsh in the VSCode integrated terminal and do the same. Output is:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS:/usr/local/sbin:/Users/hameerabbasi/anaconda/bin:/Users/hameerabbasi/anaconda/condabin:/Users/hameerabbasi/anaconda/bin

The upshot of this is that we cannot use the conda-installed Python within zsh in the integrated terminal. I've reported it here because the Python extension is disabled, just the integrated terminal.

Does this issue occur when all extensions are disabled?: Yes/No

@vscodebot vscodebot bot added the terminal Integrated terminal issues label Mar 7, 2019
@hameerabbasi
Copy link
Author

It seems it happens in bash as well, so not specific to zsh.

@jarlefosen
Copy link

It sounds like the VSCode instance is running bash instead of zsh, causing it to not source the .zshrc file as you expect.

Can you try and change your MacOS default shell to be zsh by following this guide?
http://osxdaily.com/2012/03/21/change-shell-mac-os-x/

Please note that the path to the zsh binary may be different on your machine based on how you installed it. For me I set it to be /usr/local/bin/zsh

An alternative solution is to create a common shell startup script that you can source from both .zshrc and .bash_profile so you get the same $PATH in both zsh and bash.

@hameerabbasi
Copy link
Author

That fixes it. That's kind of weird because I used chsh -s /usr/local/bin/zsh to change it... And VSCode would launch it, but the PATH was still weird.

I had the lines in both .bashrc and .zshrc and tested with both zsh and bash, and the issue was the same. But the terminal prefs section fixed it.

@rikvanderkemp
Copy link

This happens on Linux as well. Whenever I open a project and go straight to the terminal this happens:

deepinscreenshot_select-area_20190307174627

Running fish, version 3.0.1

My default shell is set to fish

@hameerabbasi
Copy link
Author

Okay, it happens again after a reboot on both shells.

@Tyriar
Copy link
Member

Tyriar commented Mar 8, 2019

When VS Code is launched from finder on mac VS Code runs $SHELL -ilc in order to get a reasonable development environment:

https://github.com/Microsoft/vscode/blob/ef32b4594599366dcf33afbf495c9609b923b983/src/vs/code/node/shellEnv.ts#L24-L28

When you launch the terminal that will again run your terminal start up scripts (which ones depend on the value in terminal.integrated.shellArgs.osx). This can mangle your PATH if your scripts aren't idempotent. I think the problems you're experiencing are by design currently as there isn't really an elegant solution to the problem.

@Tyriar Tyriar added the info-needed Issue requires more information from poster label Mar 8, 2019
@hameerabbasi
Copy link
Author

The issue here is that it completely mangles the ability of conda to work properly in Python, so conda activate <env> doesn't work. It kills the development workflow to have a different shell, especially since I use live-share to code with a co-worker.

I'm not sure what you mean by "idempotent".

@rikvanderkemp
Copy link

@Tyriar this doesn't only happen on MacOs. It happens on Linux as well. I wouldn't mind providing more information if I know what you need. This behavior only started recently.

@hameerabbasi
Copy link
Author

Neither would I. I'd love to help debug.

@hameerabbasi
Copy link
Author

hameerabbasi commented Mar 9, 2019

This behavior only started recently.

Maybe this is unrelated to my switch to ZSH, because as I stated, it happens on bash as well, with the old configuration. It probably just was a coincidence that it happened at the same time.

It kills the development workflow to have a different shell

When I say "shell" I mean a different terminal emulator.

@rikvanderkemp
Copy link

@hameerabbasi Just noticed that when I set the integrated terminal to bash it seems to work. Would you mind trying this? Maybe we can narrow down what is going on:

"terminal.integrated.shell.linux": "/usr/bin/bash",

@hameerabbasi
Copy link
Author

hameerabbasi commented Mar 9, 2019

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Wireshark.app/Contents/MacOS:/Users/hameerabbasi/anaconda/condabin:/Users/hameerabbasi/bin:/Users/hameerabbasi/anaconda/bin:/Users/hameerabbasi/.local/bin:/Users/hameerabbasi/anaconda/bin

The path /Users/hameerabbasi/anaconda/condabin should be at the start.

@rikvanderkemp
Copy link

@Tyriar I seem to may have found the issue for Fish Shell (3.0.1). Whatever I set the cwd to, it will always go to my home directory:

Using:

"terminal.integrated.cwd" : "some_random_path"

If I switch to bash, the shell navigates properly on new terminals.

@hameerabbasi
Copy link
Author

This happens for me in bash as well... cwd set to .,

$ echo $PWD
/Users/hameerabbasi

@rikvanderkemp
Copy link

rikvanderkemp commented Mar 9, 2019

That's really odd @hameerabbasi

I have confirmed that, for me, downgrading to Fish version 3.0.0 resolves my issues. So this is most likely a bug in Fish 3.0.1-1.

However, I find it odd that your bash does the same thing. Maybe this is due to having a different bash version? I'm running 5.0.0(1)-release. None the less, it's an odd behavior

Maybe try again, but this time using /bin/sh ?

@hameerabbasi
Copy link
Author

Hmm, I'm not sure... The pwd issues are with zsh again, but the $PATH issues happen everywhere.

@hameerabbasi
Copy link
Author

hameerabbasi commented Mar 14, 2019

Something else is going on here that I don't understand, maybe some cache was poisoned or something. What I did was:

  1. Uninstalled and reinstalled Anaconda (rm -rf ~/anaconda, remove conda init section from .bashrc and .zshrc, reinstall)
  2. Changed default shell to bash with (chsh -s /bin/bash and again after sudo -i). Also changed path in terminal.
  3. Uninstalled and reinstalled VSCode with a fresh download (deleted from Applications + https://stackoverflow.com/questions/42603103/how-to-completely-uninstall-vscode-on-mac).
  4. Made sure VSCode preferences were empty.
  5. Rebooted
  6. Opened up integrated terminal + which python. Result was /usr/bin/python. Shell is bash.
  7. In iTerm or Terminal it is /Users/hameerabbasi/anaconda/bin/python.

@hameerabbasi
Copy link
Author

Reported at conda/conda#8414.

@hameerabbasi
Copy link
Author

hameerabbasi commented Mar 14, 2019

Ideally, it'd be nice to only spawn the shell once, not twice. Is this possible?

For the meanwhile, I solved this by doing adding this to my prefs:

"terminal.integrated.shellArgs.osx": ["-c", "/bin/zsh"]

@Tyriar
Copy link
Member

Tyriar commented Mar 23, 2019

/duplicate #70248

@Tyriar Tyriar closed this as completed Mar 23, 2019
@vscodebot vscodebot bot added the *duplicate Issue identified as a duplicate of another issue(s) label Mar 23, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) info-needed Issue requires more information from poster terminal Integrated terminal issues
Projects
None yet
Development

No branches or pull requests

4 participants