codex icon indicating copy to clipboard operation
codex copied to clipboard

Conda envs

Open michaelzehetleitner opened this issue 1 year ago • 5 comments

Please excuse possible violations of etiquette...

Is it possible to activate a conda env in the codex terminal? I try to instruct it to use conda run -n but it mostly forgets.

I'd appreciate any suggestions.

Cheers, MZ

michaelzehetleitner avatar May 21 '25 16:05 michaelzehetleitner

Hi @michaelzehetleitner,

Hope you are doing fine,

What I usually do is activate my desired Conda environment before launching Codex. Once the environment is activated, I run Codex from within that shell session, and it inherits the environment without issues.

conda activate yourenv

Then:

codex

Let me know if that helps or if you're running into something different!

Cheers, Ansh

ansh-info avatar May 21 '25 17:05 ansh-info

Thanks for your response and ideas. This is what I tried:

There is my base environment with python version 3.12. Then I activate the environment I want to use with codex. Then python version is 3.10, as it should be. Then I activate codex and ask it for its python version. It executes

echo 'Using python:'; which python; python --version; echo; echo 'Using python3:'; which python3; python3 --version;
    echo; echo 'sys.path, executable, and PYTHONPATH:'; python3 - << 'EOF'
    import sys, os
    print('Executable:', sys.executable)
    print('Version:', sys.version)
    print('sys.path:')
    for p in sys.path: print(p)
    print('PYTHONPATH=' + repr(os.environ.get('PYTHONPATH','')))
    EOF

and gives version 3.7.6.

My next try was to instruct codex to activate my intended env. It executes:

 BASE=$(conda info --base) && source "$BASE/etc/profile.d/conda.sh" && conda activate multi_purpose_3_10 && echo
    'Activated environment:' "$CONDA_DEFAULT_ENV" 'at' "$CONDA_PREFIX" && echo && echo 'Python executable:' $(which python)
     && python --version

Then python version within codex still is 3.7.6.

michaelzehetleitner avatar May 31 '25 10:05 michaelzehetleitner

I have the same problem. Codex doesn't run the desired python in the conda env

kiyoon avatar Jun 12 '25 01:06 kiyoon

Closing this as out of date, please re-file an issue if still relevant, thanks!

tibo-openai avatar Sep 03 '25 00:09 tibo-openai

I belive codex runs every bash command in a new shell intstance, so if you want to haave codex execute e.g. unit tests in your conda env you can include instrucctions in the agents.md to execute something like

pwsh -NoLogo -Command 'conda.exe run -n "environment name" python "python_filename.py"

Replace the values in "" with your actual environment name and an example .py file from your project.

JetStrom avatar Sep 20 '25 11:09 JetStrom