Skip to content

Can't execute conda activate from bash script #7980

@mjspeck

Description

@mjspeck

Current Behavior

Trying to use conda activate my_env does not work inside a bash script. The workaround is to use source activate my_env but this shouldn't be necessary.

Steps to Reproduce

Write a bash script with the following code inside, let's call it my-script.sh:

conda activate my_env

When you run ./my-script.sh, you get the following output:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
If your shell is Bash or a Bourne variant, enable conda for the current user with

    $ echo ". /Users/matthewspeck/anaconda3/etc/profile.d/conda.sh" >> ~/.bash_profile

or, for all users, enable conda with

    $ sudo ln -s /Users/matthewspeck/anaconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh

The options above will permanently enable the 'conda' command, but they do NOT
put conda's base (root) environment on PATH.  To do so, run

    $ conda activate

in your terminal, or to put the base environment on PATH permanently, run

    $ echo "conda activate" >> ~/.bash_profile

Previous to conda 4.4, the recommended way to activate conda was to modify PATH in
your ~/.bash_profile file.  You should manually remove the line that looks like

    export PATH="/Users/matthewspeck/anaconda3/bin:$PATH"

^^^ The above line should NO LONGER be in your ~/.bash_profile file! ^^^

However, conda is in fact installed correctly, and runs fine in the command line.

The command which conda returns the following:

conda () {
	if [ "$#" -lt 1 ]
	then
		$_CONDA_EXE
	else
		\local cmd="$1"
		shift
		case "$cmd" in
			(activate) _conda_activate "$@" ;;
			(deactivate) _conda_deactivate "$@" ;;
			(install | update | uninstall | remove) $_CONDA_EXE "$cmd" "$@" && _conda_reactivate ;;
			(*) $_CONDA_EXE "$cmd" "$@" ;;
		esac
	fi
}

Expected Behavior

conda should activate in a bash script the same way it does on the command line.

Environment Information

`conda info`


     active environment : base
    active env location : /Users/matthewspeck/anaconda3
            shell level : 1
       user config file : /Users/matthewspeck/.condarc
 populated config files : /Users/matthewspeck/.condarc
          conda version : 4.5.11
    conda-build version : 3.16.2
         python version : 3.6.6.final.0
       base environment : /Users/matthewspeck/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/osx-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/pro/osx-64
                          https://repo.anaconda.com/pkgs/pro/noarch
          package cache : /Users/matthewspeck/anaconda3/pkgs
                          /Users/matthewspeck/.conda/pkgs
       envs directories : /Users/matthewspeck/anaconda3/envs
                          /Users/matthewspeck/.conda/envs
               platform : osx-64
             user-agent : conda/4.5.11 requests/2.20.0 CPython/3.6.6 Darwin/17.7.0 OSX/10.13.6
                UID:GID : 501:20
             netrc file : None
           offline mode : False

`conda config --show-sources`

==> /Users/matthewspeck/.condarc <==
ssl_verify: True
channels:
  - defaults

`conda list --show-channel-urls`

