Cannot conda activate from script or docker - bash

I try to create a new anaconda environment inside docker. I get an error message I cannot get rid of. What I do in my Dockerfile is:
FROM postgis/postgis:12-master
ENV BAG_ENV=bag
RUN wget https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh --quiet -O /tmp/anaconda.sh
RUN /bin/bash /tmp/anaconda.sh -b -p /opt/conda
RUN conda update conda
RUN conda init bash
RUN . /opt/conda/etc/profile.d/conda.sh
RUN conda create --name $BAG_ENV --force -y python=3.8.2 pip conda libxml2 lxml gdal psycopg2
RUN conda activate $BAG_ENV
I have the same error when running similar instructions from a bash script. The error I get is:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
From this link I learned to source conda.sh. This works for my bash script but not in my Dockerfile. How can I solve this problem?
I run this from an Ubuntu 20.04 machine, the Dockerfile is derived from alpine.

Related

jupyter not working from terminal [mac m1] zsh

I have installed Miniforge on my macbook air m1, and then did the following steps to successfully install jupyter and launch it:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
mkdir data-science
cd data-science
conda create --prefix ./env python=3.8
conda activate ./env
conda install -y jupyter
conda install pandas numpy matplotlib scikit-learn tqdm
Then: I launched Jupyter this way:
jupyter notebook
Everything worked fine. But when I exited the terminal and opened again and typed:
jupyter notebook
I got this error: zsh: command not found: jupyter
What is the problem?
I know that this is a path problem, but even when I go to env environment, and I run jupyter notebook I get the same command error.
Im not sure but I think you need to reactivate the environment each time you restart the terminal sesion.
conda activate ./env
then run your code

Running pip and conda in a shell script: not found

I am trying to run this code:
#!/bin/sh
git clone https://github.com/QCoDeS/Qcodes.git
cd Qcodes/
conda env create -f environment.yml
pip install qcodes
with the following command:
chmod +x qcodes
~ ❯ sudo ./qcodes
And I keep getting the error
./qcodes: 5: ./qcodes: conda: not found
./qcodes: 6: ./qcodes: pip: not found
conda and pip are installed and work on the terminal. Any insight is appreciated.
Found the solution. I forgot to remove sudo from the command.

Python running version 2.7 despite in a conda 3.8 environment

I created and activated a conda environment with python 3.8. When calling python it systematically runs Python version 2.7 instead of 3.8.
(base) $ conda create -n py38 python=3.8
(base) $ conda activate py38
(py38) $ python --version
Python 2.7.16
(py38) $ which python
/usr/bin/python
(py38) $ which python3.8
/Users/xyz/opt/anaconda3/envs/py38/bin/python3.8
In $PATH there is effectively /usr/bin but I'm surprised that conda doesn't override that while the environment is running. Also, there is no python alias to be found in any of the possible configuration files (.bashrc, .zshrc, .bash_profile, .profile or any other).
How can I get the python command to correctly run Python 3.8 while the py38 env is active?
Generally speaking, how to get conda to run the correct Python version "once and for all" in any new environment I would create in the future?
You need to make sure when you are in (py38) by :
echo $PATH
that /Users/xyz/opt/anaconda3/envs/py38/bin is before /usr/bin
then run
cd /Users/xyz/opt/anaconda3/envs/py38/bin
ln -fs python3.8 python3
ln -fs python3 python

/bin/sh: 1: gvm: not found

Problem:
I'm attempting to create a Dockerfile that installs all the components to run Go, to install GVM (Go Version Management), and to install specific Go Versions.
Error:
When I try building the container with:
docker build -t ##### .
I get this error:
/bin/sh: 1: gvm: not found
The command '/bin/sh -c gvm install go1.4 -B' returned a non-zero code: 127
Installed here:
/root/.gvm/scripts/env/gvm
/root/.gvm/scripts/gvm
/root/.gvm/bin/gvm
What I tried:
It's clearly able to install GVM but unable to use it. Why?
I thought maybe I needed to refresh the .bashrc or the .bash_profile ... but that didn't work, since they don't exist.
Dockerfile:
FROM #####/#####
#Installing Golang dependencies
RUN apt-get -y install curl git mercurial make binutils bison gcc build-essential
#Installing Golang
RUN ["/bin/bash", "-c", "bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)"]
#gvm does not exist here... why?
RUN gvm install go1.4 -B
RUN gvm use go1.4
Question:
Why does GVM not seem to be installed? How do I get rid of the error?
Your shell is /bin/sh, but gvm puts its initialization in ~/.bashrc, and expects /bin/bash.
You need to source the gvm initialization scripts to run the commands from a non-interactive bash shell:
RUN ["/bin/bash", "-c", ". /root/.gvm/scripts/gvm && gvm install go1.4 -B"]
RUN ["/bin/bash", "-c", ". /root/.gvm/scripts/gvm && gvm use go1.4"]
Or even better might be to put the commands you want to execute in a single bash script and add that to the image.
#!/bin/bash
set -e
source /root/.gvm/scripts/gvm
gvm install go1.4
gvm use go1.4

conda env running conda command /usr/bin/env bash no file

I run git bash in window, and create a conda environment:
conda create -n test python=2.7
source activate test
Inside the environment, I use the command:
conda install
It returns error message, /usr/bin/env bash no file or directory. Why?
I don't have a problem running conda outside the environment.

Resources