conda not found after update to big sur 11.3 - python-3.x

I recently updated my 2019 macbook pro to macos big sur version 11.3. Before the update I had anaconda installed, had created virtual python 3 environments, installed jupyter notebook, and had added conda to my python path variable. I was able to activate conda env and launch jupyter notebook servers. I updated to big sur version 11.3 and now when I try to do anything with conda all I get is:
-bash: conda: command not found
I saw some posts that the issue may be caused by zsh being the new default. So I tried the commands below. Also tried switching my default terminal to zsh, but nothing has worked. So I switched back to bash.
Does anyone know what the issue might be and can you suggest how to fix it?
tried:
/System/Volumes/Data/anaconda3/bin/conda init zsh
tried:
source /System/Volumes/Data/anaconda3/bin/activate
output:
-bash: /System/Volumes/Data/anaconda3/bin/conda: /anaconda3/bin/python: bad interpreter: No such file or directory
code:
vim ~/.bash_profile
output:
# added by Anaconda3 2019.03 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/anaconda3/etc/profile.d/conda.sh" ]; then
. "/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
~
~
~
~
~
update:
I tried the first suggestion in the link below,
"source /System/Volumes/Data/anaconda3/bin/activate"
But got the usual conda not found.
Mas OS Big Sur update - Python3 / conda / pip not found
My anaconda home does seem to be in the same location mentioned in the second answer from the post above
"/System/Volumes/Data/anaconda3"
so maybe that's the issue.
Update:
tried updating path in bash_profile as below
got error below
conda info
-bash: /anaconda3/bin/conda: No such file or directory
# added by Anaconda3 2019.03 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/System/Volumes/Data/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/System/Volumes/Data/anaconda3/etc/profile.d/conda.sh" ]; then
. "/System/Volumes/Data/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/System/Volumes/Data/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
~
~
~
~
~
~

Try to find where all the condas are and then proceed accordingly (i.e. change the path in your scripts):
find / -name "*conda*" 2>/dev/null

so after much googling, hacking, and swearing I got the second solution on this link to work:
Mas OS Big Sur update - Python3 / conda / pip not found
move your anaconda3
run the prefix rehome tool
re-initialize your conda

I got the same problem when switching to Monterey and downloading Anaconda on it. Tried lots of commands but all failed, having different problems like conda commands not found/couldn't run python script/couldn't reinstall Anaconda/python etc. It took me hours to figure out the simplest solution is just to type "chsh -s /bin/zsh" to switch to zsh...I didn't even know bash and zsh would cause such problem

Related

Conda does not install correctly - it thinks /usr is an env location

So I am having a great deal of difficulty installing conda correctly.
Here is what I have tried.
First I installed anaconda with:
sudo yum install anaconda
(I don't know if this is explicitly required, but I did it anyway)
I logged out and logged in for a fresh shell.
Then I installed conda with:
sudo yum install conda
Again I logged out and logged in for a fresh shell.
At this point when I typed which conda, I got:
conda ()
{
\local cmd="${1-__missing__}";
case "$cmd" in
activate | deactivate)
__conda_activate "$#"
;;
install | update | upgrade | remove | uninstall)
__conda_exe "$#" || \return;
__conda_reactivate
;;
*)
__conda_exe "$#"
;;
esac
}
which I thought was weird. Then I typed conda init, I was prompted for the superuser password, and then I got:
no change /usr/condabin/conda
modified /usr/bin/conda
modified /usr/bin/conda-env
modified /usr/bin/activate
modified /usr/bin/deactivate
modified /usr/etc/profile.d/conda.sh
modified /usr/etc/fish/conf.d/conda.fish
modified /usr/shell/condabin/Conda.psm1
modified /usr/shell/condabin/conda-hook.ps1
modified /usr/lib/python3.6/site-packages/xontrib/conda.xsh
modified /usr/etc/profile.d/conda.csh
modified /home/jeff/.bashrc
==> For changes to take effect, close and re-open your current shell. <==
so I logged out and logged in again. At this point I got the (base) prefix in front of the prompt. So then I type conda activate base and everything seems right. But when I type conda list I get
EnvironmentLocationNotFound: Not a conda environment: /usr
and when I type conda info, I get:
active environment : base
active env location : /usr
shell level : 1
user config file : /home/jeff/.condarc
populated config files : /usr/share/conda/condarc.d/defaults.yaml
conda version : 4.10.3
conda-build version : not installed
python version : 3.6.8.final.0
virtual packages : __linux=4.18.0=0
__glibc=2.28=0
__unix=0=0
__archspec=1=x86_64
base environment : /usr (read only)
conda av data dir : /usr/etc/conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /var/cache/conda/pkgs
/home/jeff/.conda/pkgs
envs directories : /home/jeff/.conda/envs
/usr/envs
platform : linux-64
user-agent : conda/4.10.3 requests/2.20.0 CPython/3.6.8 Linux/4.18.0-372.16.1.el8_6.x86_64 rocky/8.6 glibc/2.28
UID:GID : 1000:1000
netrc file : None
offline mode : False
I think the problem is with the "active env location" and "env directories" entries. Are those correct? I tried looking around at how to change these values but I was unsuccessful. How can I continue?

