Every time I try to use conda in my terminal I get this error:
zsh: correct 'conda' to '.conda' [nyae]?
I have added export PATH=$PATH:$HOME/anaconda/bin to my .zshrc and to my .bash_profile files.
Now, if I run source ~/.bash_profile it works, but I have to run this command every time I open a new window. Is there a way to fix this?
I got the same problem, so I copy the coda initialize code from my .bashrc to .zshrc and it worked.
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/path/to/ur/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/path/to/ur/anaconda3/etc/profile.d/conda.sh" ]; then
. "/path/to/ur/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/path/to/ur/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
Related
Cant start my virtual environment of flask through cygwin :
my system :(windows 10)
Method 1:
$ env/Scripts/activate
Method 2:
$ env/Scripts/activate.bat
Method 3:
$ source ./env/Scripts/activate
on my cygwin cli, but it gives the following error all the time :
-bash: $'\r': command not found
-bash: ./env/Scripts/activate: line 4: syntax error near unexpected token `$'{\r''
'bash: ./env/Scripts/activate: line 4: `deactivate () {
Note : The first two methods of activating virtual environment works nicely on VSCode but not on cygwin.
My activate file :
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi
unset VIRTUAL_ENV
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="D:\projects\websites\googleHostFlaskApp\env"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH
# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
PS1="(flask) ${PS1:-}"
export PS1
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r 2> /dev/null
fi
As #Doug suggested , changing CR-LF to LF did worked.
The error was due to difference in line endings.
Unix systems (Linux and Mac) default to the LF (line feed) character for line breaks.
Windows on the other hand is “special” and defaults to CR/LF (carriage return AND line feed).
If you are using vscode like me: Then there is CRLF written at the bottom of vscode
By clicking there you can change activate file from CRLFto LF and it will remove the error you are facing.
I am using a Catalina macOS. I previously was able to work with my python installations with ease on this system. But today after updating other packages, such as wget and julia, I have encountered these errors zsh: command not found: python3.8 on my terminal. Following suggestions on these links I have tried to modify the PATH and zshrc but none of these approaches enables me to solve my problem.
I would be grateful if you can share your suggestions on how to deal with this issue.
Here are some of the outputs of my system.
zshrc:
vi ~/.zshrc
alias python=/usr/local/bin/python3.8
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/shasa/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/shasa/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/shasa/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/shasa/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
python:
which python
python: aliased to /usr/local/bin/python3.8
PATH:
echo $PATH
/Users/shasa/anaconda3/bin:/Users/shasa/anaconda3/condabin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin
Edit 1: In /usr/local/bin/, I can see that python3#, python3.9# and python3.8#* are present. Do you think the extra * near python3.8# can cause this problem? If yes, how can resolve that?
Following the discussion in the comments, I have found the source of the problem. I run brew doctor and indeed found out that the python3.8 symlinks were broken. I have then removed broken symlinks by brew cleanup and reinstalled that again.
I created a new Conda environment on an x86-64 Linux mainframe, using the command
conda create --name myenv --file somefile.txt --python=3.8.
I double checked my Python version in this environment using conda list, which returns
...
python 3.8.3 hcff3b4d_0
...
However, after activating this environment, Python 3 scripts doesn't run, and running which python reveals that the environment defaults to using the default system Python 2 interpreter:
$ which python
/usr/bin/python
My Efforts So Far
First, I added the line export PATH=$PATH:/home/miniconda3/envs/myenv/bin to my ~/.bashrc and ~/.profile files, to no effect. which python still returns /usr/bin/python.
I then checked my alias file to see if python is aliased to Python 2. But there is no entry in the alias file about python.
For your reference
my ~/.bashrc looks like this:
$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
alias julia="/home/julia-1.4.0/bin/julia"
export PATH=$PATH:/home/miniconda3/envs/myenv/bin
$ cat ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
$ cat ~/.profile
export PATH=$PATH:/home/miniconda3/envs/myenv/bin
I think you need to add your env path to the front of the PATH variable so it will find python there first. The OS will look for a file or application in the PATH list, and use the first match that it finds.
Change
export PATH=$PATH:/home/qingyanz/miniconda3/envs/myenv/bin
to this:
export PATH=/home/qingyanz/miniconda3/envs/myenv/bin:$PATH
As an example, here are the settings on my conda environment:
(ds_tensorflow) C:\Users\me>which python
/c/Users/me/miniconda3/envs/ds_tensorflow/python
(ds_tensorflow) C:\Users\me>env | grep PATH
...
PATH=/c/Users/me/miniconda3/envs/ds_tensorflow:/mingw-w64/bin:/usr/bin:/bin:...
I have trouble using anaconda environment in Tmux. I am on OSX.
I first
tmux
Then activate the Conda env:
conda activate myenv
At this point when I conda info shows the correct active environment and correct location. But which python still points to the default /usr/bin/python.
In the .bash_profile I have these lines added by anaconda when installed. So I guess I need to add something to let the terminal find the right python path?
# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/jiajunyang/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/Users/username/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/username/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/Users/username/anaconda3/bin:$PATH"
fi
fi
Thank you for your suggestion.
Below works for me on macOS 10.15 with zsh:
Add below line to your ~/.tmux.conf file
set -g default-command "/bin/zsh"
If you're using a shell other than zsh, I assume changing the path to the shell you're using will also work.
same here, mac 10.14, tmux 3.0a
solution is:
source /Users/mac/opt/anaconda3/etc/profile.d/conda.sh
[[ -z $TMUX ]] ∨ conda deactivate; conda activate base
add 2 lines in your .zshrc. Then
source ~/.zshrc
everything works fine now!!
I had the same issue. Finally I find that tmux will always call the profile for your shell, not just the rc. So if you are using bash like I do, it will call /etc/profile, which will have a call to path_helper.
In order to fix this, change /etc/profile to:
if [[ -z $TMUX ]] && [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
If you are using bash, also change any export PATH=$PATH:/foo in .bashrc to
if [[ -z $TMUX ]]; then
export PATH=$PATH:/foo
fi
then you restart the terminal(for example Iterm). Everything should be good!
I would like to have a different PYTHONPATH from my usual in a particular virtualenv. How do I set this up automatically? I realize that it's possible to hack the bin/activate file, is there a better/more standard way?
This django-users post is probably going to help you a lot. It suggests using virtualenvwrapper to wrap virtualenv, to use the add2virtualenv command. Using this, when the environment is active, you can just call:
add2virtualenv directory1 directory2 ...
to add the directories to your pythonpath for the current environment.
It handles autonomously the PATH changes on environment switches. No black magic required. Et voila!
Here is the hacked version of bin/activate for reference. It sets the PYTHONPATH correctly, but unsetting does not work.
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly
deactivate () {
if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
PATH="$_OLD_VIRTUAL_PATH"
export PATH
unset _OLD_VIRTUAL_PATH
fi
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r
fi
if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
PS1="$_OLD_VIRTUAL_PS1"
export PS1
unset _OLD_VIRTUAL_PS1
fi
if [ -n "$_OLD_PYTHONPATH" ] ; then
PYTHONPATH="$_OLD_PYTHONPATH"
export PYTHONPATH
unset _OLD_PYTHONPATH
fi
unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
# Self destruct!
unset deactivate
fi
}
# unset irrelavent variables
deactivate nondestructive
VIRTUAL_ENV="env_location" # Anonymized
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
export PATH
_OLD_VIRTUAL_PS1="$PS1"
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
export PS1
# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
hash -r
fi
_OLD_PYTHONPATH="$PYTHONPATH"
PYTHONPATH="new_pythonpath" #Anonymized
export PYTHONPATH