Deep Learning & Machine Learning/Tensorflow&PyTorch 개발환경

Macbook M1에 설치된 Visual Studio Code에서 ModuleNotFoundError: No module named ‘tensorflow’ 에러

webnautes 2023. 10. 16. 21:40
반응형

갑자기 Macbook M1에 설치된 vscode에서 Run Python File in Terminal을 사용하여 실행시 tensorflow 모듈 인식이 안되고 다음과 같은 에러가 났습니다.

ModuleNotFoundError: No module named ‘tensorflow’

2022. 3. 5 최초작성

 

(tensorflow-dev) webnautes@webnautesui-MacBookAir python_work % conda run -n tensorflow-dev --no-capture-output --live-stream python /Users/webnautes/Documents/python_work/autoencoder_and_classification.py

Traceback (most recent call last):

  File "/Users/webnautes/Documents/python_work/autoencoder_and_classification.py", line 7, in <module>

    from tensorflow.keras import layers, Sequential, optimizers, callbacks, regularizers, models

ModuleNotFoundError: No module named 'tensorflow'

ERROR conda.cli.main_run:execute(33): Subprocess for 'conda run ['python', '/Users/webnautes/Documents/python_work/autoencoder_and_classification.py']' command failed.  (See above for error)



하지만 터미널에서 다음처럼 python으로 실행하도록 해보면 문제없이 됩니다.  안되는 이유를 알 수 없군요. 

tensorflow-dev) webnautes@webnautesui-MacBookAir python_work % python autoencoder_and_classification.py 



2022. 3. 13

아래 링크에 나온대로 vscode의 환경 설정에서 다음 두 가지 항목을 확인해보니 두번째 항목이 체크되어 있어 체크해제하니 문제가 사라졌습니다. vscode에서 Run Python File in Terminal을 사용하여 실행시 기존에 열어놓았던 터미널을 종료하고 해야합니다. 

https://github.com/microsoft/vscode-python/issues/18665#issuecomment-1062605333 

 

Python › Terminal: Activate Env In Current Terminal

Python › Terminal: Activate Environment



반응형