conda source deactivate : bash: deactivate: No such file or directory

I installed Conda at a different location than the default location on Ubuntu 16.4 using the official installation helper.
Now conda create and source activate works, but source deactivate gives me the error:
(deep) yuqiong#yuqiong-G7-7588:/media/yuqiong/DATA$ source deactivate
bash: deactivate: No such file or directory
I checked this issue on Github: #458: "Using source deactivate on a conda env fails unless the root anaconda directory is in PATH". It seems to be related, but I do not understand what happens when I run source deactivate inside a conda environment. Is it because something is wrong with my PATH variables?
Here is the part of my /.bashrc related to Conda, if helpful.
Thanks so much for your help!
# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/media/yuqiong/DATA/Anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/media/yuqiong/DATA/Anaconda3/etc/profile.d/conda.sh" ]; then
. "/media/yuqiong/DATA/Anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/media/yuqiong/DATA/Anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
### conda shortcuts
function actv() {
#do things with parameters like $1 such as
source activate "$1"
}
So I still have not figured out why source deactivate does not work anymore, but the good thing is conda deactivate works. I'm sticking with that now.
And I think the problem is I do not understand how conda works... Here is a gentle intro to package manager if anyone's interested...https://medium.com/#sdboyer/so-you-want-to-write-a-package-manager-4ae9c17d9527
Use
conda deactivate
To deactivate or to go to the base source and then you can use
conda info --envs
to get the list of available sources
source activate <source_name>
and to activate a particular source.
Refer this for more -> Managing environments - conda.io
Just Put
conda deactivate
good to know
conda activate and conda deactivate only work on conda 4.6 and later versions

