고전컴퓨터/궁금한것들 모음

[Jypyter notebook] 주피터 노트북에서 .py파일 실행시키기

nineil91 2022. 3. 16. 04:13
#1
! python 파일명.확장자 #command line에 치는것과 같은 기능

#2
exec(open("파일명.확장자").read())

https://stackoverflow.com/questions/42163470/how-to-execute-a-py-file-from-a-ipynb-file-on-the-jupyter-notebook

 

How to execute a * .PY file from a * .IPYNB file on the Jupyter notebook?

I am working on a Python Notebook and I would like that large input code [input] pack into a [* .PY] files and call this files from the notebook. The action of running a [.PY] file from the Noteb...

stackoverflow.com

위 stackoverflow에서 조언한대로 

실행 되었다.

 

한가지 문제가 있다. .py 파일에서 import한 라이브러리가 적용되지 않는다는 것이다. Figure(640X480)이 아니라 effective_dimension 그래프가 나타나야 하는데 라이브러리를 부르지 않아 원하는 결과값이 나오지 않았다.

 

본 문제를 수동으로 import 하는걸로 해결했지만, 다른 좋은 방법이 있다면 블로그에 다시 쓰겠다.