2014-06-10 1 views
2

비슷한 문제가있는 사이트를 검색해 보았지만 정확한 딜레마가없는 것 같습니다.Python ImportError : 'convert.py'모듈이 없습니다

파이썬 튜토리얼 서적에서는 섭씨 온도를 화씨로 변환하는 프로그램을 작성했습니다. 유휴 셸에서 실행할 때 프로그램이 작동하지만 오류가 반환됩니다. 다음은 프로그램 자체 코드입니다.

#convert.py 
#converts Celsius temperatures to Farenheit 

     def main(): 
      celsius = input("Type the temperature in degrees Celsius: ") 
      farenheit = ((9/5)* int(celsius)) + 32 
      print(farenheit) 

    main(); 

오류가 있습니다.

>>> import convert.py 
Type the temperature in degrees Celsius: 59 
138.2 
Traceback (most recent call last): 
    File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked 
AttributeError: 'module' object has no attribute '__path__' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "<pyshell#0>", line 1, in <module> 
    import convert.py 
ImportError: No module named 'convert.py'; 'convert' is not a package 

저는 Python 3.4.1을 사용하고 있습니다.

+1

'.py'가 없으므로';'는 필요하지 않습니다. –

답변

6

파이썬 모듈을 가져올 때 파일 확장명을 추가하지 마십시오. 당신은 수행해야합니다

>>> import convert 

이 코드를 :

>>> import convert.py 

파이썬은 convert 패키지에있는 존재하지 않는 py 모듈을 가져올 말하고있다.

여기 파이썬에서 모듈과 패키지를 가져 오는 데 reference이 있습니다.

1

.py 확장 프로그램을 삭제해야합니다.

import convert 

무엇 발생하는 파이썬 convert다음 py라는 중첩 된 모듈을 찾습니다 수입이다 : 파이썬 수입은 기본 이름을 사용합니다. convert은 패키지가 아니며 다른 모듈을 포함 할 수 없으므로이 부분은 실패합니다.