Where is the command “conda” (Executable file in Anaconda ?

I do not add anaconda3/bin into my $PATH variable in ubuntu(run which conda return null).
I also can use conda -V and conda -h in another directory.
Of course, the executable file conda in anaconda3/bin also works.
but another command like jupyter only works we are in the following directory anaconda3/bin.
I'm puzzled about it, the issue seems to be the environmental variable, I don't know how to fix it, any help is appreciated.
Add the anaconda path to the bash
cd ~
gedit .bashrc
export PATH=~/anaconda3/bin:$PATH

Bash and Conda: Installing non-conda packages in conda environment with executable bash script

I am writing a bash script with the objective of hosting it on a computing cluster. I want the script to create a conda environment for whichever user executes it, so that everyone on our team can quickly set-up the same working environment.
I realize this is a bit overkill for the number of commands necessary but I wanted to practice some bash scripting. Here is my script so far:
#!/bin/bash
# Load anaconda
module load Anaconda/4.2.0
# Create environment
conda create -n ADNI
# Load environment
source activate ADNI
# Install image processing software
pip install med2image
echo 'A working environment named ADNI has been created.'
echo 'Please run `source activate ADNI` to work in it.'
This script creates the environment successfully. However, once I load the environment after running the script, I run conda list to see which packages are loaded within it and get the following output:
(ADNI) MLG-BH0039:ADNI_DeepLearning johnca$ conda list
# packages in environment at /Users/johnca/miniconda3/envs/ADNI:
#
(ADNI) MLG-BH0039:ADNI_DeepLearning johnca$
This gives me the impression that the environment has no packages loaded in it. Is this correct? If so, how can I alter the script so that the desired packages successfully install into the specified environment.
Thanks!
I managed to find a better way to automate this process by creating an environment.yml file with all the desired packages. This can include pip packages as well. My file looks like this:
name: ADNI
channels:
- soumith
- defaults
dependencies:
- ca-certificates=2017.08.26=h1d4fec5_0
- certifi=2017.11.5=py36hf29ccca_0
- cffi=1.11.2=py36h2825082_0
- freetype=2.8=hab7d2ae_1
- intel-openmp=2018.0.0=hc7b2577_8
- jpeg=9b=h024ee3a_2
- libffi=3.2.1=hd88cf55_4
- libgcc=7.2.0=h69d50b8_2
- libgcc-ng=7.2.0=h7cc24e2_2
- libgfortran-ng=7.2.0=h9f7466a_2
- libpng=1.6.32=hbd3595f_4
- libstdcxx-ng=7.2.0=h7a57d05_2
- libtiff=4.0.9=h28f6b97_0
- mkl=2018.0.1=h19d6760_4
- numpy=1.13.3=py36ha12f23b_0
- olefile=0.44=py36h79f9f78_0
- openssl=1.0.2n=hb7f436b_0
- pillow=4.2.1=py36h9119f52_0
- pip=9.0.1=py36h6c6f9ce_4
- pycparser=2.18=py36hf9f622e_1
- python=3.6.0=0
- readline=6.2=2
- scipy=1.0.0=py36hbf646e7_0
- setuptools=36.5.0=py36he42e2e1_0
- six=1.11.0=py36h372c433_1
- sqlite=3.13.0=0
- tk=8.5.18=0
- wheel=0.30.0=py36hfd4bba0_1
- xz=5.2.3=h55aa19d_2
- zlib=1.2.11=ha838bed_2
- pytorch=0.2.0=py36hf0d2509_4cu75
- torchvision=0.1.9=py36h7584368_1
- pip:
- cycler==0.10.0
I can then automate creating the environment by referencing this file, as in:
#!/bin/bash
# Load anaconda
module load Anaconda/4.2.0
# Create environment
conda env create -f adni_env.yml
echo ' '
echo 'A working environment named ADNI has been created or updated.'
echo 'If working on the cadillac server please `module load Anaconda/4.2.0`.'
echo 'Then run `source activate ADNI` to work within the environment.'
echo ' '
I hope this can help anyone in the future who may have similar issues.
The command
conda create -n ADNI
creates an environment with no packages installed, not even Python or pip. Therefore, despite activating the environment, you are still using some other pip that appears on your PATH. You need to install pip or Python into the environment first, either when the environment is created or afterwards with the conda install command
conda create -n ADNI python=3.6
will install Python, which brings along pip when the environment is created or
conda create -n ADNI
conda install -n ADNI python=3.6
will install Python afterwards.
In the best case, you would use conda to install that package. It isn't all that difficult to create a conda package from a pip package and upload it to a channel on Anaconda.org so your team can access it.

Pyenv choose virtualenv directory

I just began to use pyenv to manage my python versions, and began to use the pyenv virtualenv plugin to manage my virtualenvs, and so far, I have loved it. One thing I miss however, is that with virtualenv, you could actually place virtual environments in repository directories so that your repository was a completely reproducible environment. Does anyone know of a way to choose the directory of your virtualenv in pyenv?
Short answer: You can’t, as far as I know.
It wouldn’t really work either, right? If you use pyenv virtualenv to install a virtualenv into a repo, and you clone that repo to another machine… how would pyenv on the new machine know to take control of the virtualenv in the repository?
Also, “you probably shouldn’t do that”. Virtualenvs are not 100% decoupled from the underlying Python installation, and aren’t really all that portable. And do you really want to litter your repositories with a bunch of easily replicated junk? The “right” way to go about things is probably to to maintain a requirements.txt for pip — that way you can easily reproduce your development environment wherever you clone your repo.
That all said, there’s nothing stopping you from using plain old virtualenv to create a virtualenv anywhere you like, even if you installed virtualenv into a Python interpreter under pyenv control. That virtualenv itself will of course not be administered by pyenv, but you can still use it as you always did…
Here is a GitHub issue on the project tracker asking about this: https://github.com/pyenv/pyenv/issues/802
The reply by a project collaborator was:
You can just create virtualenv in any location. To use it from pyenv, create symlink to the environment in ~/.pyenv/versions
although I must say I'm not very satisfied with this solution.
There's a workaround
In your project directory, create a .python-version file. Assuming you already installed some virtual environment using pyenv-virtualenv, then append this line to it(you may want to change the version number):
3.7.1/envs/your-project-name#3.7.1
Whenever you enter into the directory, the correct python version will be used, and it works pretty well.
How about:
pyenv install -s 3.8.3 # install preferred version if needed
PYENV_VERSION=3.8.3 python -m venv /tmp/your/prefered/dir ; source /tmp/your/prefered/dir/activate
Note that this method uses venv, not virtualenv, which is slightly different, but a part of a standard library.
Slightly left-field answer, but I ended up writing a hacky equivalent of pyenv that looks for a virtualenv in a directory and its parents because pyenv doesn't really seem to support this as layed out in the answer about.
I called this script enpy, put it on my path and then called e.g. enpy -c import sys; print(sys.executable)
#!/usr/bin/python3
import os
import sys
from pathlib import Path
NAMES = ("venv", "env", ".env", ".venv")
def find_python():
cwd = Path(os.getcwd())
for direc in [cwd] + list(cwd.parents):
for p in NAMES:
venv = direc / p
if venv.exists():
return venv / "bin" / "python"
else:
raise Exception("Could not find python")
python = find_python()
os.execvp(str(python), [str(python)] + sys.argv[1:])
To build on-top of a previous comment, you can add this to your .zshrc:
pyCreate () {
if [ -d .venv ];then
rm -rf .venv; fi &&
if [ -f .python-version ];then
pyVersion="local"
else
pyVersion="global"; fi &&
location=${1:-requirements.txt} &&
if [ -f $location ];then
action=(pip install -r $location)
else
action=(echo "\n No file: $location \n"); fi &&
PYENV_VERSION=`pyenv $pyVersion` python -m venv .venv &&
source .venv/bin/activate &&
pip install --upgrade pip && $action
}
I use the simple recipe of
python -m venv virt to create the local venv
Link the venv to pyenv with ln -s <local virt> ~/.pyenv/versions/<venv name>
Now you can do pyenv local <venv name> and all other normal operations from pyenv with this venv.
For the interested I have made two CLIs
pyenv-here to create a new venv and set local dir in one go
pyenv-link to link a local virt to pyenv
The top comment is wrong; you certainly can.
Once you create your virtual environment with pyenv virtualenv 3.9.15 your-environment-name, you can specify the directories in which this environment will be used automatically with the following command. In your desired directory, run:
pyenv local your-environment-name
The command will create the necessary .python-version file that includes the name of your environment. From now on, every time you enter the folder, the specified environment will be used.
If you want to just use pyenv specific python version and create virtual env from it in wanted directory, you can for example do this:
~/.pyenv/versions/3.10.8/bin/python -m venv my/path/to/venv

Resources