0

我最近在 Kubuntu 12.04 ( iPython, matplotlib, numpy, ipython-notebook, ipython-qtconsole, python-scipy) 上安装了几个 Python 包。现在,当我尝试从命令行 ( ./script.py) 运行 python 脚本时,我被扔进了 python 解释器。

例子:

user@machine:~/$ ./script.py 

Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> 

为什么会这样?

我能做些什么来阻止这个?

除了删除 iPython 还有其他选择吗?

编辑:我应该提到脚本是一个 python 模块。我不知道这是否与它有关。我能够运行一个简单的hello world脚本就好了。

@亚当米哈尔辛: #!/usr/bin/python

编辑 2:看起来这与 iPython 无关。我删除了 iPython,但我仍然遇到这个问题。这是文件的内容。(这发生在我的大多数 Python 文件中)

#!/usr/bin/python

# Import libraries
import sys
import subprocess

def createCommand(project):
    # Create the basic command
    command = "git clone " + project

    subprocess.call(command, shell = True)

    return 0

def helpMenu():

    return 0;

def validateInput(user_input):
    # validity key
    valid = 0

    if (len(user_input) < 3):
        help()
        return 1

    if (user_input[1] == '-cl'):
        if (len(user_input) == 3):
            valid = 1
            return 0

    if (valid == 0):
        help()
        return 1

def main(user_input):
    # Validate inputs
    failure = validateInput(user_input)

    # Return if there was a failure    
    if (failure == 1):
        return 1;

    # Create the git commands        
    failure = createCommand(user_input[2])

    # Return if there was a failure    
    if (failure == 1):
        return 1;

    return 0;

if (__name__ == '__main__'):
    main(sys.argv)

编辑3:误报!

这很尴尬。help()事实证明,我知道我的函数会遇到命名空间问题。我将其更改为helpMenu()但忘记更改它的名称。

我很抱歉浪费了帖子。:(

4

1 回答 1

0

这很尴尬。事实证明,我知道我的 help() 函数会遇到命名空间问题。我将其更改为 helpMenu() 但忘记更改它的调用位置。

我很抱歉浪费了帖子。:(

于 2012-04-30T13:17:39.537 回答