如何让 virtualenvwrapper 和 cygwin 合作?
我正在尝试通过 Cygwin 让 virtualenv[wrapper]
在我的 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
子目录,而只有 Lib
和 Scripts
。 Scripts
包含 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 中的命令?
I am trying to get virtualenv[wrapper]
to work on my Windows machine through Cygwin. The install is successful, together with easy_install
, based on these directions: http://www.doughellmann.com/docs/virtualenvwrapper/.
The problem comes in when I use the mkvirtualenv [name_of_vir_env]
. I get the following output:
$ 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.
Inside the testenv
directory, there is no bin
subdirectory, rather only Lib
and Scripts
. Scripts
contains activate.bat
which is supposed to be used to activate this particular environment, however if I try to run this out through bash
I get an error:
$ ./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 ('
I can exit bash
and call activate.bat
and this changes to the desired environment. But then not being in bash
I cannot use the workon
command, or any other in virtualenvwrapper_bashrc
.
How can I get the two to work together, that is, stay in bash
so I can use the commands in virtualenvwrapper_bashrc
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我对 virtualenvwrapper 没有经验,但经常使用 virtualenv。我不认为 activate.bat 旨在在 cygwin 下运行,它在常规 Windows shell 中运行时可以工作。我认为如果您使用 cygwin,您可能想要使用更像 bin/activate (类 unix 操作系统的版本)的东西。
bash 中的 cygwin 环境可能与 activate.bat 期望运行的标准环境有很大不同,因此找到一个可以与 bash 一起使用的激活脚本(也许找到 unix 版本的副本)可能会让您到达可以运行的位置bash 中的 virtualenv。
I'm not experienced with virtualenvwrapper, but do use virtualenv regularly. I don't think the activate.bat is intended to be run under cygwin, it works when run in the regular windows shell. I think if you are using cygwin, you might want to use something more like bin/activate(the version for unix-like OS's).
The cygwin environment within bash could be drastically different from the standard environment activate.bat expects to run in, so finding an activate script that would work with bash(perhaps find a copy from a unix version) would probably get you to where you can run your virtualenv within bash.
这篇文章看起来很有前途
http://atbrox.com/2009/ 09/21/如何获取 pipvirtualenvfabric-working-on-cygwin/
--
昆汀
This post looks promising
http://atbrox.com/2009/09/21/how-to-get-pipvirtualenvfabric-working-on-cygwin/
--
Quentin
这对我来说是这样的:
https://bitbucket.org/cliffxuan/virtualenvwrapper-for -cygwin-windows-python
vanilla
virtualenvwrapper
似乎不支持 Cygwin 环境。但需要注意的是,virtualenv 的 Scripts 目录下的可执行脚本只有在将它们显式传递给 python 命令并且不使用
~< 时才可执行。 /code> 或 Cygwin 隐式转换以
/cygdriv/c/...
开头的路径的任何其他内容 - 本机 Windows Python 无法看到这些路径。This did it for me:
https://bitbucket.org/cliffxuan/virtualenvwrapper-for-cygwin-windows-python
The vanilla
virtualenvwrapper
does not seem to support the Cygwin environment.A caveat however is that executable scripts under the
Scripts
directory of the virtualenv are only executable if you pass them explicitly to thepython
command and don't use~
or anything else that Cygwin implicitly converts a path starting with/cygdriv/c/...
—the native Windows Python cannot see those paths.我不知道 virtualenv,但我看到 cygwin 看起来像一个经典的混合路径语法问题:
你的字符串是:
但是 Cygwin 将反斜杠解释为“.”的转义。字符,产生:
它位于您引用的错误文本中,显然是格式错误的路径。检查你的实际环境变量 - 它可能是 DOS/Windows 路径语法,而内部部分是 cygwin/unix 语法。
如果是这样,请尝试使用 os.path.join 将两个部分拼接在一起,看看是否能获得一致的语法。
I don't know virtualenv, but I'm seeing what looks like a classic mixed path syntax issue from cygwin:
Your string is:
but Cygwin is interpreting the backslash as an escape for the "." character, producing:
which is in the error text you're quoting and is obviously a malformed path. Check your actual environment variable - it's probably in DOS/Windows path syntax, while the internal part is in cygwin/unix syntax.
If so, try using os.path.join to splice the two parts together and see if you get a consistent syntax out of that.