# packages in environment at /Users/matthewspeck/anaconda3:
#
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0                    py36_0    defaults
alabaster                 0.7.12                   py36_0    defaults
anaconda-client           1.7.2                    py36_0    defaults
anaconda-navigator        1.9.2                    py36_0    defaults
anaconda-project          0.8.2                    py36_0    defaults
appdirs                   1.4.3            py36h28b3542_0    defaults
appnope                   0.1.0            py36hf537a9a_0    defaults
appscript                 1.0.1            py36h1de35cc_1    defaults
asn1crypto                0.24.0                   py36_0    defaults
astroid                   2.0.4                    py36_0    defaults
astropy                   3.0.5            py36h1de35cc_0    defaults
atomicwrites              1.2.1                    py36_0    defaults
attrs                     18.2.0           py36h28b3542_0    defaults
automat                   0.7.0                    py36_0    defaults
babel                     2.6.0                    py36_0    defaults
backcall                  0.1.0                    py36_0    defaults
backports                 1.0                      py36_1    defaults
backports.os              0.1.1                    py36_0    defaults
backports.shutil_get_terminal_size 1.0.0                    py36_2    defaults
beautifulsoup4            4.6.3                    py36_0    defaults
bitarray                  0.8.3            py36h1de35cc_0    defaults
bkcharts                  0.2              py36h073222e_0    defaults
blas                      1.0                         mkl    defaults
blaze                     0.11.3                   py36_0    defaults
bleach                    3.0.2                    py36_0    defaults
blosc                     1.14.4               hd9629dc_0    defaults
bokeh                     1.0.1                    py36_0    defaults
boto                      2.49.0                   py36_0    defaults
bottleneck                1.2.1            py36h1d22016_1    defaults
bzip2                     1.0.6                h1de35cc_5    defaults
ca-certificates           2018.03.07                    0    defaults
certifi                   2018.10.15               py36_0    defaults
cffi                      1.11.5           py36h6174b99_1    defaults
chardet                   3.0.4                    py36_1    defaults
click                     7.0                      py36_0    defaults
cloudpickle               0.6.1                    py36_0    defaults
clyent                    1.2.2                    py36_1    defaults
colorama                  0.4.0                    py36_0    defaults
conda                     4.5.11                   py36_0    defaults
conda-build               3.16.2                   py36_0    defaults
conda-env                 2.6.0                         1    defaults
constantly                15.1.0           py36h28b3542_0    defaults
contextlib2               0.5.5            py36hd66e5e7_0    defaults
coverage                  4.5.1            py36h1de35cc_0    defaults
cryptography              2.3.1            py36hdbc3d79_0    defaults
curl                      7.61.0               ha441bb4_0    defaults
cycler                    0.10.0           py36hfc81398_0    defaults
cython                    0.29             py36h0a44026_0    defaults
cytoolz                   0.9.0.1          py36h1de35cc_1    defaults
dask                      0.20.0                   py36_0    defaults
dask-core                 0.20.0                   py36_0    defaults
datashape                 0.5.4                    py36_1    defaults
dbus                      1.13.2               h760590f_1    defaults
decorator                 4.3.0                    py36_0    defaults
defusedxml                0.5.0                    py36_1    defaults
distributed               1.24.0                   py36_0    defaults
docutils                  0.14             py36hbfde631_0    defaults
entrypoints               0.2.3                    py36_2    defaults
et_xmlfile                1.0.1            py36h1315bdc_0    defaults
expat                     2.2.6                h0a44026_0    defaults
fastcache                 1.0.2            py36h1de35cc_2    defaults
filelock                  3.0.10                   py36_0    defaults
flask                     1.0.2                    py36_1    defaults
flask-cors                3.0.6                    py36_0    defaults
freetype                  2.9.1                hb4e5f40_0    defaults
get_terminal_size         1.0.0                h7520d66_0    defaults
gettext                   0.19.8.1             h15daf44_3    defaults
gevent                    1.3.7            py36h1de35cc_1    defaults
glib                      2.56.2               hd9629dc_0    defaults
glob2                     0.6                      py36_1    defaults
gmp                       6.1.2                hb37e062_1    defaults
gmpy2                     2.0.8            py36h6ef4df4_2    defaults
greenlet                  0.4.15           py36h1de35cc_0    defaults
h5py                      2.8.0            py36h878fce3_3    defaults
hdf5                      1.10.2               hfa1e0ec_1    defaults
heapdict                  1.0.0                    py36_2    defaults
html5lib                  1.0.1                    py36_0    defaults
hyperlink                 18.0.0                   py36_0    defaults
icu                       58.2                 h4b95b61_1    defaults
idna                      2.7                      py36_0    defaults
imageio                   2.4.1                    py36_0    defaults
imagesize                 1.1.0                    py36_0    defaults
importlib_metadata        0.6                      py36_0    defaults
incremental               17.5.0                   py36_0    defaults
intel-openmp              2019.0                      118    defaults
ipykernel                 5.1.0            py36h39e3cac_0    defaults
ipython                   7.1.1            py36h39e3cac_0    defaults
ipython_genutils          0.2.0            py36h241746c_0    defaults
ipywidgets                7.4.2                    py36_0    defaults
isort                     4.3.4                    py36_0    defaults
itsdangerous              1.1.0                    py36_0    defaults
jbig                      2.1                  h4d881f8_0    defaults
jdcal                     1.4                      py36_0    defaults
jedi                      0.13.1                   py36_0    defaults
jinja2                    2.10                     py36_0    defaults
jpeg                      9b                   he5867d9_2    defaults
jsonschema                2.6.0            py36hb385e00_0    defaults
jupyter                   1.0.0                    py36_7    defaults
jupyter_client            5.2.3                    py36_0    defaults
jupyter_console           6.0.0                    py36_0    defaults
jupyter_core              4.4.0                    py36_0    defaults
jupyterlab                0.35.3                   py36_0    defaults
jupyterlab_launcher       0.13.1                   py36_0    defaults
jupyterlab_server         0.2.0                    py36_0    defaults
keyring                   16.0.0                   py36_0    defaults
kiwisolver                1.0.1            py36h0a44026_0    defaults
lazy-object-proxy         1.3.1            py36h1de35cc_2    defaults
libarchive                3.3.3                hc2e69e3_1    defaults
libcurl                   7.61.0               hf30b1f0_0    defaults
libcxx                    4.0.1                h579ed51_0    defaults
libcxxabi                 4.0.1                hebd6815_0    defaults
libedit                   3.1.20170329         hb402a30_2    defaults
libffi                    3.2.1                h475c297_4    defaults
libgfortran               3.0.1                h93005f0_2    defaults
libiconv                  1.15                 hdd342a3_7    defaults
libpng                    1.6.34               he12f830_0    defaults
libsodium                 1.0.16               h3efe00b_0    defaults
libssh2                   1.8.0                h322a93b_4    defaults
libtiff                   4.0.9                hcb84e12_2    defaults
libxml2                   2.9.8                hab757c2_1    defaults
libxslt                   1.1.32               hb819dd2_0    defaults
llvmlite                  0.25.0           py36h8c7ce04_0    defaults
locket                    0.2.0            py36hca03003_1    defaults
lxml                      4.2.5            py36hef8c89e_0    defaults
lz4-c                     1.8.1.2              h1de35cc_0    defaults
lzo                       2.10                 h362108e_2    defaults
markupsafe                1.0              py36h1de35cc_1    defaults
matplotlib                3.0.0            py36h54f8f79_0    defaults
mccabe                    0.6.1                    py36_1    defaults
mistune                   0.8.4            py36h1de35cc_0    defaults
mkl                       2019.0                      118    defaults
mkl-service               1.1.2            py36h6b9c3cc_5    defaults
mkl_fft                   1.0.6            py36hb8a8100_0    defaults
mkl_random                1.0.1            py36h5d10147_1    defaults
more-itertools            4.3.0                    py36_0    defaults
mpc                       1.1.0                h6ef4df4_1    defaults
mpfr                      4.0.1                h3018a27_3    defaults
mpmath                    1.0.0                    py36_2    defaults
msgpack-python            0.5.6            py36h04f5b5a_1    defaults
multipledispatch          0.6.0                    py36_0    defaults
navigator-updater         0.2.1                    py36_0    defaults
nbconvert                 5.4.0                    py36_1    defaults
nbformat                  4.4.0            py36h827af21_0    defaults
ncurses                   6.1                  h0a44026_0    defaults
networkx                  2.2                      py36_1    defaults
nltk                      3.3.0                    py36_0    defaults
nose                      1.3.7                    py36_2    defaults
notebook                  5.7.0                    py36_0    defaults
numba                     0.40.0           py36h6440ff4_0    defaults
numexpr                   2.6.8            py36h1dc9127_0    defaults
numpy                     1.15.4           py36h6a91979_0    defaults
numpy-base                1.15.4           py36h8a80b8c_0    defaults
numpydoc                  0.8.0                    py36_0    defaults
odo                       0.5.1            py36hc1af34a_0    defaults
olefile                   0.46                     py36_0    defaults
openpyxl                  2.5.9                    py36_0    defaults
openssl                   1.0.2p               h1de35cc_0    defaults
packaging                 18.0                     py36_0    defaults
pandas                    0.23.4           py36h6440ff4_0    defaults
pandoc                    1.19.2.1             ha5e8f32_1    defaults
pandocfilters             1.4.2                    py36_1    defaults
parso                     0.3.1                    py36_0    defaults
partd                     0.3.9                    py36_0    defaults
path.py                   11.5.0                   py36_0    defaults
pathlib2                  2.3.2                    py36_0    defaults
patsy                     0.5.1                    py36_0    defaults
pcre                      8.42                 h378b8a2_0    defaults
pep8                      1.7.1                    py36_0    defaults
pexpect                   4.6.0                    py36_0    defaults
pickleshare               0.7.5                    py36_0    defaults
pillow                    5.3.0            py36hb68e598_0    defaults
pip                       18.1                     py36_0    defaults
pkginfo                   1.4.2                    py36_1    defaults
pluggy                    0.8.0                    py36_0    defaults
ply                       3.11                     py36_0    defaults
prometheus_client         0.4.2                    py36_0    defaults
prompt_toolkit            2.0.7                    py36_0    defaults
psutil                    5.4.8            py36h1de35cc_0    defaults
ptyprocess                0.6.0                    py36_0    defaults
py                        1.7.0                    py36_0    defaults
pyasn1                    0.4.4            py36h28b3542_0    defaults
pyasn1-modules            0.2.2                    py36_0    defaults
pycodestyle               2.4.0                    py36_0    defaults
pycosat                   0.6.3            py36h1de35cc_0    defaults
pycparser                 2.19                     py36_0    defaults
pycrypto                  2.6.1            py36h1de35cc_9    defaults
pycurl                    7.43.0.2         py36hdbc3d79_0    defaults
pyflakes                  2.0.0                    py36_0    defaults
pygments                  2.2.0            py36h240cd3f_0    defaults
pylint                    2.1.1                    py36_0    defaults
pyodbc                    4.0.24           py36h0a44026_0    defaults
pyopenssl                 18.0.0                   py36_0    defaults
pyparsing                 2.3.0                    py36_0    defaults
pyqt                      5.9.2            py36h655552a_2    defaults
pysocks                   1.6.8                    py36_0    defaults
pytables                  3.4.4            py36h13cba08_0    defaults
pytest                    3.10.0                   py36_0    defaults
pytest-arraydiff          0.2              py36h39e3cac_0    defaults
pytest-astropy            0.4.0                    py36_0    defaults
pytest-cov                2.6.0                    py36_0    defaults
pytest-doctestplus        0.1.3                    py36_0    defaults
pytest-openfiles          0.3.0                    py36_0    defaults
pytest-remotedata         0.3.1                    py36_0    defaults
python                    3.6.6                hc167b69_0    defaults
python-dateutil           2.7.5                    py36_0    defaults
python-libarchive-c       2.8                      py36_6    defaults
python.app                2                        py36_9    defaults
pytz                      2018.7                   py36_0    defaults
pywavelets                1.0.1            py36h1d22016_0    defaults
pyyaml                    3.13             py36h1de35cc_0    defaults
pyzmq                     17.1.2           py36h1de35cc_0    defaults
qt                        5.9.6                h45cd832_2    defaults
qtawesome                 0.5.2                    py36_0    defaults
qtconsole                 4.4.2                    py36_0    defaults
qtpy                      1.5.2                    py36_0    defaults
readline                  7.0                  h1de35cc_5    defaults
requests                  2.20.0                   py36_0    defaults
rope                      0.11.0                   py36_0    defaults
ruamel_yaml               0.15.46          py36h1de35cc_0    defaults
scikit-image              0.14.0           py36h0a44026_1    defaults
scikit-learn              0.20.0           py36h4f467ca_1    defaults
scipy                     1.1.0            py36h28f7352_1    defaults
seaborn                   0.9.0                    py36_0    defaults
send2trash                1.5.0                    py36_0    defaults
service_identity          17.0.0           py36h28b3542_0    defaults
setuptools                40.5.0                   py36_0    defaults
simplegeneric             0.8.1                    py36_2    defaults
singledispatch            3.4.0.3          py36hf20db9d_0    defaults
sip                       4.19.8           py36h0a44026_0    defaults
six                       1.11.0                   py36_1    defaults
snappy                    1.1.7                he62c110_3    defaults
snowballstemmer           1.2.1            py36h6c7b616_0    defaults
sortedcollections         1.0.1                    py36_0    defaults
sortedcontainers          2.0.5                    py36_0    defaults
sphinx                    1.8.1                    py36_0    defaults
sphinxcontrib             1.0                      py36_1    defaults
sphinxcontrib-websupport  1.1.0                    py36_1    defaults
spyder                    3.3.1                    py36_1    defaults
spyder-kernels            0.2.6                    py36_0    defaults
sqlalchemy                1.2.13           py36h1de35cc_0    defaults
sqlite                    3.24.0               ha441bb4_0    defaults
statsmodels               0.9.0            py36h1d22016_0    defaults
sympy                     1.3                      py36_0    defaults
tblib                     1.3.2            py36hda67792_0    defaults
terminado                 0.8.1                    py36_1    defaults
testpath                  0.4.2                    py36_0    defaults
tk                        8.6.8                ha441bb4_0    defaults
toolz                     0.9.0                    py36_0    defaults
tornado                   5.1.1            py36h1de35cc_0    defaults
tqdm                      4.28.1           py36h28b3542_0    defaults
traitlets                 4.3.2            py36h65bd3ce_0    defaults
twisted                   17.5.0                   py36_0    defaults
typed-ast                 1.1.0            py36h1de35cc_0    defaults
unicodecsv                0.14.1           py36he531d66_0    defaults
unixodbc                  2.3.7                h1de35cc_0    defaults
urllib3                   1.23                     py36_0    defaults
virtualenv                16.1.0                    <pip>
wcwidth                   0.1.7            py36h8c6ec74_0    defaults
webencodings              0.5.1                    py36_1    defaults
werkzeug                  0.14.1                   py36_0    defaults
wheel                     0.32.2                   py36_0    defaults
widgetsnbextension        3.4.2                    py36_0    defaults
wrapt                     1.10.11          py36h1de35cc_2    defaults
xlrd                      1.1.0                    py36_1    defaults
xlsxwriter                1.1.2                    py36_0    defaults
xlwings                   0.14.0                   py36_0    defaults
xlwt                      1.2.0            py36h5ad1178_0    defaults
xz                        5.2.4                h1de35cc_4    defaults
yaml                      0.1.7                hc338f04_2    defaults
zeromq                    4.2.5                h0a44026_1    defaults
zict                      0.1.3                    py36_0    defaults
zlib                      1.2.11               hf3cbc9b_2    defaults
zope                      1.0                      py36_1    defaults
zope.interface            4.6.0            py36h1de35cc_0    defaults
zstd                      1.3.3                h2a6be3a_0    defaults

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogissue has been triaged but has not been earmarked for any upcoming releaseclipertains to the CLI interfacegood first issuegreat for new contributors, code change is envisioned to be trivial/relatively straight-forwardseverity::3major; broken functionality with a workaroundsource::communitycatch-all for issues filed by community membersstale::recovered[bot] recovered after being marked as staletype::bugdescribes erroneous operation, use severity::* to classify the type

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions