如何让virtualenvwrapper和cygwin协作?
我正在尝试在我的Windows电脑上通过Cygwin使用virtualenv[wrapper]
。根据这些说明,安装是成功的,连同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
里的命令?
4 个回答
这个方法对我有效:
https://bitbucket.org/cliffxuan/virtualenvwrapper-for-cygwin-windows-python
普通的 virtualenvwrapper
似乎不支持 Cygwin 环境。
不过有一点需要注意的是,在虚拟环境的 Scripts
目录下的可执行脚本,只有在你明确用 python
命令来运行它们时才能执行。如果你使用 ~
或者其他 Cygwin 会自动转换的路径,比如以 /cygdriv/c/...
开头的路径,原生的 Windows Python 是看不到这些路径的。
这篇帖子看起来很有希望,
你可以在这里查看:http://atbrox.com/2009/09/21/how-to-get-pipvirtualenvfabric-working-on-cygwin/
-- Quentin
我对virtualenvwrapper不太熟悉,但我经常使用virtualenv。我觉得activate.bat这个文件不适合在cygwin下运行,它在普通的Windows命令行中可以正常工作。如果你在使用cygwin,可能更适合用类似bin/activate这样的文件(这是为类Unix操作系统准备的版本)。
在bash的cygwin环境中,可能和activate.bat所期待的标准环境差别很大,所以找到一个适合bash的activate脚本(也许可以找一个Unix版本的拷贝)可能会让你在bash中顺利运行你的virtualenv。