0

最近、Kubuntu 12.04 ( iPythonmatplotlibnumpyipython-notebook、 )ipython-qtconsoleにいくつかの Python パッケージをインストールしましpython-scipyた。コマンドラインから python スクリプトを実行しようとすると ( ./script.py)、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 に答える