5 ms·
My flow that I have settled on as being the most predicable (even though PDM allows for installing to a local virtualenv as well) is (with pyenv): mkdir newp
by Zizizizz 4y ago
My flow that I have settled on as being the most predicable (even though PDM allows for installing to a local virtualenv as well) is (with pyenv):
mkdir newproject && cd newproject
echo 3.11.0 > .python-version # (If different python version)
python -m venv .venv # Make the venv
And I have this in my `.zshrc` so whenever I `cd` to that directory, it auto-activates the virtual environment. Having the local directory in the project also makes it really easy for my editor (neovim or VS Code) to pick up
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
# Custom key-bindings
python_venv() {
MYVENV=./.venv
# when you cd into a folder that contains $MYVENV
[[ -d $MYVENV ]] && [[ ! $VIRTUAL_ENV ]] && source $MYVENV/bin/activate
# when you cd into a folder that doesn't
[[ ! -d $MYVENV ]] && [[ $VIRTUAL_ENV ]] && deactivate
}
autoload -U add-zsh-hook
add-zsh-hook chpwd python_venv
python_venv
- truculent 4y agoDo you have any issues with many virtualenvs/packages taking up a lot of disk space? For instance, numerical packages (scipy, torch, etc) can add up if they’re duplicated across many projects, and, as I understand it, virtualenv doesn’t do any caching/symlinking.
- Zizizizz 4y agoI don't work on too many projects at a time and tend to archive and remove the virtualenv when I finish working on something for the foreseeable future. I can see why that would be a problem for some though.
- fbdab103 4y ago>...virtualenv doesn’t do any caching/symlinking. Well, one of us is incorrect then. I had been thinking for years that one of the key benefits was that virtualenv would not do a blind copy of files (except on Windows...sigh). The `venv` command even has a `symlinks` vs `copies` option. `python3 -m venv --help`
- truculent 4y agoSorry, this was my mistake - I ought to have said that pip doesn't cache/symlink installed packages (unless I am wrong about this also!). You are, of course, correct that the python binaries are symlinked.
- giancarlostoro 4y agoI really just run the same python module as you directly, its the most predictable across platforms.
- dmurray 4y ago> # when you cd into a folder that doesn't Is this the behaviour you want, for subdirectories of your project root? Other tools (e.g. git, but also version managers like asdf) tend to look in the current directory, and then recursively try the parent directory to find what the current configuration should be.
- Zizizizz 4y agoI don't really know the last time I cd'd to a subdirectory in a project, I typically just use fzf or nnn for any of those interactions. Not a bad idea though, thanks!
- Fatnino 4y agoWhy don't you run `python3.11 -m venv .venv`