Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conda shell function injects $CONDA_PREFIX into $PATH causing incorrect behavior in conda run #11174

Closed
Tracked by #11316
chenghlee opened this issue Jan 28, 2022 · 7 comments · Fixed by #11666
Closed
Tracked by #11316
Assignees
Labels
duplicate::primary if an issue/PR has duplicates, this is the consolidated, primary issue/PR in-progress issue is actively being worked on locked [bot] locked due to inactivity plugins::run pertains to conda-run severity::1 blocker; broken functionality with no workaround source::anaconda created by members of Anaconda, Inc. source::community catch-all for issues filed by community members type::bug describes erroneous operation, use severity::* to classify the type
Milestone

Comments

@chenghlee
Copy link
Contributor

chenghlee commented Jan 28, 2022

Description

What happened?

The $PATH/%PATH% set by conda run includes directories from the base environment; conda activate, on the other hand, removes base environment components from the PATH. This can be problematic, as conda run and conda activate can have different executables (and on Windows, DLLs) available to the user.

A basic replicating case:

(base) $ conda create -n py39 python=3.9
(base) $ conda run -n py39 python -c 'import os; print(os.environ["PATH"]);'
${CONDA_ROOT}/envs/py39/bin:${CONDA_ROOT}/bin:${CONDA_ROOT}/condabin:${HOME}/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(base) $ conda activate py39
(py39) $ python -c 'import os; print(os.environ["PATH"]);'
${CONDA_ROOT}/envs/py39/bin:${CONDA_ROOT}/condabin:${HOME}/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

(Note that ${CONDA_ROOT}/bin gets removed from $PATH in the activated environment, but not when using conda run.)

Conda Details

conda info
active environment : base
    active env location : ${CONDA_ROOT}
            shell level : 1
       user config file : ${HOME}/.condarc
 populated config files : ${HOME}/.condarc
          conda version : 4.11.0
    conda-build version : 3.21.7
         python version : 3.8.12.final.0
       virtual packages : __osx=10.16=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : ${CONDA_ROOT}  (writable)
      conda av data dir : ${CONDA_ROOT}/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : ${CONDA_ROOT}/pkgs
                          ${HOME}/.conda/pkgs
       envs directories : ${CONDA_ROOT}/envs
                          ${HOME}/.conda/envs
               platform : osx-64
             user-agent : conda/4.11.0 requests/2.27.1 CPython/3.8.12 Darwin/20.6.0 OSX/10.16
                UID:GID : 502:20
             netrc file : None
           offline mode : False
conda config
==> ${HOME}/.condarc <==
restore_free_channel: False
conda_build:
  error_overdepending: True
  error_overlinking: True
conda list
# packages in environment at /Users/clee/Applications/miniconda3:
#
# Name                    Version                   Build  Channel
anaconda-client           1.9.0            py38hecd8cb5_0    defaults
attrs                     21.4.0             pyhd3eb1b0_0    defaults
beautifulsoup4            4.10.0             pyh06a4308_0    defaults
brotlipy                  0.7.0           py38h9ed2024_1003    defaults
bzip2                     1.0.8                h1de35cc_0    defaults
ca-certificates           2021.10.26           hecd8cb5_2    defaults
certifi                   2021.10.8        py38hecd8cb5_2    defaults
cffi                      1.15.0           py38hc55c11b_1    defaults
chardet                   4.0.0           py38hecd8cb5_1003    defaults
charset-normalizer        2.0.4              pyhd3eb1b0_0    defaults
clyent                    1.2.2                    py38_1    defaults
conda                     4.11.0           py38hecd8cb5_0    defaults
conda-build               3.21.7           py38hecd8cb5_0    defaults
conda-content-trust       0.1.1              pyhd3eb1b0_0    defaults
conda-package-handling    1.7.3            py38h9ed2024_1    defaults
conda-token               0.3.0              pyhd3eb1b0_0    defaults
coreutils                 8.32                 haf1e3a3_0    defaults
cryptography              36.0.0           py38hf6deb26_0    defaults
filelock                  3.4.2              pyhd3eb1b0_0    defaults
glob2                     0.7                pyhd3eb1b0_0    defaults
icu                       58.2                 h0a44026_3    defaults
idna                      3.3                pyhd3eb1b0_0    defaults
importlib-metadata        4.8.2            py38hecd8cb5_0    defaults
importlib_metadata        4.8.2                hd3eb1b0_0    defaults
ipython_genutils          0.2.0              pyhd3eb1b0_1    defaults
jinja2                    2.11.3             pyhd3eb1b0_0    defaults
jq                        1.6               h9ed2024_1000    defaults
jsonschema                3.2.0              pyhd3eb1b0_2    defaults
jupyter_core              4.9.1            py38hecd8cb5_0    defaults
libarchive                3.4.2                ha0e9c3a_0    defaults
libcxx                    12.0.0               h2f01273_0    defaults
libffi                    3.3                  hb1e8313_2    defaults
libiconv                  1.16                 h1de35cc_0    defaults
liblief                   0.10.1               h0a44026_0    defaults
libxml2                   2.9.12               hcdb78fc_0    defaults
lz4-c                     1.9.3                h23ab428_1    defaults
markupsafe                2.0.1            py38h9ed2024_0    defaults
nbformat                  5.1.3              pyhd3eb1b0_0    defaults
ncurses                   6.3                  hca72f7f_2    defaults
oniguruma                 6.9.7.1              h9ed2024_0    defaults
openssl                   1.1.1m               hca72f7f_0    defaults
packaging                 21.3               pyhd3eb1b0_0    defaults
pip                       21.2.4           py38hecd8cb5_0    defaults
pkginfo                   1.8.2              pyhd3eb1b0_0    defaults
psutil                    5.8.0            py38h9ed2024_1    defaults
py-lief                   0.10.1           py38haf313ee_0    defaults
pycosat                   0.6.3            py38h1de35cc_1    defaults
pycparser                 2.21               pyhd3eb1b0_0    defaults
pyopenssl                 21.0.0             pyhd3eb1b0_1    defaults
pyparsing                 3.0.4              pyhd3eb1b0_0    defaults
pyrsistent                0.18.0           py38hca72f7f_0    defaults
pysocks                   1.7.1                    py38_1    defaults
python                    3.8.12               h88f2d9e_0    defaults
python-dateutil           2.8.2              pyhd3eb1b0_0    defaults
python-libarchive-c       2.9                pyhd3eb1b0_1    defaults
python.app                3                py38hca72f7f_0    defaults
pytz                      2021.3             pyhd3eb1b0_0    defaults
pyyaml                    6.0              py38hca72f7f_1    defaults
readline                  8.1.2                hca72f7f_1    defaults
requests                  2.27.1             pyhd3eb1b0_0    defaults
ripgrep                   12.1.1                        0    defaults
ruamel.yaml               0.16.12          py38haf1e3a3_1    defaults
ruamel.yaml.clib          0.2.6            py38hca72f7f_0    defaults
ruamel_yaml               0.15.100         py38h9ed2024_0    defaults
setuptools                58.0.4           py38hecd8cb5_0    defaults
six                       1.16.0             pyhd3eb1b0_0    defaults
soupsieve                 2.3.1              pyhd3eb1b0_0    defaults
sqlite                    3.37.0               h707629a_0    defaults
tk                        8.6.11               h7bc2e8c_0    defaults
tqdm                      4.62.3             pyhd3eb1b0_1    defaults
traitlets                 5.1.1              pyhd3eb1b0_0    defaults
urllib3                   1.26.7             pyhd3eb1b0_0    defaults
wget                      1.20.1               h051b688_0    defaults
wheel                     0.37.1             pyhd3eb1b0_0    defaults
xz                        5.2.5                h1de35cc_0    defaults
yaml                      0.2.5                haf1e3a3_0    defaults
zipp                      3.7.0              pyhd3eb1b0_0    defaults
zlib                      1.2.11               h4dc903c_4    defaults
zstd                      1.5.0                hcb37349_1    defaults

Resolution

It would appear that the __add_sys_prefix_to_path shell function added in conda 4.6.12 is the culprit here.

Duplicate Issues

@chenghlee chenghlee added type::bug describes erroneous operation, use severity::* to classify the type source::anaconda created by members of Anaconda, Inc. plugins::run pertains to conda-run labels Jan 28, 2022
@jezdez jezdez added this to the 4.12.0 milestone Feb 3, 2022
@jezdez
Copy link
Member

jezdez commented Feb 3, 2022

@chenghlee do you think this is related to #11072?

@chenghlee
Copy link
Contributor Author

@jezdez That's my suspicion, but I can't exactly prove it.

@jezdez jezdez added severity::2 critical; broken functionality with an unacceptably complex workaround backlog issue has been triaged but has not been earmarked for any upcoming release labels Feb 3, 2022
@beeankha beeankha added the duplicate::primary if an issue/PR has duplicates, this is the consolidated, primary issue/PR label Feb 21, 2022
@jezdez jezdez self-assigned this Feb 22, 2022
@CheeseMochi CheeseMochi added the in-progress issue is actively being worked on label Feb 22, 2022
@conda-bot conda-bot removed the backlog issue has been triaged but has not been earmarked for any upcoming release label Feb 22, 2022
@beeankha
Copy link
Contributor

Related to issue #11231

@jezdez
Copy link
Member

jezdez commented Feb 25, 2022

We've reviewed the work-around in #11257 and decided to remove this from the upcoming 4.12.0 release since we don't have the confidence that it would be an appropriate fix.

We'll need to dig more into why #8528 added the __add_sys_prefix_to_path function to the shell scripts (and related Windows versions). @kenodegard's comment also sheds some light on the subtleties of the problem.

@jezdez jezdez modified the milestones: 4.12.0, Release TBD Feb 25, 2022
@kenodegard kenodegard added the backlog issue has been triaged but has not been earmarked for any upcoming release label Mar 7, 2022
@conda-bot conda-bot removed the in-progress issue is actively being worked on label Mar 7, 2022
@karrtikr
Copy link

karrtikr commented Mar 8, 2022

Potentially related to #11305

@jezdez jezdez added severity::1 blocker; broken functionality with no workaround source::community catch-all for issues filed by community members labels May 12, 2022
@jezdez jezdez modified the milestones: Release TBD, 4.13.0 May 12, 2022
@jezdez
Copy link
Member

jezdez commented May 12, 2022

As mentioned in yesterday's community call we're bumping this up in severity since it seems to affect a lot of users of Visual Studio Code.

@kenodegard kenodegard added the in-progress issue is actively being worked on label May 12, 2022
@conda-bot conda-bot removed the backlog issue has been triaged but has not been earmarked for any upcoming release label May 12, 2022
@kenodegard kenodegard assigned kenodegard and unassigned jezdez May 12, 2022
@kenodegard kenodegard modified the milestones: 4.13.0, 4.14.0 May 20, 2022
@kenodegard kenodegard removed the in-progress issue is actively being worked on label Jun 1, 2022
@conda-bot conda-bot added the backlog issue has been triaged but has not been earmarked for any upcoming release label Jun 1, 2022
@LtDan33 LtDan33 added in-progress issue is actively being worked on and removed backlog issue has been triaged but has not been earmarked for any upcoming release labels Jul 27, 2022
@kenodegard kenodegard added in-progress issue is actively being worked on and removed in-progress issue is actively being worked on labels Jul 27, 2022
@kenodegard kenodegard modified the milestones: 4.14.0, 4.15.0 Aug 1, 2022
@imatiach-msft
Copy link

imatiach-msft commented Oct 28, 2022

I was able to work around this by calling conda deactivate first, like this (and then passing to subprocess.check_call in my case):

    command = [
        "conda",
        "deactivate",
        "&&",
        "conda",
        "run",
        "-n",
        self.inference_conda_env,
        "python",
        get_wrapmodel_filepath(),
        "--model_path",
        self.model_path,
        "--wrapped_model_path",
        self.wrapped_model_path,
    ]

related issues:
#11305
#2379
#11174

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate::primary if an issue/PR has duplicates, this is the consolidated, primary issue/PR in-progress issue is actively being worked on locked [bot] locked due to inactivity plugins::run pertains to conda-run severity::1 blocker; broken functionality with no workaround source::anaconda created by members of Anaconda, Inc. source::community catch-all for issues filed by community members type::bug describes erroneous operation, use severity::* to classify the type
Projects
Archived in project
9 participants