Imports working with raw file, but not in IDLE

后端 未结 2 1110
南方客
南方客 2021-01-23 21:15

UPDATE 10 Secs later
Fixed properly now, and thanks to JF and Gauden.

UPDATE
I have found a temporary fix by saving the IDLE fi

2条回答
  •  我在风中等你
    2021-01-23 22:09

    EDIT The answer to the above question proved to be fairly simple, but I am editing this answer as a possible troubleshooting checklist for future reference, and as a checklist for others who may need to prepare questions of this nature in the future.

    CLUE 1: What is the path to the module you are importing?

    >>> import wikipedia
    >>> print wikipedia.__file__
    

    This will give you the path to the compiled module, and is one clue.

    CLUE 2: What is the path to the Python executable?

    (See also this question).

    >>> import sys
    >>> print sys.executable
    

    Try this in the shell and in an IDLE script. If the two results are different, then you are using two Python interpreters and only one of them has a path that points to the wikipedia module.

    CLUE 3: What is the sys.path?

    Also repeat this in both shell and as a script in IDLE.

    >>> print '\n'.join( sys.path )
    

    (You may be able to use sys.path.append("d:/irectory/folder/is/in") to add that location to the sys.path. This should add that directory to the list of places Python looks for modules.)

    CLUE 4: What is the PYTHONPATH and does it differ in the two environments?

    (See also this answer).

    Finally repeat this in both shell and as a script in IDLE.

    >>> import os
    >>> print '\n'.join( os.environ['PATH'].split(os.pathsep) )
    

    Again note the two results (from shell and from IDLE) and see if there is difference in the PYTHONPATH in the two environments.

    If all these tests prove inconclusive, I would add as much of this information as you can to your question as it would help give you specific further leads. Also add what OS you are using and any tracebacks that you get.

提交回复
热议问题