Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

520
Vistas
Can't activate conda env from shell script

I've tried everything I've seen on SO to get this to work, but so far everything fails. Using macOS Big Sur 11.6, bash in Terminal (not zsh).

I'm trying to create a setup file and execute with sh setup.sh that will setup the env, install python, and then activate it. Nothing fancy. Doing it manually works fine, but once I put it in a shell script, it won't work. I'm running this script from inside an empty project folder.

Current script:

conda create -n MASTER python=3.8.5 -y

conda activate MASTER

Yeah, it's that simple to start with. I commented out the other pip installs until this works properly.

I tried running: bash -i setup.sh but it still does not activate. I get no errors but I'm still stuck in (base).

I tried using source: source /opt/anaconda3/etc/profile.d/conda.sh at beginning of script and/or before activate, still doesn't work. No errors again, but stuck in (base).

I tried using: eval $(conda shell.bash hook) at the start of script and before I try to activate the env, but it fails. This time I get the error:

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

But if I run conda init bash (in Terminal or in the script itself), it outputs:

no change     /opt/anaconda3/condabin/conda
no change     /opt/anaconda3/bin/conda
no change     /opt/anaconda3/bin/conda-env
no change     /opt/anaconda3/bin/activate
no change     /opt/anaconda3/bin/deactivate
no change     /opt/anaconda3/etc/profile.d/conda.sh
no change     /opt/anaconda3/etc/fish/conf.d/conda.fish
no change     /opt/anaconda3/shell/condabin/Conda.psm1
no change     /opt/anaconda3/shell/condabin/conda-hook.ps1
no change     /opt/anaconda3/lib/python3.8/site-packages/xontrib/conda.xsh
no change     /opt/anaconda3/etc/profile.d/conda.csh
no change     /Users/liquidRock/.bash_profile
No action taken.

I tried doing /opt/anaconda3/bin/conda activate MASTER which also prompts me to do conda init bash.

Even tried adding #!/bin/bash to the top of the file just in case, but no dice.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Thanks to @fravadona for the simplest of solutions.

Simply executing the script with source instead of sh. 🤦🏻‍♂️

Final setup.sh script (with my preliminary pip installs):

# env & python
conda create -n MASTER python=3.8.5 -y
conda activate MASTER

# pip installs
pip install cmake
pip install --upgrade pip setuptools wheel
pip install opencv-python==4.2.0.32
pip install argparse
pip install datetime
pip install colorama
pip install python-dotenv
pip install python-dotenv[cli]

Executed thusly:

$ source setup.sh

Anaconda creates the env, installs python and dependencies, activates the env, then pip installs the additional dependencies.

Still not sure why it won't work by adding other things to the shell script, but this is still a great, simple solution. And yes, I am a novice with this stuff.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda