Python ImportError-这里有什么问题?

Bra*_*ter 0 python import module importerror

我是编程和Python的新手.我正在关注Learn Python the Hard Way一书.作为练习25的一部分,我写了一个脚本:

def break_words(stuff):   
    """This function will break up words for us."""   
    words = stuff.split(' ')    
    return words        

def sort_words(words):    
    """Sorts the words."""    
    return sorted(words)        

def print_first_word(words):    
    """Prints the first words after popping it off."""    
    word = words.pop(0)    
    print word

def print_last_word(words):    
    """Prints the last word after popping it off."""    
    word = words.pop(-1)    
    print word    

def sort_sentence(sentence):    
    """Takes in a full sentence and returns the sorted words."""    
    words = break_words(sentence)    
    return sort_words(words)       

def print_first_and_last(sentence):    
    """Prints the first and last words of the sentence."""    
    words = break_words(sentence)    
    print_first_word(words)`
Run Code Online (Sandbox Code Playgroud)

我把它从gedit保存为

ex25.py

在路径下

C:\用户\布兰登\实验\ Python_ex

我正在运行64位Windows 7.

当我从python.exe导入ex25时,我得到:

> Traceback (most recent call last):
>  File "(stdin)", line 1, in `<module>`
> ImportError: No module named ex25
Run Code Online (Sandbox Code Playgroud)

在Computer\Properties\Advanced\Environment Variables下,我添加了系统变量:

PYTHONPATH

C:\ Python27

这没有用.我究竟做错了什么?

Nem*_*den 5

C:\Users\Brandon\Experiment\Python_ex不在你的系统路径上,因此python不知道你的ex25模块可以在哪里找到

import sys
sys.path.append(r'C:\Users\Brandon\Experiment\Python_ex')
Run Code Online (Sandbox Code Playgroud)