无法通过cygwin启动我的烧瓶虚拟环境

Cant start my virtual environment of flask through cygwin

无法通过cygwin启动我的flask虚拟环境:
我的系统:(windows 10)

方法一:

$ env/Scripts/activate

方法二:

$ env/Scripts/activate.bat

方法三:

$ source ./env/Scripts/activate

在我的 cygwin cli 上,但它始终给出以下错误:

-bash: $'\r': command not found
-bash: ./env/Scripts/activate: line 4: syntax error near unexpected token `$'{\r''
'bash: ./env/Scripts/activate: line 4: `deactivate () {

注意: 前两种激活虚拟环境的方法在 VSCode 上运行良好,但在 cygwin 上运行不佳。

我的激活文件:

# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
    # reset old environment variables
    if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
        PATH="${_OLD_VIRTUAL_PATH:-}"
        export PATH
        unset _OLD_VIRTUAL_PATH
    fi
    if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
        PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
        export PYTHONHOME
        unset _OLD_VIRTUAL_PYTHONHOME
    fi

    # This should detect bash and zsh, which have a hash command that must
    # be called to get it to forget past commands.  Without forgetting
    # past commands the $PATH changes we made may not be respected
    if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
        hash -r 2> /dev/null
    fi

    if [ -n "${_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
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="D:\projects\websites\googleHostFlaskApp\env"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH

# 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

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
    _OLD_VIRTUAL_PS1="${PS1:-}"
    PS1="(flask) ${PS1:-}"
    export PS1
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands.  Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
    hash -r 2> /dev/null
fi

正如@Doug 所建议的,将 CR-LF 更改为 LF 确实有效。 错误是由于行尾不同造成的。

Unix 系统(Linux 和 Mac)默认为 LF(换行)字符换行符。
另一方面,Windows 是“特殊的”,默认为 CR/LF(回车 return AND 行饲料)。

如果你和我一样在使用vscode:那么vscode[=11=下面写着CRLF ]

单击此处,您可以将 activate 文件从 CRLF 更改为 LF,这将消除您面临的错误。