---
title: "#파이썬 #모듈 #설치 #전역 활용법"
url: "https://notes.junghanacs.com/notes/20250329T213644"
author: "Junghan Kim"
date: "2025-03-29T21:36:00+09:00"
lastmod: "2025-03-29T00:00:00+09:00"
tags: ["hylang","python"]
description: "클론한 파이썬 모듈을 전역에서 활용하는 방법을 정리한 실용 노트이다."
---

> [!abstract] 이 노트에 대하여
> 
> 로컬에서 클론한 py2hy 같은 모듈을 다른 디렉터리에서도 쓰려면 어떻게 설치하고 경로를 잡아야 하는지 설명한다. 파이썬 패키지 활용의 기본 감각을 정리한 노트다.

## BIBLIOGRAPHY

## 관련노트

-   [#LLM: hyrule 설치 하이랭 플러그인](https://notes.junghanacs.com/notes/20250329T164150)

## 히스토리

-   [2025-05-15 Thu 12:41] 3월29일로 가서 추가한다.
-   [2025-03-29 Sat 21:36] 생성

## 로그

### [|2025-03-29 Sat 21:36|](https://notes.junghanacs.com/journal/20250324T000000#h-2025-03-29)

@user

py2hy라는 파이썬 코드를 클론해서 아래와 같이 실행하면 동작이 가능해.

```shell
$ chd py2hy
$ ls
py2hy/  tests/  README.rst  conftest.py  hello.py  setup.py
$ python -m py2hy hello.py
```

py2hy 디렉토리 밖에서도 이 모듈을 사용하고 싶은데 어떻게 해야하지?

@assistant `py2hy` 모듈을 다른 디렉토리에서 사용하려면, 해당 모듈을 Python의 패키지 경로에 추가해야 합니다. 이를 위해서는 다음 방법을 사용할 수 있습니다:

1.  **가상 환경 사용**: 가상 환경을 생성하고, `py2hy` 디렉토리를 그 환경에 설치합니다.
    ```bash
    python -m venv myenv
    source myenv/bin/activate  # Linux/macOS
    myenv\Scripts\activate  # Windows
    cd py2hy
    python setup.py install
    ```

2.  **시스템 패키지 경로에 설치**: `py2hy` 디렉토리에서 직접 설치합니다.
    ```bash
    cd py2hy
    python setup.py install
    ```

3.  **수동으로 경로 추가**: Python 코드에서 `sys.path` 를 수정하여 `py2hy` 디렉토리를 추가합니다.
    ```python
    import sys
    sys.path.append('/path/to/py2hy')
    import py2hy
    ```

이 방법들 중 하나를 선택하여 `py2hy` 모듈을 사용할 수 있습니다.

-   Citations: [1] <https://blog.naver.com/kwrmygirl/222924666952> [2] <https://docs.python.org/ko/3.13/installing/index.html> [3] <https://www.youtube.com/watch?v=MGJBctmfOtU>

@user

### 클로드3.7소네트

[py2hy라는 파이썬 코드를 클론해서 아래와 같이 실행하면 동작이 가능해. $ chd py2hy $ ls py2hy/ tes-](https://www.perplexity.ai/search/py2hyraneun-paisseon-kodeureul-JsDD_NiOT6i8Uzn7sfw5eQ)

py2hy 모듈을 다른 디렉토리에서도 사용하려면 다음과 같은 방법들이 있습니다:

#### 패키지 설치하기

가장 권장되는 방법은 py2hy를 패키지로 설치하는 것입니다:

1.  **setup.py를 이용한 설치**:
    ```sh
    cd py2hy
    pip install .
    ```
    또는 개발 모드로 설치:
    ```sh
    cd py2hy
    pip install -e .
    ```
    개발 모드(-e 옵션)로 설치하면 코드를 수정할 때마다 재설치할 필요 없이 변경사항이 바로 반영됩니다[2][8].

2.  **전역 패키지 디렉토리에 설치**:
    ```sh
    cd py2hy
    python setup.py install
    ```
    이 방법은 py2hy를 시스템 전체에서 사용할 수 있게 합니다[2].

#### 다른 방법들

1.  **PYTHONPATH 환경 변수 설정**:
    ```sh
    export PYTHONPATH=/path/to/py2hy:$PYTHONPATH
    ```
    이렇게 하면 Python이 py2hy 모듈을 찾을 수 있는 경로에 추가됩니다[5].

2.  **sys.path에 경로 추가**: 스크립트 내에서 다음과 같이 코드를 추가합니다:
    ```python
    import sys
    import os
    sys.path.insert(1, "/path/to/py2hy")
    import py2hy
    ```
    이 방법은 임시적인 해결책으로 사용할 수 있습니다[1][3].

3.  **가상 환경 사용**: 가상 환경을 생성하고 그 안에 py2hy를 설치하면 프로젝트별로 독립적인 환경을 유지할 수 있습니다[8].
    ```sh
    python -m venv myenv
    source myenv/bin/activate  # Windows: myenv\Scripts\activate
    cd py2hy
    pip install .
    ```

#### 주의사항

-   전역 설치는 시스템 Python 환경에 영향을 줄 수 있으므로 가능하면 가상 환경을 사용하는 것이 좋습니다[6][8].
-   상대 경로 임포트는 복잡할 수 있으며, 특히 다른 디렉토리 구조에서 문제가 발생할 수 있습니다[3][5].

가장 안전하고 권장되는 방법은 pip를 사용하여 패키지를 설치하는 것입니다. 이렇게 하면 어디서든 py2hy 모듈을 사용할 수 있습니다.

-   Citations: [1] <https://sentry.io/answers/import-files-from-a-different-folder-in-python/> [2] <https://www.activestate.com/resources/quick-reads/python-package-installation-on-windows/> [3] <https://www.reddit.com/r/learnpython/comments/shvgj2/cant_import_packages_from_a_python_module_which/> [4] <https://support.seeq.com/kb/R65/cloud/installing-python-modules> [5] <https://www.reddit.com/r/learnpython/comments/u3bl38/python_import_modules_from_different_directories/> [6] <https://www.pythonmorsels.com/installing-python-packages/> [7] <https://docs.python.org/3/tutorial/modules.html> [8] <https://packaging.python.org/tutorials/installing-packages/> [9] <https://stackoverflow.com/questions/66024987/how-to-import-a-module-from-outside-the-current-folder> [10] <https://stackoverflow.com/questions/36936212/how-do-i-install-a-pip-package-globally-instead-of-locally> [11] <https://discuss.python.org/t/which-is-the-right-way-to-use-modules-within-a-package/15297> [12] <https://stackoverflow.com/questions/39471295/how-to-install-python-package-for-global-use-by-all-users-incl-www-data> [13] <https://github.com/dagster-io/dagster/discussions/18255> [14] <https://docs.python.org/ko/3.13/installing/index.html> [15] <https://github.com/ContinuumIO/anaconda-issues/issues/11378> [16] <https://www.reddit.com/r/learnprogramming/comments/125sxz1/when_to_install_python_packages_globally_vs/>

---

Perplexity로부터의 답변: pplx.ai/share
