Note: Was a personal project, but I left oh-my-zsh for vanilla, and rye for mise. Please fork and become new maintainer.
╭─ ~/containers ────────────────────────────────────────────────────────────╮
╰─ at 12:33:24 PM ─╯
❯ which python; python -V
/usr/bin/python
Python 3.12.3❯ cd djtoolbar
╭─ ~/containers/djtoolbar on main ?13 ──────── django ╱ 3.12.2 ─╮
╰─ at 11:43:54 AM ─╯
❯ which python; python -V
/home/avery/containers/djtoolbar/.venv/bin/python
Python 3.12.2❯ cd ..
╭─ ~/containers ────────────────────────────────────────────────────────────╮
╰─ at 12:33:24 PM ─╯
❯ which python; python -V
/usr/bin/python
Python 3.12.3Recent discussion on Hacker News
rye plugin, inspired by poetry plugin oh-my-zsh has been entirely rewritten, and renamed rye-venv
- Configures your python development environment automatically when you enter a folder bootstrapped with
rye - Plays nice with
pythonplugin (poetryplugin has not been tested) - Minimal and effective
Configuration: there's a virtualenv plugin and a python plugin also bundled with omz
I recommend only using the python plugin and not the virtualenv plugin (they are likely to conflict): python plugin code Plus, the virtualenv plugin is virtuallyuseless. see: virtualenv plugin code
Also, if you use rye-venv and python plugins together, it would be best to load
python after rye-venv in your array, and disable PYTHON_AUTO_VRUN in .zshrc (set to 0). Only one plugin should automatically enable venv. rye-venv has no option to disable this functionality.
The original source of inspiration poetry-envsource
[{ "paraphrase": ["poetry-env", "README.md"] }]This plugin automatically changes rye environment when you enter a rye project directory. It looks for pyproject.toml file to determine if its a rye environment. If it fings pyproject.toml, and a venv is defined by rye, it'll try and source the activate file, enabling the virtualenv automatically. When you leave the folder, it will deactivate it.
Note: rye also uses venv and pyenv-like file .python-version, so if you primarily use rye, I recommend removing those plugins from your .zshrc array, as they'll likely conflict.
The python omz plugin could still useful, but I recommend running it after rye-venv plugin, and disabling PYTHON_AUTO_VRUN (set to 0) Oh-my-ZSH Python plugin info https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/python
At some point I will have to deconflict this plugin with poetry, but since poetry doesn't manage Python versions, I am not sure why someone would use it instead of rye.
Official rye installation instructions
Homebrew (Mac and linux)
Mac Ports (MacOS)
Scoop (Windows)
Winget (Windows)
zsh shell capable of:
add-zsh-hook
autoload
chpwd
Optional (but recommended): oh my zsh
With oh-my-zsh:
tested w/ Arch linux official rye package, global config not sourced
- clone this repo to
$ZSH/custom/plugins/rye-venv
╰─❯ cd $ZSH/custom/plugins
clone --depth 1 https://github.com/averyfreeman/rye-venv.git- add
rye-venvto the plugins array in$HOME/.zshrc.
# $HOME/.zshrc
# note: other plugins included to demonstrate order, but are not necessary
plugins=(asdf ... rye-venv python)- reload
.zshrc
╰─❯ zsh # or open a new shellwithout oh-my-zsh:
this method is untested if someone wants to try it, please send me issue w/ results in theory, it should just need the 3 requirements listed above
- clone repo somewhere
- source plugin file
- reload
.zshrc
╰─❯ cd /your/parent/folder
clone --depth 1 https://github.com/averyfreeman/rye-venv.git
echo 'source /path/to/rye-venv/rye-venv.plugin.zsh' >> $HOME/.zshrc
zsh╰─❯ cd $ZSH/custom/plugins
clone https://github.com/averyfreeman/rye-venv.git
vim $HOME/.zshrc
/pluginsfind uncommented line:
plugins=(asdf ... python)add rye-venv here:
# note: other plugins shown not necessary
# included to demonstrate order
plugins=(asdf ... rye-venv python)save file, exit, and reload .zshrc - one method:
╰─❯ zsh
echo $pluginsshould show:
... rye-venv ...Also, don't forget:
$RYE_HOME:
╰─❯ env | grep RYE
RYE_HOME=/home/$USER/.rye