dvc: dvc run unexpectedly modifies PATH before running commands
Steps to reproduce:
pyenv install miniconda3-latest
pyenv shell miniconda3-latest
conda install dvc==0.59.2
conda create -n testenv python=3.7
mkdir dvc-test && cd dvc-test
dvc init && dvc run -f tmp.dvc 'echo $PATH'
Expected output:
- Conda env
/bin
- Pyenv shim
/bin
- Conda base
/bin
- Pyenv shim
/bin
- etc
Actual output:
- Conda base
/bin
- Pyenv shim
/bin
- Conda env
/bin
- Pyenv shim
/bin
- Conda base
/bin
- Pyenv shim
/bin
- etc
Somehow part of the PATH
from wherever DVC is installed is getting prepended to PATH
before dvc run
-ing something. This potentially breaks code in the project.
Note that installing and running DVC with Pipx instead of Conda does not result in the same problem. The adverse interaction appears to be Conda-specific (although there are many combinations of environments I haven’t yet tried). This particular Pipx installation is not being managed by Conda.
Discord conversation: https://discordapp.com/channels/485586884165107732/485596304961962003/623513705145040919
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 17 (13 by maintainers)
Commits related to this issue
- dvc: remove PATH prefixes appended by pyenv Unlike PyInstaller, pyenv doesn't leave backups of original env vars when it modifies them. If we look into the shim, pyenv and pyenv-exec, we can figure o... — committed to efiop/dvc by efiop 5 years ago
- run: make shell not load config files Config files like `~/.zshenv`, `~/.bashenv` etc, are loaded on each shell invocation, which might overwrite the environment breaking the commands we are trying t... — committed to efiop/dvc by efiop 5 years ago
- run: improve pyenv PATH modification criteria https://discordapp.com/channels/485586884165107732/485596304961962003/628766062472724510 Related to #2506 — committed to efiop/dvc by efiop 5 years ago
Great work! 🎊 Thanks everybody for taking the time!
So we’ve had an interactive debugging session with @benjaminvdb today and found that he had
~/.zshenv
file that was modifyingPATH
. As it turned out [1]so it was modifying the
PATH
when dvc was spawning a new process. Moving those lines fromzshenv
tozshrc
fixed the problem, but it would still be nice for us to protect against such things in the future. To do that we could consider using-f
option for zsh and an equivalent option for bash, to make them not load such files. Will take a look.[1] http://zsh.sourceforge.net/Intro/intro_3.html
I have tried two setups, and both fail the sense that:
ImportError: No module named pandas
is returned.dvc run -o test 'which python > test'
outputs/usr/local/bin/python
in thetest
file, where it should point topython
in the virtualenv.Setup 1
Setup 2
Yes, Python was installed by Homebrew. (FYI: the Python interpreter that comes with the latest version of macOS (Mojave, version 10.14.6) is 2.7.10 and is 4.5 years old. I figure most people using Python on macOS will have shadowed this outdated version with a more recent one.)
@shcheklein and @efiop asked me to share the output of a few commands on the Discord channels and perhaps it helps if I share it here as well.
I wish I could help out more, but my knowledge of Python environments and DVC internals is very limited. However, let me know if I can help you out with further information and I’m happy to provide it.
@shcheklein in their case, is DVC installed in the “parent” Python environment, or in a separate virtualenv? The problem might lie in something that has to do with the parent/child relationship.
Also, did they use Homebrew to install Python? Brew is another common factor here, and more likely to cause problems than Zsh, since Brew does its own layer of symlinking.
My admittedly convoluted setup: