← 전체로 돌아가기
스킬 python

PM2 특정 Python 버전으로 실행

PM2로 특정 Python 버전 앱을 실행하는 방법

pm2pythoninterpreterprocess-managementlinux

PM2로 특정 파이썬 버전 앱 실행하기

PM2로 파이썬 앱을 실행할 때 특정 파이썬 인터프리터를 지정해야 할 때가 있어. 이럴 땐 다음 스텝을 따르면 됨.

  • 1. 파이썬 버전 경로 찾기

    • 먼저, 사용하려는 특정 파이썬 버전의 경로를 알아야 해.
    • which python3.x 명령어로 쉽게 찾을 수 있어. (예: which python3.7)

    ```bash which python3.7

    출력 예시: /usr/bin/python3.7

    ```

  • 2. PM2로 프로그램 시작하기

    • PM2 start 명령어에 -interpreter 플래그를 써서 원하는 파이썬 인터프리터 경로를 지정하면 돼.

    bash pm2 start your_script.py --interpreter=/path/to/specific/python

    • 예시: app.py를 파이썬 3.7로 실행할 경우

    bash pm2 start app.py --interpreter=/usr/bin/python3.7

    • /usr/bin/python3.7는 실제 파이썬 인터프리터 경로로 바꿔야 함.
    • 앱에 필요한 인자가 있다면 명령어 뒤에 추가하면 돼.
    • 프로세스 이름 지정은 --name 옵션을 사용하면 됨.

    bash pm2 start horangApp_admin.py --interpreter=/usr/bin/python3.8 --name="hr_admin"

  • 3. 실행 확인하기

    • 앱 실행 후, pm2 show <앱_이름> 명령어로 올바른 파이썬 버전으로 실행 중인지 확인할 수 있어.
    • 이 명령어로 프로세스 상세 정보와 사용 중인 인터프리터를 볼 수 있음.

    bash pm2 show app

여기서 배울 것

  1. `which` 명령어로 특정 파이썬 인터프리터 경로를 찾을 수 있음.
  2. PM2 `start` 명령어의 `-interpreter` 플래그로 파이썬 버전을 지정함.
  3. `--name` 옵션으로 PM2 프로세스 이름을 설정할 수 있음.
  4. `pm2 show`로 실행 중인 앱의 상세 정보를 확인 가능함.
원본 파일 보기 (.claude/skills/tn-pm2-venv-execute/SKILL.md)
---
name: PM2 특정 Python 버전으로 실행
description: Use when the user asks to start a Python application with a specific Python interpreter version using PM2, or when they need to specify the Python executable path for a PM2 process.
version: 1.0.0
source: /home/son/prj/resume/backup_notes_260317/notion/Tech Note/pm2 venv execute c9bdf1d0b3be4825893183fa5b68b76b.md
---

# pm2 venv execute

using pm2, how can i start the program with specific python version?

1. **Locate the Python Version**: First, ensure that you know the path of the specific Python version you want to use. You can usually find this out by typing **`which python3.x`** in your terminal, where **`3.x`** is the version number. For example, for Python 3.7, you would use **`which python3.7`**.
    
    ![Screen Shot 2024-01-26 at 9.06.35 PM.png](pm2%20venv%20execute/Screen_Shot_2024-01-26_at_9.06.35_PM.png)
    
2. **Start the Program with PM2**: Use the PM2 **`start`** command with the **`-interpreter`** flag to specify the path to the desired Python interpreter. The command would look something like this:
    
    ```css
    cssCopy code
    pm2 start your_script.py --interpreter=/path/to/specific/python
    
    ```
    
    For example, if you're using Python 3.7 and your script is named **`app.py`**, the command might be:
    
    ```jsx
    javascriptCopy code
    pm2 start app.py --interpreter=/usr/bin/python3.7
    
    ```
    
    Replace **`/usr/bin/python3.7`** with the actual path to the Python interpreter you found in the first step.
    
3. **Verify**: After starting the application, you can verify that it's running with the correct Python version by using:
    
    ```sql
    sqlCopy code
    pm2 show app
    
    ```
    
    This will display detailed information about the process, including the interpreter being used.
    

Remember to replace **`your_script.py`** with the path to your actual Python script and **`/path/to/specific/python`** with the actual path to the Python interpreter you wish to use.

Also, if your Python application requires specific arguments, you can append them at the end of the PM2 start command.

NAME program

pm2 start horangApp_admin.py --interpreter=/usr/bin/python3.8 **--name=”hr_admin”**