MichaelAquilina / zsh-autoswitch-virtualenv

🐍 ZSH plugin to automatically switch python virtualenvs (including pipenv and poetry) as you move between directories
GNU General Public License v3.0
507 stars 80 forks source link

mkvenv: Random suffix generator broken when 'python' is not in $PATH #171

Closed moha-gh closed 2 years ago

moha-gh commented 2 years ago

Issue Details

KDE neon (basically Ubuntu LTS + bleeding edge KDE) apparently doesn't have a python in $PATH by default - you'll need to explicitly call either python2 or python3. This breaks the generation of the random virtualenv suffix introduced with #166. I get a command not found error when calling mkvenv and end up with a virtualenv without a suffix. Everything apart from that works fine (i.e. the venv automatically picks Python3, even though it is not in $PATH).

Since that seems to be the only place in the plugin that expects a python, I'd be great if there could be some check to warn the user if it isn't available. Or possibly use a different method (mktemp -u XXXX comes to mind, but I have no idea whether that would be available on all supported platforms :grey_question: )

Operating System (uname -a)

Linux 5.13.0-35-generic #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

zsh version (zsh --version)

zsh 5.8 (x86_64-ubuntu-linux-gnu)

autoswitch-virtualenv version

3.5.0

How is zsh-autoswitch-virtualenv installed?

Steps to reproduce the issue

cd /tmp
mkdir foo
cd foo
mkvenv
Command 'python' not found, did you mean:
  command 'python3' from deb python3
  command 'python' from deb python-is-python3
Creating foo- virtualenv
[...]
Switching virtualenv: foo- [🐍Python 3.8.10]

gist link to your zshrc

n/a

MichaelAquilina commented 2 years ago

Python not being in your path is an issue though 🤔 Maybe we can make this more explicit in the README but we would expect a python binary being available in your path considering this is a plugin related to python virtualenvs

We could also warn the user that they need to do this if we detect this issue as you suggested

moha-gh commented 2 years ago

Python not being in your path is an issue though thinking Maybe we can make this more explicit in the README but we would expect a python binary being available in your path considering this is a plugin related to python virtualenvs

A reasonable assumption, yes. Since I haven't encountered any other issue with this setup so far (as mentioned, the venv is working fine - same goes for tools like pip or development in VS Code) I still wanted to bring it up :) It'd be happy to file a PR that extends the documentation accordingly.

MichaelAquilina commented 2 years ago

Go for it @moha-gh :)

moha-gh commented 2 years ago

The new check added with #172 works as expected for me. To make python available in $PATH I've installed the python-is-python3 package via apt install.