【问题标题】:How do I get virtualenvwrapper and cygwin to co-operate?如何让 virtualenvwrapper 和 cygwin 合作?
【发布时间】:2010-02-01 00:06:48
【问题描述】:

我正在尝试让virtualenv[wrapper] 通过 Cygwin 在我的 Windows 机器上工作。安装成功,连同easy_install,根据这些指示:http://www.doughellmann.com/docs/virtualenvwrapper/

当我使用mkvirtualenv [name_of_vir_env] 时出现问题。我得到以下输出:

$ mkvirtualenv testenv
New python executable in testenv\Scripts\python.exe
Installing setuptools.................done.
bash: D:\.virtualenvs/testenv/bin/postactivate: No such file or directory
chmod: getting attributes of `D:\\.virtualenvs/testenv/bin/postactivate': No such file or directory
bash: D:\.virtualenvs/testenv/bin/predeactivate: No such file or directory
chmod: getting attributes of `D:\\.virtualenvs/testenv/bin/predeactivate': No such file or directory
bash: D:\.virtualenvs/testenv/bin/postdeactivate: No such file or directory
chmod: getting attributes of `D:\\.virtualenvs/testenv/bin/postdeactivate': No such file or directory
ERROR: Environment 'D:\.virtualenvs/testenv' does not contain an activate script.

testenv 目录中,没有bin 子目录,而只有LibScriptsScripts 包含 activate.bat 应该用于激活此特定环境,但是如果我尝试通过 bash 运行它,我会收到错误:

$ ./activate.bat
./activate.bat: line 1: @echo: command not found
./activate.bat: line 4: syntax error near unexpected token `('
./activate.bat: line 4: `if not defined PROMPT ('

我可以退出bash 并调用activate.bat,这将更改为所需的环境。但是不在bash 中,我不能使用workon 命令或virtualenvwrapper_bashrc 中的任何其他命令。

我怎样才能让两者协同工作,即留在bash,以便我可以使用virtualenvwrapper_bashrc中的命令?

【问题讨论】:

    标签: python cygwin virtualenv


    【解决方案1】:

    我没有使用 virtualenvwrapper 的经验,但确实经常使用 virtualenv。我不认为 activate.bat 打算在 cygwin 下运行,它在常规 Windows shell 中运行时可以工作。我认为如果您使用的是 cygwin,您可能想要使用更像 bin/activate(类 unix 操作系统的版本)之类的东西。

    bash 中的 cygwin 环境可能与 activate.bat 期望运行的标准环境大不相同,因此找到一个可以与 bash 一起使用的激活脚本(也许从 unix 版本中找到一个副本)可能会让你到达你可以在 bash 中运行你的 virtualenv。

    【讨论】:

    • 不得不使用 . venv/脚本/激活
    【解决方案2】:

    【讨论】:

    • 遗憾的是它使用了 cygwin 自己的 Python,截至 2012 年 9 月 15 日,它最高只有 Python 2.6.8。
    【解决方案3】:

    这是为我做的:

    https://bitbucket.org/cliffxuan/virtualenvwrapper-for-cygwin-windows-python

    vanilla virtualenvwrapper 似乎不支持 Cygwin 环境。

    但是需要注意的是,virtualenv 的Scripts 目录下的可执行脚本只有在您将它们显式传递给python 命令并且不使用~ 或任何其他Cygwin 隐式转换路径时才可执行以/cygdriv/c/... 开头——本机 Windows Python 无法看到这些路径。

    【讨论】:

      【解决方案4】:

      我不知道 virtualenv,但我看到了来自 cygwin 的经典混合路径语法问题:

      你的字符串是:

      D:\.virtualenvs/testenv/bin/predeactivate
      

      但 Cygwin 将反斜杠解释为“。”的转义。角色,生产:

      D:.virtualenvs/testenv/bin/postactivate
      

      在您引用的错误文本中,显然是格式错误的路径。检查您的实际环境变量 - 它可能是 DOS/Windows 路径语法,而内部部分是 cygwin/unix 语法。

      如果是这样,请尝试使用 os.path.join 将这两个部分拼接在一起,看看是否能得到一致的语法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-25
        • 1970-01-01
        • 2018-01-31
        • 1970-01-01
        相关资源
        最近更新 更多