3

I use Cmder on windows 10 with Python 3.5 and virtualenv on my laptop and work computer just fine.

Now I have a new computer running Windows 10, Python 3.5, virtualenv 15.0 and I am able to initialize a python virtual environment with:

virtualenv env

and I get the virtualenv directories but when I run:

env/Scripts/activate

Nothing happens. No error message and worst of all nothing to signify that the environment was activated or not (i.e. the string "(env)" does not pop up in the terminal next to the path).

The odd thing is that I can activate a venv when using plain old cmd and the "(env)" shows up in the terminal. Just not when run in Cmder. Another oddity (which I don't think is related but may be) is that once I can get a virtualenv running in regular cmd, it says the "deactivate" keyword is not recognized when I try to shut it off.

I found this post (below) on StackOverflow which is similar but not all that useful as it doesn't actually have an answer and is more about PowerShell.

https://stackoverflow.com/questions/31769863/cant-activate-python-venv-in-windows-10

Any thoughts?

Thank you.

3

Note this answer is outdated and no longer required as cmder supports conda/venv now. Update your cmder install if it's not working for you.

Original (outdated) answer

I had a similar issue with a conda env (and it appears to be the same for vanilla virtualenv). Cmder forces its own prompt and ignores the PROMPT env var, you need to add a file called [cmder dir]\config[something].lua with the following content:

 -- Code based on https://github.com/cmderdev/cmder/issues/1056
 -- with modifications to make it actually work (https://github.com/cmderdev/cmder/issues/1056#issuecomment-237403714)
---
 -- Find out current conda/virtual envs
 -- @return {false|conda/virtual env name}
---

local clink_path_lua_file = clink.get_env('CMDER_ROOT')..'\\vendor\\clink-completions\\modules\\path.lua'
dofile(clink_path_lua_file)

function get_virtual_env(env_var)
    env_path = clink.get_env(env_var)
    if env_path then
        basen = exports.basename(env_path)
        return basen
    end
    return false
end

---
 -- add conda env name 
---
function conda_prompt_filter()
    -- add in conda env name
    local conda_env = get_virtual_env('CONDA_DEFAULT_ENV')
    if conda_env then
        clink.prompt.value = string.gsub(clink.prompt.value, "λ", "["..conda_env.."] λ")
    end
end

---
 -- add virtual env name 
---
function venv_prompt_filter()
    -- add in virtual env name
    local venv = get_virtual_env('VIRTUAL_ENV')
    if venv then
        clink.prompt.value = string.gsub(clink.prompt.value, "λ", "["..venv.."] λ")
    end
end

clink.prompt.register_filter(conda_prompt_filter, 20)
clink.prompt.register_filter(venv_prompt_filter, 20)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.