Skip to content

Python virtual env is in wrong order in PATH for nested configs #4515

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

Open
jdx opened this issue Feb 24, 2025 · 3 comments
Open

Python virtual env is in wrong order in PATH for nested configs #4515

jdx opened this issue Feb 24, 2025 · 3 comments

Comments

@jdx
Copy link
Owner

jdx commented Feb 24, 2025

Discussed in #4510

Originally posted by fredriv February 24, 2025
We're migrating to mise + uv to replace asdf + direnv.

We have a repository where various subdirectories have their own Python virtual environment. However, when setting this up in mise, the virtual environments end up in the wrong order in PATH. This seems similar to the issue reported in #4361?

In ~/tmp/base/mise.toml:

[env]
_.python.venv = { path = ".venv", create = true }

[tools]
python = "3.12.9"
uv = "0.5.29"

In ~/tmp/base/override/mise.toml:

[env]
_.python.venv = { path = ".venv", create = true }

[tools]
python = "3.13.2"
uv = "0.5.29"

When entering ~/tmp/base/override I would expect to get Python 3.13 but I'm still getting the version specified in the base config:

tmp/base/override
❯ python --version
Python 3.12.9

This is the start of the PATH variable:

tmp/base/override
❯ echo $PATH
/Users/fredriv/tmp/base/.venv/bin:/Users/fredriv/tmp/base/override/.venv/bin:...

I would expect the two entries to be in the reverse order, with my current directory's virtual environment at the start.

Output of mise doctor:

❯ mise doctor
version: 2025.2.7 macos-arm64 (2025-02-19)
activated: yes
shims_on_path: no

build_info:
  Target: aarch64-apple-darwin
  Features: DEFAULT, NATIVE_TLS, SELF_UPDATE
  Built: Wed, 19 Feb 2025 20:57:49 +0000
  Rust Version: rustc 1.84.1 (e71f9a9a9 2025-01-27) (Homebrew)
  Profile: release

shell:
  /bin/zsh
  zsh 5.9 (arm64-apple-darwin24.0)

dirs:
  cache: ~/Library/Caches/mise
  config: ~/.config/mise
  data: ~/.local/share/mise
  shims: ~/.local/share/mise/shims
  state: ~/.local/state/mise

config_files:
  ~/.tool-versions
  ~/.config/mise/config.toml
  ~/tmp/base/mise.toml
  ~/tmp/base/override/mise.toml

ignored_config_files: (none)

backends:
  aqua
  asdf
  cargo
  core
  dotnet
  gem
  go
  npm
  pipx
  spm
  ubi
  vfox

plugins:
  poetry    https://github.com/mise-plugins/mise-poetry.git#80d807b
  postgres  https://github.com/mise-plugins/mise-postgres.git#acbbc49

toolset:
  aqua:astral-sh/[email protected]
  aqua:hashicorp/[email protected]
  core:[email protected]

path:
  ~/tmp/base/.venv/bin
  ~/tmp/base/override/.venv/bin
  ~/.local/share/mise/installs/python/3.13.2/bin
  ~/.local/share/mise/installs/uv/0.5.29/uv-aarch64-apple-darwin
  ~/.local/share/mise/installs/terraform/1.10.4
  /opt/homebrew/share/google-cloud-sdk/bin
  /opt/homebrew/bin
  /opt/homebrew/sbin
  /usr/local/bin
  /System/Cryptexes/App/usr/bin
  /usr/bin
  /bin
  /usr/sbin
  /sbin
  /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin
  /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin
  /var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
  /Library/Apple/usr/bin
  ~/.local/bin
  ~/.local/bin
  ~/.klipy/bin

env_vars:
  MISE_SHELL=zsh

settings:
  experimental  true ~/.config/mise/config.toml

No problems found
```</div>
@jdx jdx marked this as a duplicate of #4516 Feb 25, 2025
@laluka
Copy link

laluka commented Feb 28, 2025

I've had a similare and probably related issue ✋

First a gentle intro with the venv path order bug :

» tail -n 3 ~/.config/mise/config.toml            
[env._.python.venv]
path = ".venv"
create = true
--------------------------------------------------------------
» which python                                    
/home/lalu/.venv/bin/python
--------------------------------------------------------------
# Commented out the mise/venv config
» rm /home/lalu/.venv
--------------------------------------------------------------
» which python                                    
/home/lalu/.local/share/mise/installs/python/3.12.8/bin/python

Another one demoing a local mise use not taking the lead on the global config while suffering from the global python venv config

~/Downloads » ls                               
-----------------------------------------------
~/Downloads » which python                     
/home/lalu/.venv/bin/python
-----------------------------------------------
~/Downloads » python --version                 
Python 3.12.8
-----------------------------------------------
~/Downloads » mise use [email protected]           
mise ~/Downloads/mise.toml tools: [email protected]
-----------------------------------------------
~/Downloads » which python                     
/home/lalu/.venv/bin/python
-----------------------------------------------
~/Downloads » python --version                 
Python 3.12.8

# Fixing by removin the mise/venv config, then everything comes back to normal

~/Downloads » mise use [email protected]                          
--------------------------------------------------------------
~/Downloads » which python                                    
/home/lalu/.local/share/mise/installs/python/3.12.8/bin/python
--------------------------------------------------------------
~/Downloads » mise use [email protected]                          
mise ~/Downloads/mise.toml tools: [email protected]
--------------------------------------------------------------
~/Downloads » which python                                    
/home/lalu/.local/share/mise/installs/python/3.8.20/bin/python
--------------------------------------------------------------
~/Downloads » python --version                                
Python 3.8.20

This might also be related to an alias I use that changed a flag in a wrong or overly-wide way?

lbt-pv='f(){ mise use "python@$1" ; mise config set env._.python.venv.path .venv ; mise config set --type bool env._.python.venv.create true ; mise exec -- which python ; mise exec -- python --version ;  unset -f f; }; f'

I know my investigation hasen't

@halms
Copy link

halms commented Mar 4, 2025

Does history repeat itself?
There was something similar a year ago: #1751 / #1724 / #1771

@joshuataylor
Copy link
Contributor

Also, just found you can't have virtualenv path defined in both env AND tools..:

[settings]
python_compile = true
experimental = true

[env]
_.python.venv = { path = ".venv2", create = true }

[tools]
python = { version = '3.13.2', virtualenv = '.venv2' }

This doesn't seem to unset PATH properly when using mise activate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants