"command not found: pyenv" when opening terminal - pyenv

Some time ago I installed and used pyenv for a purpose I don't need anymore. Then, I uninstalled it. However, whenever I open up my terminal the first thing it prints is:
/Users/jcortizrh/.zshrc:1: command not found: pyenv
So it looks like my terminal is still trying to use pyenv. How can I fix this? I tried editing the .zshrc file but it looks complicated and I'm afraid of modifying it and ruining my terminal somehow.
EDIT: my .zshrc looks like this:
PATH=$(pyenv root)/shims:$PATH
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/jcortizrh/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/jcortizrh/opt/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/jcortizrh/opt/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/jcortizrh/opt/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

Turns out that removing the first line from my .zshrc solves the issue. Thanks for the suggestions!

Related

Opening zsh in vscode gives me error (core parameters have unexpectedly changed)

When opening zsh on the normal terminal I have no errors, while when I open it on vscode I get this:
z4h: core parameters have unexpectedly changed
Expected:
ZDOTDIR=/Users/*******
Found:
ZDOTDIR=/var/folders/0f/**************/T/vscode-zsh
Restore the parameters or restart Zsh with exec zsh.
Restore the parameters or restart Zsh with exec zsh.
I installed zsh with z4h and for a while it worked well. Then it started showing this error randomly.
PS: I tried restarting Zsh with exec zsh.
EDIT:
Tried to create the folder "/var/folders/0f/******/T/vscode-zsh" and paste the files in /Users/ in there as suggested but it still didn't work. Then in that folder, in the .zshrc I tried editing a part of it from this
if [[ "$VSCODE_INJECTION" == "1" ]]; then
if [[ $options[norcs] = off && -f $USER_ZDOTDIR/.zshrc ]]; then
VSCODE_ZDOTDIR=$ZDOTDIR
ZDOTDIR=$USER_ZDOTDIR
. $USER_ZDOTDIR/.zshrc
ZDOTDIR=$VSCODE_ZDOTDIR
fi
if [[ -f $USER_ZDOTDIR/.zsh_history ]]; then
HISTFILE=$USER_ZDOTDIR/.zsh_history
fi
fi
to this:
if [[ "$VSCODE_INJECTION" == "1" ]]; then
if [[ $options[norcs] = off && -f $USER_ZDOTDIR/.zshrc ]]; then
VSCODE_ZDOTDIR=$ZDOTDIR
ZDOTDIR=$USER_ZDOTDIR
. $USER_ZDOTDIR/.zshrc
ZDOTDIR=$USER_ZDOTDIR
fi
if [[ -f $USER_ZDOTDIR/.zsh_history ]]; then
HISTFILE=$USER_ZDOTDIR/.zsh_history
fi
fi
When in vscode the first time I opened a new terminal it worked, but after that the file was again the same as the fist one and creating another terminal would give the same error.
Apparently, this is a bug on the VS code side and a fix has been made available in the insider build and will be available to the public shortly and can be tracked at link.
For now, this can be solved by setting terminal.integrated.shellIntegration.enabled to false in settings.json file or by disabling this option in settings
The message shows vscode executes zsh from /var/folders/0f/**************/T/vscode-zsh.
But no z4h's setting there. A workaround as below:
Backup if the /var/folders/0f/**************/T/vscode-zsh/.zshenv and /var/folders/0f/**************/T/vscode-zsh/.zshrc that existed in the path
Copy /Users/*******/.zshenv and /Users/*******/.zshrc to /var/folders/0f/**************/T/vscode-zsh/
Restart the terminal on vscode
If it still doesn't work. Another way that execute zsh with the same path. You need to reset the environment variable ZIM_HOME to the Expected path.
In vscode CMD+Shift+P
Choose Preferences: Open Settings (JSON)
Add a keyname terminal.integrated.profiles.osx
Add the following value to this key.
{
"zsh": {
"path": "/bin/zsh",
"ZDOTDIR": "/Users/*******"
}
}
It would look like as below finally. [updated] the env var in your case
is ZDOTDIR
{
...
"terminal.integrated.profiles.osx": {
"zsh": {
"path": "/bin/zsh",
"ZDOTDIR": "/Users/*******"
}
}
...
}
Restart the terminal.

How to change the shell used in code runner?

I have nodejs installed and I can access it in my default shell (bash).
The problem is that when I try to run a file it tries to open it with /bin/sh and thus it says /bin/sh: node: command not found
The problem disappears when I set in configuration run in integrated terminal as I have set the default shell for the terminal to bash.
How to change the default shell used in the code runner to bash so that I can run the file?
The only solution I found to your same problem is to make code runner run into the vscode integrated terminal.
My settings.json
"code-runner.executorMapByGlob": {
"*.ts": "ts-node --esm $fullFileName",
},
"code-runner.runInTerminal": true
In my case it stopped happening when opened vs code on bash, in that scenario code runner runs with bash, so probably you should take a look what starts the vs code and how.
If your problem is that sh doesn't have the same path as bash just add to the /etc/profile.d a file with the following code and should work:
if [ -n "${BASH_VERSION}" ]; then
# include ~/.bashrc if it exists
if [ -f "${HOME}/.bashrc" ]; then
. "${HOME}/.bashrc"
fi
fi

VSCODE & GitHub Desktop pre-commit hook: npx: command not found

I am starting a new repo, thinking I should use the most recent Huksy v6 which is installed from LintStaged using their setup guide:
npx mrm lint-staged
// package.json updated with:
"husky": ">=6",
"lint-staged": ">=10",
This adds necessary packages and adds the husky files including the precommit files:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
When i run my commit in the terminal it works fine. However, if I try to run my commit in GitHub Desktop or VSCode (which I know some teammates do), it results in an error for both:
npx: command not found. husky - pre-commit hook exited with code 127 (error)
I have npx installed:
npx -v
// 6.14.10
If I try to install in globall, such as described in other StackOverflow suggestions, it returns a warning about existing location (with & with out sudo):
ERR! EEXIST: file already exists, symlink '../lib/node_modules/npx/index.js' -> '/Users/plucks/.nvm/versions/node/v14.15.4/bin/npx'
npm ERR! File exists: /Users/plucks/.nvm/versions/node/v14.15.4/bin/npx
npm ERR! Remove the existing file and try again, or run npm
npm ERR! with --force to overwrite files recklessly.
Is there anything I can do so the programs like VSCode & GitHub Desktop can run?
I've got the solution from here. Hope you can find it as well!
https://typicode.github.io/husky/#/?id=command-not-found
https://github.com/typicode/husky/issues/912
Here it is, for clarity:
add a file ~/.huskyrc if you don't have one already
make sure it includes the following:
# ~/.huskyrc
# This loads nvm.sh and sets the correct PATH before running hook
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
As per this suggestion, adding the following to your pre-commit file should fix it:
export NVM_DIR="$HOME/.nvm/nvm.sh"
. "$(dirname $NVM_DIR)/nvm.sh"
export NVM_DIR="$HOME/.nvm"
a=$(nvm ls | grep 'node')
b=${a#*(-> }
v=${b%%[)| ]*}
export PATH="$NVM_DIR/versions/node/$v/bin:$PATH"
So the full file would look like this:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
export NVM_DIR="$HOME/.nvm/nvm.sh"
. "$(dirname $NVM_DIR)/nvm.sh"
export NVM_DIR="$HOME/.nvm"
a=$(nvm ls | grep 'node')
b=${a#*(-> }
v=${b%%[)| ]*}
export PATH="$NVM_DIR/versions/node/$v/bin:$PATH"
npm run test
For husky>=6: update your .husky/pre-commit file to contain this:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
npx lint-staged
This will find and expose the current node path and therefore npx path that you are using, which has been configured with Node Version Manager nvm
Before adding any modifications to your project try restarting your IDE as mentioned in this issue
I had to combine the answers of Cathal and Misol.
I did not want to edit the .husky/pre-commit like Cathal for two reasons:
I would need to that for every project I use husky in
It would actually break husky for my fellow developers on Windows
So I added a global ~/.huskyrc file like Misol did with the following contents:
export NVM_DIR="$HOME/.nvm/nvm.sh"
. "$(dirname $NVM_DIR)/nvm.sh"
export NVM_DIR="$HOME/.nvm"
a=$(nvm ls | grep 'node')
b=${a#*(-> }
v=${b%%[)| ]*}
export PATH="$NVM_DIR/versions/node/$v/bin:$PATH"
If you are working on a team with other people who may have installed nvm or node in slightly different fashion than you have, I would not recommend adding any export statements or edits to the $PATH in your .husky/precommit or ~/.huskyrc files.
If you want your VSCode to have proper access to the $PATH you expect from terminal you should always launch VSCode from terminal in the folder you are working from.
For example, in a terminal window:
~/_git/my_project: code .
Will launch VSCode with my_project open in a new window (it should remember your tabs and window state from the last time you worked on your project).
VSCode will now use the $PATH your terminal uses from your ~/.zshrc or ~/.bashrc, etc.
With this setup my .husky/precommit looks like this:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
and my my .lintstagedrc.json looks like this:
{
"*.{js,jsx,ts,tsx}": [
"eslint --fix --debug --max-warnings=-1",
"npm run lint:prettier-fix"
],
"*.{css,less,sass,scss}": ["npm run lint:prettier-fix"],
"*.{g?(raph)ql,json,html,md,y?(a)ml}": ["npm run lint:prettier-fix"]
}
For those using fnm instead of nvm, adding the following to ~/.huskyrc worked for me:
eval "$(fnm env)"
Open VSCode settings and set the Inherit Env setting (Terminal > Integrated: Inherit Env) to false:
"terminal.integrated.inheritEnv": false
This setting enables or disables whether new shells should inherit their environment from VS Code.
I change code as the top answer says. But it doesn't works at first, and then reopen VScode and it works.
In the terminal, I input these commands:
copy this command in terminal and press enter.
vi ~/.huskyrc
copy this command in terminal.
export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
input :wq to quit edit state
reopen VScode.

I'm unable to open a terminal in vsCode. Error message "The terminal process terminated with exit code: 3221225477". What should I do?

I'm not sure why but I can't open a terminal in vscode. I'm running windows 10, and my version of vscode is 1.46. The error code is as follows
The terminal process terminated with exit code: 3221225477
Please have a look at this github issue.
https://github.com/microsoft/vscode/issues/95111
It looks like the antivirus program could trigger this kind of issue.
This is just for corner case.
Having same issue after deleting ~/.bash_profile on Windows 10. Working correctly after restore it.
# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc

Pyenv cannot switch Python versions

I have pyenv installed, however, it does not do its most basic function, namely switch Python versions. The following terminal commands demonstrate this.
the file `main.py` is equivalent to:
import sys
print (sys.version)
Admins-MacBook-Pro-4:kylefoley kylefoley$ pyenv versions
system
* 2.7.14 (set by PYENV_VERSION environment variable)
3.5.3
3.6.1
3.7.3
pypy3.6-7.1.1
Admins-MacBook-Pro-4:kylefoley kylefoley$ pyenv global 3.5.3
Admins-MacBook-Pro-4:kylefoley kylefoley$ pyenv exec python main.py
2.7.14 (default, Oct 17 2019, 00:01:43)
As you can see when I run main.py the version that comes out is 2.7. A lot of people have this problem. One common solution is putting
eval "$(pyenv init -)"
On the bash_profile which I have done and that did not help. Over here
Cannot switch Python with pyenv
it is recommended:
Put the PATH and shell environment vars into your .bash_profile (or whatever file your distro uses).
But what PATH and what shell environment vars is he talking about?
Also my .bashrc file looks like this:
export PATH="/Users/kylefoley/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Any help would be appreciated. One other things, when I run the following commands, I get the following output:
Admins-MacBook-Pro-4:kylefoley kylefoley$ python
Python 3.6.1rc1 (default, Mar 4 2017, 22:58:58)
The problem is that .bashrc is not sourced in a non-login mode.
Init files for Bash:
login mode:
/etc/profile
~/.bash_profile, ~/.bash_login, ~/.profile (only first one that exists)
interactive non-login:
/etc/bash.bashrc (some Linux; not on Mac OS X)
~/.bashrc
non-interactive:
source file in $BASH_ENV
And on macOS, the default Bash shell opened by a terminal app is a interactive login shell, but on Linux, the default shell opened by a terminal app is a interactive non-login shell.
Solution
The weird interactive, non-login loading requirement confuses people in other situations as well. The best solution is to change the loading requirement of ~/.bashrc as interactive only, which is exactly most of the Linux distros are doing.
# write content below into ~/.bash_profile
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
This should be the solution you desire. And I recommend every Bash user setup this in the profile.
References
Unix shell initialization
Everything was done correctly, it's just that I thought the terminal command . ~/.bash_profile updates the bash profile without having to close the terminal or open a new one in order for changes to take effect. It turns out that . ~/.bash_profile only updates some of the bash_profile. After restarting the terminal, everything was working as planned.
Just add to your .bashrc or similar file, the line.
eval "$(pyenv init --path)"
After the "export PATH=$PYENV..." . Don't forget to reset your terminal after try again!
Worked on Fedora & Mint.
Just add this into you .bashrc file:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH"
If your .bashrc is sourced from ~/.bash_profile you are done.
Official docs https://github.com/pyenv/pyenv#advanced-configuration suggests puting into .bashrc:
eval "$(pyenv init -)"
which was not working for me.
1.) configure:
pyenv global [python version]
2.)restart terminal (close all terminal windows)