【问题标题】:Trouble running scripts installed by virtualenv-commands on Windows在 Windows 上运行由 virtualenv-commands 安装的脚本时遇到问题
【发布时间】:2011-08-20 10:24:07
【问题描述】:

在 Windows 上运行已安装的脚本时出现问题,如下所示

C:\Users\Piotr>where python
C:\program files\Python\2.7\python.exe
C:\Users\Piotr>python c:\program files\Python\2.7\scripts\ve init
[Errno 2] No such file or directory
Is "ve-init" executable in the current path?
C:\Users\Piotr>

我尝试按照How to run installed python script? 问题中的建议解决此问题,但没有成功:

C:\Users\Piotr>assoc .py
.py=Python.File
C:\Users\Piotr>ftype Python.File
Python.File=c:\program files\Python\2.7\python.exe "%1" %*
C:\Users\Piotr>dir /b "c:\program files\python\2.7\scripts"
easy_install-2.7-script.py
easy_install-2.7.exe
easy_install-script.py
easy_install.exe
pip-2.7-script.py
pip-2.7.exe
pip-script.py
pip.exe
ve-clone
ve-extend
ve-init.py
ve.py
virtualenv-script.py
virtualenv.exe    
C:\Users\Piotr>python c:\program files\Python\2.7\Scripts\ve.py init
[Errno 2] No such file or directory
Is "ve-init" executable in the current path?

我认为这种情况下的特别之处在于ve 脚本通过操作系统(os.execvp())运行命令脚本(ve-init、ve-clone 等)。

【问题讨论】:

  • 我阅读了您链接到的帖子。在我看来你没有按照它的指示行事?您需要 ve-init 才能被 Windows 运行。如果不是ve-init.py 和正确的文件关联,windows 怎么知道如何运行它?
  • 我遵循了这些说明,但不想让我的问题太长,所以我跳过了结果。现在我将它们添加到我的问题中。
  • 在我看来,当您需要运行ve-init.py 时,您仍然在尝试运行ve-init——该列表中没有ve-init。即使有了关联,您仍然需要完整的文件名吗?
  • 对,这就是ve 脚本的作用(command = 've-%s' % command 然后return os.execvp(command, (command, ) + args)。我将不得不修改这些脚本,如果有其他方法可以得到,我想避免这样做它工作。
  • 没有任何方法可以在 Windows 上执行此操作,除非您在 MSYS 中使用 bash 或可以解释文件开头的 hashbang 的东西。否则,您需要文件具有 .py 扩展名或显式调用 python。

标签: python windows exec virtualenv virtualenv-commands


【解决方案1】:

解决方案是将.py 扩展名添加到PATHEXT 环境变量中,这样Python 脚本就可以在不指定扩展名的情况下运行(只要它们在PATH 上)。

尽管如此,这还不足以让 virtualenv-commands 在 Windows 上运行,因为这个包使用了 Windows 上不可用的 Unix 特定工具。

有趣的是,我想创建 virtualenv-commands 背后的想法是通过不使用 shell 脚本使其比 virtualenvwrapper 更具可移植性,但目前的实现似乎只支持 Unix。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 2012-09-19
    • 1970-01-01
    • 2015-01-17
    • 2017-01-15
    • 2013-03-20
    相关资源
    最近更新 更多