Python ImportError-这里有什么问题?

Python ImportError-这里有什么问题?

问题描述:

我是编程和Python的新手。我正在关注学习Python困难之路一书。
作为练习25的一部分,我写了一个脚本:

I am new to programming and Python. I am following the Learn Python the Hard Way book. As a part of exercise 25, I wrote a script:

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)`

我把它从gedit中保存为

I saved this from gedit as


ex25.py

ex25.py

路径


C:\ Users \ Brandon \Experiment\Python_ex

C:\Users\Brandon\Experiment\Python_ex

我正在运行64位Windows 7。

I am running 64-bit Windows 7.

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

When I go to import ex25 from python.exe I get:

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

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

Under Computer\Properties\Advanced\Environment Variables I added the System Variable:


PYTHONPATH

PYTHONPATH

C:\Python27

C:\Python27

这没有帮助。
我做错了什么?

That didn't help. What am I doing wrong?

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

C:\Users\Brandon\Experiment\Python_ex is not on your system path, thus python is not aware where your ex25 module can be found

import sys
sys.path.append(r'C:\Users\Brandon\Experiment\Python_ex')