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

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.

Related

Cannot conda activate from script or docker

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.

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

Does conda env export use pip?

I successfully created a Conda environment at path ./xxxxx/conda_env/xyz. I am also able to activate that environment.
However, conda env export -p /xxxxx/conda_env/xyz fails (I have the same environment activated), giving error
Traceback (most recent call last):
File "/xxxxx/conda_env/xyz/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal.cli'
Does conda env export uses pip? If so, why?
P.S. I do have pip installed
$ conda list --explicit | grep pip
http://anaconda:8080/conda/anaconda/linux-64/pip-20.0.2-py36_1.tar.bz2
Your command doesn't make sense:
conda env export -p /xxxxx/conda_env/xyz
should probably be
conda env export -p /xxxxx/anaconda3/envs/conda_env
But it seems this command is deprecated anyhow. According to Exporting the environment.yml file your should instead use
conda activate conda_env
conda env export > environment.yml
However, it's totally fine to pip install packages from pypi.org into a conda environment that are not available on anaconda.org. And ideally pip packages should also end up in the environments.yml like
name: conda_env
channels:
- default
dependencies:
- python=3.8
- pip:
- tables
So no surprise that pip is involved here.

Spyder not starting AttributeError: module 'asycio' has no attribute 'WindowsSelectorLoopPolicy'

I activate my environment and launch from the conda command line
> activate myenv
> spyder
but I get this error:
Please help
I had to remove my environment conda remove -n envname --all and then conda create -n envname followed by activate envname then conda install -c anaconda spyder.
Seems that there is an issue with my old environments and a recent update I performed.
Now I have to just install the rest of the packages into this environment as clone from previous one wont even allow spyder4 to be installed.

Python environment names missing

If I list my python environments I get a number of unnamed or nameless environments:
(base)$ conda env list
# conda environments:
#
/Users/drf/anaconda
/Users/drf/anaconda/envs/arc
/Users/drf/anaconda/envs/grids
/Users/drf/anaconda/envs/junk
/Users/drf/anaconda/envs/msr
/Users/drf/anaconda/envs/py27
base * /Users/drf/anaconda/envs/py37
/Users/drf/anaconda/envs/pygridgen
/Users/drf/anaconda/envs/pynomo
/Users/drf/anaconda/envs/python3
/Users/drf/anaconda/envs/pytides
/Users/drf/anaconda/envs/pytides3
/Users/drf/anaconda/envs/wxpython
(base)$
I can activate them with their path names, but I can't use shortnames to activate them:
(base) $ conda activate base
(base) $ conda activate /Users/drf/anaconda/envs/arc
(arc) $ conda activate /Users/drf/anaconda/envs/grids
(grids) $ conda activate /Users/drf/anaconda/envs/junk
(junk) $ conda activate /Users/drf/anaconda/envs/msr
(msr) $ conda activate /Users/drf/anaconda/envs/py27
(py27) $ conda activate /Users/drf/anaconda/envs/py37
(py37) $
But I cannot use the shortnames:
(msr)$ conda activate msr
Could not find conda environment: msr
You can list all discoverable environments with `conda info --envs`.
Where are the short names stored and how do I get their utility back?
Make sure you deactivate the activated environments. If you create multiple environments and activate them, they act as child processes and won't recognize the changes in the parent.
I had the same problem when I upgraded conda and anaconda. You need to add the path to your environments using:
conda config --add envs_dirs <path to envs>
For example, after I upgraded I got the following:
(base) $ conda info --envs
# conda environments:
#
/Users/mah/anaconda
/Users/mah/anaconda/envs/ase3
base * /Users/mah/opt/anaconda3
Note that my old environments were in /Users/mah/anaconda… whereas my new install is expecting the environments to be in /Users/mah/opt/anaconda3. The solution in this specific case was:
(base) $ conda config --add envs_dirs /Users/mah/anaconda/envs
(base) $ conda env list
# conda environments:
#
/Users/mah/anaconda
ase3 /Users/mah/anaconda/envs/ase3
base * /Users/mah/opt/anaconda3

Resources