Open Konfekt opened 2 weeks ago
@Konfekt this plugin doesn't support raw venv environments.
venv is fine for basic usage, but virtualenv is more advanced in terms of features. One super useful example is hooks, which are not available in venv. Current virtualenv versions can use venv under the hood though for environment creation. I recommend using virtualenv + virtualenvwrapper.
However a limited support can be added for venv if it's easy. Please provide exact steps how to reproduce you problem.
For example, I create a virtual environment in the current work dir by virtualenv .
.
Now I'd like to activate it by :VirtualEnvActivate
but of course I am always thrown back to missing a central user dir
vim-virtualenv: '/home/konfekt/.virtualenvs' is not a directory
Error detected while processing function virtualenv#activate:
line 36:
E121: Undefined variable: s:state
E116: Invalid arguments for function has_key(s:state, 'virtualenv_directory') && (l
:target ==# s:state['virtualenv_directory'])
and then
Error detected while processing function virtualenv#activate:
line 36:
E121: Undefined variable: s:state
E116: Invalid arguments for function has_key(s:state, 'virtualenv_directory') && (l
:target ==# s:state['virtualenv_directory'])
I cannot reproduce you problem. The following steps work correctly for me:
$ ls test
ls: cannot access 'test': No such file or directory
$ mkdir test
$ virtualenv test
pip-24.3.1-py3-none-any.whl already present in /home/coacher/.local/share/virtualenv/wheel/3.12/embed/3/pip.json
created virtual environment CPython3.12.7.final.0-64 in 5186ms
creator CPython3Posix(dest=/home/coacher/Work/test, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(extra_search_dir=/usr/share/python-wheels,download=True, pip=bundle, via=copy, app_data_dir=/home/coacher/.local/share/virtualenv)
added seed packages: pip==24.3.1
activators BashActivator,PythonActivator
$ cd test/
$ vim -u ~/.vimrc.minimal -c ':VirtualEnvActivate | echo virtualenv#state()'
The last command shows the correct virtualenv name and paths meaning it's activated successfully.
Here's the minimal vimrc, please try with it to prevent interference from other plugins:
set nocompatible
call plug#begin('~/.vim/plugins/')
Plug 'Coacher/vim-virtualenv'
call plug#end()
filetype on
Note that this issue refers to venv
, a subset of virtualenv
, that is python -m venv test
and not virtualenv test
. Could you try with venv
instead?
Note that this issue refers to
venv
, a subset ofvirtualenv
, that ispython -m venv test
and notvirtualenv test
. Could you try withvenv
instead?
I'm following your original comment here: https://github.com/Coacher/vim-virtualenv/issues/2#issuecomment-2438005539
Namely For example, I create a virtual environment in the current work dir by virtualenv ..
What are the correct steps to reproduce then?
Following the steps above
$ ls test
ls: cannot access 'test': No such file or directory
$ mkdir test
$ virtualenv test
pip-24.3.1-py3-none-any.whl already present in /home/coacher/.local/share/virtualenv/wheel/3.12/embed/3/pip.json
created virtual environment CPython3.12.7.final.0-64 in 5186ms
creator CPython3Posix(dest=/home/coacher/Work/test, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(extra_search_dir=/usr/share/python-wheels,download=True, pip=bundle, via=copy, app_data_dir=/home/coacher/.local/share/virtualenv)
added seed packages: pip==24.3.1
activators BashActivator,PythonActivator
$ cd test/
$ vim -u ~/.vimrc.minimal -c ':VirtualEnvActivate | echo virtualenv#state()'
with ~/.vimrc.minimal
reading
set nocompatible
let &rtp = '~/.vim/plugged/vim-virtualenv/' . ',' . &rtp
filetype plugin indent on
syntax on
I get
vim-virtualenv: '/home/konfekt/.virtualenvs' is not a directory
Error detected while processing command line..function virtualenv#activate:
line 36:
E121: Undefined variable: s:state
E116: Invalid arguments for function has_key(s:state, 'virtualenv_directory') && (l
:target ==# s:state['virtualenv_directory'])
Error detected while processing command line..function virtualenv#state:
line 8:
E121: Undefined variable: s:state
E116: Invalid arguments for function keys(s:state)
According to the official docs venv is a subset of virtualenv.
I have a venv inside a folder that can be enabled with
. venv/bin/activate
. Reading the docs it seems that virtualenv puts these into a single folder per user. How to replicate the venv behavior instead?