본문 바로가기

파이썬

[Python] 파이썬 콘솔에서의 옵션 m

예제를 보면 python -m venv, python -m pip install --upgrade pip  등

이런 코드를 발견할 수 있다. 때로는 -m 옵션을 넣지 않아 에러가 뜨기도 하는데..

 

-m 옵션은 무슨 의미일까?

 

stackoverflow.com/questions/46319694/what-does-it-mean-to-run-library-module-as-a-script-with-the-m-option

 

What does it mean to "run library module as a script" with the "-m" option?

I'm new to Python (and to programming as well) and, although well documented, I cannot understand what exactly means the -m directive (precisely in the creation of a virtual environment: python3 -m...

stackoverflow.com

76개의 추천을 받은 답변을 보니 대충 모듈의 전체 경로를 안 적어도 어디서든 실행이 가능하게끔 하는 역할을 하는 것이라고 한다.

 

예컨대 pip를 실행한다고 가정해보자.

내 경우 pip가 있는 경로는 'C:\Users\user\AppData\Local\Programs\Python\Python37-32\Scripts'이다.

보통 이 경로로 가서 pip를 실행하는 경우도 있다.

하지만 -m 옵션을 이용하면 굳이 이 경로까지 이동하지 않더라도 환경 변수에 등록된 파이썬 경로의 모듈을 쓸 수 있다.