LINUX.ORG.RU

А где находится deactivate?

 


0

0

Есть whisper в virtualenv. Я в bashrc сделал функцию, которая использует whisper. В функции я делаю:

if [[ -d .env ]]; then
    source .env/bin/activate
fi

Далее я вызываю whisper. Он отрабатывает и мне надо сделать deactivate. Скрипт пишет, что deactivate command not found. Это функция virtualenv’a? Как ее вызвать? find’ом ее не смог найти в директории .env

★★★
Ответ на: комментарий от anonymous

Да неужели?

┌─[user@debian-home]─[main]─[ /home/user/media/source_code/whisper ]
└──╼ source .env/bin/activate
(.env) ┌─[user@debian-home]─[main]─[ /home/user/media/source_code/whisper ]
└──╼ source deactivate
bash: deactivate: No such file or directory
(.env) ┌[x]─[user@debian-home]─[main]─[ /home/user/media/source_code/whisper ]
└──╼
serg002 ★★★
() автор топика

Сама команда deactivate при этом работает

В доках пишут

You can deactivate a virtual environment by typing deactivate in your shell.The exact mechanism is platform-specific and is an internal implementation detail (typically, a script or shell function will be used).

anonymous
()
Ответ на: комментарий от anonymous

Да, в .env/bin/activate

deactivate () {
    unset -f pydoc >/dev/null 2>&1 || true

    # reset old environment variables
    # ! [ -z ${VAR+_} ] returns true if VAR is declared at all
    if ! [ -z "${_OLD_VIRTUAL_PATH:+_}" ] ; then
        PATH="$_OLD_VIRTUAL_PATH"
        export PATH
        unset _OLD_VIRTUAL_PATH
    fi
    if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
        PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
        export PYTHONHOME
        unset _OLD_VIRTUAL_PYTHONHOME
    fi

    # The hash command must be called to get it to forget past
    # commands. Without forgetting past commands the $PATH changes
    # we made may not be respected
    hash -r 2>/dev/null

    if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
        PS1="$_OLD_VIRTUAL_PS1"
        export PS1
        unset _OLD_VIRTUAL_PS1
    fi

    unset VIRTUAL_ENV
    if [ ! "${1-}" = "nondestructive" ] ; then
    # Self destruct!
        unset -f deactivate
    fi
}

Как бы ее правильно вызвать из функции в bashrc?

serg002 ★★★
() автор топика
Ответ на: комментарий от serg002

Да неужели?

Там в первом же предложении ответа

Usually, activating a virtualenv gives you a shell function named: deactivate

Зачем ты пытаешься делать source для функции шелла?

theNamelessOne ★★★★★
()
Последнее исправление: theNamelessOne (всего исправлений: 1)
Ответ на: комментарий от masa

PYTHONHOME PYTHONPATH это пути к библиотекам, вся суть использования венв в них. Конечно можно вызвать правильную версию питона с правильными путяит к библиотекам, это скрипт activate и делает

anonymous
()
Ответ на: комментарий от anonymous

Чел, никакие PYTHONPATH и HOME в активейте не ставятся, это переменные для пользователя чтобы переопределять стандартное поведение.

Путь к системным библиотекам зашит в логике работы самого питона, костылик в виде активейта только добавляет тебе в PATH путь до бинарника, чтобы ты не дрочился с полными путями и рисует название венва в баше.

А теперь извинись

masa
()
Ответ на: комментарий от masa

Извинити

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
    _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
    unset PYTHONHOME
fi

Он только unset PYTHONHOME делает.

И я все равно немогу понять, как подтягиваются из .venv/lib64/python3.xx/site-packages, которые устанавливаются через pip в виртуалэнве

anonymous
()
Ответ на: комментарий от anonymous

Ладно, разобрался вроде

https://docs.python.org/3/library/site.html

It starts by constructing up to four directories from a head and a tail part. For the head part, it uses sys.prefix and sys.exec_prefix; empty heads are skipped. For the tail part, it uses the empty string and then lib/site-packages (on Windows) or lib/pythonX.Y[t]/site-packages (on Unix and macOS)

anonymous
()