committed by
GitHub
1 changed files with 298 additions and 0 deletions
@ -0,0 +1,298 @@ |
|||||
|
# ํ๊ฒฝ ๋ณ์ |
||||
|
|
||||
|
/// tip | "ํ" |
||||
|
|
||||
|
๋ง์ฝ "ํ๊ฒฝ ๋ณ์"๊ฐ ๋ฌด์์ด๊ณ , ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ์๊ณ ๊ณ์๋ค๋ฉด, ์ด ์ฑํฐ๋ฅผ ์คํตํ์
๋ ์ข์ต๋๋ค. |
||||
|
|
||||
|
/// |
||||
|
|
||||
|
ํ๊ฒฝ ๋ณ์๋ ํ์ด์ฌ ์ฝ๋์ **๋ฐ๊นฅ**์ธ, **์ด์ ์ฒด์ **์ ์กด์ฌํ๋ ๋ณ์์
๋๋ค. ํ์ด์ฌ ์ฝ๋๋ ๋ค๋ฅธ ํ๋ก๊ทธ๋จ์์ ์ฝ์ ์ ์์ต๋๋ค. |
||||
|
|
||||
|
ํ๊ฒฝ ๋ณ์๋ ์ ํ๋ฆฌ์ผ์ด์
**์ค์ **์ ์ฒ๋ฆฌํ๊ฑฐ๋, ํ์ด์ฌ์ **์ค์น** ๊ณผ์ ์ ์ผ๋ถ๋ก ์ ์ฉํฉ๋๋ค. |
||||
|
|
||||
|
## ํ๊ฒฝ ๋ณ์๋ฅผ ๋ง๋ค๊ณ ์ฌ์ฉํ๊ธฐ |
||||
|
|
||||
|
ํ์ด์ฌ ์์ด๋, **์
ธ (ํฐ๋ฏธ๋)** ์์ ํ๊ฒฝ ๋ณ์๋ฅผ **์์ฑ** ํ๊ณ ์ฌ์ฉํ ์ ์์ต๋๋ค. |
||||
|
|
||||
|
//// tab | Linux, macOS, Windows Bash |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
// You could create an env var MY_NAME with |
||||
|
$ export MY_NAME="Wade Wilson" |
||||
|
|
||||
|
// Then you could use it with other programs, like |
||||
|
$ echo "Hello $MY_NAME" |
||||
|
|
||||
|
Hello Wade Wilson |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
//// tab | Windows PowerShell |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
// Create an env var MY_NAME |
||||
|
$ $Env:MY_NAME = "Wade Wilson" |
||||
|
|
||||
|
// Use it with other programs, like |
||||
|
$ echo "Hello $Env:MY_NAME" |
||||
|
|
||||
|
Hello Wade Wilson |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
## ํ์ด์ฌ์์ ํ๊ฒฝ ๋ณ์ ์ฝ๊ธฐ |
||||
|
|
||||
|
ํ์ด์ฌ **๋ฐ๊นฅ**์ธ ํฐ๋ฏธ๋์์(๋ค๋ฅธ ๋๊ตฌ๋ก๋ ๊ฐ๋ฅ) ํ๊ฒฝ ๋ณ์๋ฅผ ์์ฑ๋ ํ ์๋ ์๊ณ , ์ด๋ฅผ **ํ์ด์ฌ์์ ์ฝ์ ์ ์์ต๋๋ค.** |
||||
|
|
||||
|
์๋ฅผ ๋ค์ด ๋ค์๊ณผ ๊ฐ์ `main.py` ํ์ผ์ด ์๋ค๊ณ ํฉ์๋ค: |
||||
|
|
||||
|
```Python hl_lines="3" |
||||
|
import os |
||||
|
|
||||
|
name = os.getenv("MY_NAME", "World") |
||||
|
print(f"Hello {name} from Python") |
||||
|
``` |
||||
|
|
||||
|
/// tip | "ํ" |
||||
|
|
||||
|
<a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> ์ ๋ ๋ฒ์งธ ์ธ์๋ ๋ฐํํ ๊ธฐ๋ณธ๊ฐ์
๋๋ค. |
||||
|
|
||||
|
์ฌ๊ธฐ์๋ `"World"`๋ฅผ ๋ฃ์๊ธฐ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก์จ ์ฌ์ฉ๋ฉ๋๋ค. ๋ฃ์ง ์์ผ๋ฉด `None` ์ด ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฌ์ฉ๋ฉ๋๋ค. |
||||
|
|
||||
|
/// |
||||
|
|
||||
|
๊ทธ๋ฌ๋ฉด ํด๋น ํ์ด์ฌ ํ๋ก๊ทธ๋จ์ ๋ค์๊ณผ ๊ฐ์ด ํธ์ถํ ์ ์์ต๋๋ค: |
||||
|
|
||||
|
//// tab | Linux, macOS, Windows Bash |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
// Here we don't set the env var yet |
||||
|
$ python main.py |
||||
|
|
||||
|
// As we didn't set the env var, we get the default value |
||||
|
|
||||
|
Hello World from Python |
||||
|
|
||||
|
// But if we create an environment variable first |
||||
|
$ export MY_NAME="Wade Wilson" |
||||
|
|
||||
|
// And then call the program again |
||||
|
$ python main.py |
||||
|
|
||||
|
// Now it can read the environment variable |
||||
|
|
||||
|
Hello Wade Wilson from Python |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
//// tab | Windows PowerShell |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
// Here we don't set the env var yet |
||||
|
$ python main.py |
||||
|
|
||||
|
// As we didn't set the env var, we get the default value |
||||
|
|
||||
|
Hello World from Python |
||||
|
|
||||
|
// But if we create an environment variable first |
||||
|
$ $Env:MY_NAME = "Wade Wilson" |
||||
|
|
||||
|
// And then call the program again |
||||
|
$ python main.py |
||||
|
|
||||
|
// Now it can read the environment variable |
||||
|
|
||||
|
Hello Wade Wilson from Python |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
ํ๊ฒฝ๋ณ์๋ ์ฝ๋ ๋ฐ๊นฅ์์ ์ค์ ๋ ์ ์์ง๋ง, ์ฝ๋์์ ์ฝ์ ์ ์๊ณ , ๋๋จธ์ง ํ์ผ๊ณผ ํจ๊ป ์ ์ฅ(`git`์ ์ปค๋ฐ)ํ ํ์๊ฐ ์์ผ๋ฏ๋ก, ๊ตฌ์ฑ์ด๋ **์ค์ ** ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ผ๋ฐ์ ์
๋๋ค. |
||||
|
|
||||
|
**ํน์ ํ๋ก๊ทธ๋จ ํธ์ถ**์ ๋ํด์๋ง ์ฌ์ฉํ ์ ์๋ ํ๊ฒฝ ๋ณ์๋ฅผ ๋ง๋ค ์๋ ์์ต๋๋ค. ํด๋น ํ๋ก๊ทธ๋จ์์๋ง ์ฌ์ฉํ ์ ์๊ณ , ํด๋น ํ๋ก๊ทธ๋จ์ด ์คํ๋๋ ๋์๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค. |
||||
|
|
||||
|
๊ทธ๋ ๊ฒ ํ๋ ค๋ฉด ํ๋ก๊ทธ๋จ ๋ฐ๋ก ์, ๊ฐ์ ์ค์ ํ๊ฒฝ ๋ณ์๋ฅผ ๋ง๋ค์ด์ผ ํฉ๋๋ค: |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
// Create an env var MY_NAME in line for this program call |
||||
|
$ MY_NAME="Wade Wilson" python main.py |
||||
|
|
||||
|
// Now it can read the environment variable |
||||
|
|
||||
|
Hello Wade Wilson from Python |
||||
|
|
||||
|
// The env var no longer exists afterwards |
||||
|
$ python main.py |
||||
|
|
||||
|
Hello World from Python |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
/// tip | "ํ" |
||||
|
|
||||
|
<a href="https://12factor.net/config" class="external-link" target="_blank">The Twelve-Factor App: Config</a> ์์ ์ข ๋ ์์ธํ ์์๋ณผ ์ ์์ต๋๋ค. |
||||
|
|
||||
|
/// |
||||
|
|
||||
|
## ํ์
๊ณผ ๊ฒ์ฆ |
||||
|
|
||||
|
์ด ํ๊ฒฝ๋ณ์๋ค์ ์ค์ง **ํ
์คํธ ๋ฌธ์์ด**๋ก๋ง ์ฒ๋ฆฌํ ์ ์์ต๋๋ค. ํ
์คํธ ๋ฌธ์์ด์ ํ์ด์ฌ ์ธ๋ถ์ ์์ผ๋ฉฐ ๋ค๋ฅธ ํ๋ก๊ทธ๋จ ๋ฐ ๋๋จธ์ง ์์คํ
(Linux, Windows, macOS ๋ฑ ๋ค๋ฅธ ์ด์ ์ฒด์ )๊ณผ ํธํ๋์ด์ผ ํฉ๋๋ค. |
||||
|
|
||||
|
์ฆ, ํ์ด์ฌ์์ ํ๊ฒฝ ๋ณ์๋ก๋ถํฐ ์ฝ์ **๋ชจ๋ ๊ฐ**์ **`str`**์ด ๋๊ณ , ๋ค๋ฅธ ํ์
์ผ๋ก์ ๋ณํ์ด๋ ๊ฒ์ฆ์ ์ฝ๋์์ ์ํํด์ผ ํฉ๋๋ค. |
||||
|
|
||||
|
**์ ํ๋ฆฌ์ผ์ด์
์ค์ **์ ์ฒ๋ฆฌํ๊ธฐ ์ํ ํ๊ฒฝ ๋ณ์ ์ฌ์ฉ์ ๋ํ ์์ธํ ๋ด์ฉ์ [๊ณ ๊ธ ์ฌ์ฉ์ ๊ฐ์ด๋ - ์ค์ ๋ฐ ํ๊ฒฝ ๋ณ์](./advanced/settings.md){.internal-link target=\_blank} ์์ ํ์ธํ ์ ์์ต๋๋ค. |
||||
|
|
||||
|
## `PATH` ํ๊ฒฝ ๋ณ์ |
||||
|
|
||||
|
**`PATH`**๋ผ๊ณ ๋ถ๋ฆฌ๋, **ํน๋ณํ** ํ๊ฒฝ๋ณ์๊ฐ ์์ต๋๋ค. ์ด์์ฒด์ (Linux, Windows, macOS ๋ฑ)์์ ์คํํ ํ๋ก๊ทธ๋จ์ ์ฐพ๊ธฐ์ํด ์ฌ์ฉ๋ฉ๋๋ค. |
||||
|
|
||||
|
๋ณ์ `PATH`์ ๊ฐ์ Linux์ macOS์์๋ ์ฝ๋ก `:`, Windows์์๋ ์ธ๋ฏธ์ฝ๋ก `;`์ผ๋ก ๊ตฌ๋ถ๋ ๋๋ ํ ๋ฆฌ๋ก ๊ตฌ์ฑ๋ ๊ธด ๋ฌธ์์ด์
๋๋ค. |
||||
|
|
||||
|
์๋ฅผ ๋ค์ด, `PATH` ํ๊ฒฝ ๋ณ์๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค: |
||||
|
|
||||
|
//// tab | Linux, macOS |
||||
|
|
||||
|
```plaintext |
||||
|
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin |
||||
|
``` |
||||
|
|
||||
|
์ด๋ ์์คํ
์ด ๋ค์ ๋๋ ํ ๋ฆฌ์์ ํ๋ก๊ทธ๋จ์ ์ฐพ์์ผ ํจ์ ์๋ฏธํฉ๋๋ค: |
||||
|
|
||||
|
- `/usr/local/bin` |
||||
|
- `/usr/bin` |
||||
|
- `/bin` |
||||
|
- `/usr/sbin` |
||||
|
- `/sbin` |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
//// tab | Windows |
||||
|
|
||||
|
```plaintext |
||||
|
C:\Program Files\Python312\Scripts;C:\Program Files\Python312;C:\Windows\System32 |
||||
|
``` |
||||
|
|
||||
|
์ด๋ ์์คํ
์ด ๋ค์ ๋๋ ํ ๋ฆฌ์์ ํ๋ก๊ทธ๋จ์ ์ฐพ์์ผ ํจ์ ์๋ฏธํฉ๋๋ค: |
||||
|
|
||||
|
- `C:\Program Files\Python312\Scripts` |
||||
|
- `C:\Program Files\Python312` |
||||
|
- `C:\Windows\System32` |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
ํฐ๋ฏธ๋์ **๋ช
๋ น์ด**๋ฅผ ์
๋ ฅํ๋ฉด ์ด์ ์ฒด์ ๋ `PATH` ํ๊ฒฝ ๋ณ์์ ๋์ด๋ **๊ฐ ๋๋ ํ ๋ฆฌ**์์ ํ๋ก๊ทธ๋จ์ **์ฐพ์ต๋๋ค.** |
||||
|
|
||||
|
์๋ฅผ ๋ค์ด ํฐ๋ฏธ๋์ `python`์ ์
๋ ฅํ๋ฉด ์ด์ ์ฒด์ ๋ ํด๋น ๋ชฉ๋ก์ **์ฒซ ๋ฒ์งธ ๋๋ ํ ๋ฆฌ**์์ `python`์ด๋ผ๋ ํ๋ก๊ทธ๋จ์ ์ฐพ์ต๋๋ค. |
||||
|
|
||||
|
์ฐพ์ผ๋ฉด **์ฌ์ฉํฉ๋๋ค**. ๊ทธ๋ ์ง ์์ผ๋ฉด **๋ค๋ฅธ ๋๋ ํ ๋ฆฌ**์์ ๊ณ์ ์ฐพ์ต๋๋ค. |
||||
|
|
||||
|
### ํ์ด์ฌ ์ค์น์ `PATH` ์
๋ฐ์ดํธ |
||||
|
|
||||
|
ํ์ด์ฌ์ ์ค์นํ ๋, ์๋ง `PATH` ํ๊ฒฝ ๋ณ์๋ฅผ ์
๋ฐ์ดํธ ํ ๊ฒ์ด๋๊ณ ๋ฌผ์ด๋ดค์ ๊ฒ๋๋ค. |
||||
|
|
||||
|
//// tab | Linux, macOS |
||||
|
|
||||
|
ํ์ด์ฌ์ ์ค์นํ๊ณ ๊ทธ๊ฒ์ด `/opt/custompython/bin` ๋๋ ํ ๋ฆฌ์ ์๋ค๊ณ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค. |
||||
|
|
||||
|
`PATH` ํ๊ฒฝ ๋ณ์๋ฅผ ์
๋ฐ์ดํธํ๋๋ก "์"๋ผ๊ณ ํ๋ฉด ์ค์น ๊ด๋ฆฌ์๊ฐ `/opt/custompython/bin`์ `PATH` ํ๊ฒฝ ๋ณ์์ ์ถ๊ฐํฉ๋๋ค. |
||||
|
|
||||
|
๋ค์๊ณผ ๊ฐ์ด ๋ณด์ผ ์ ์์ต๋๋ค: |
||||
|
|
||||
|
```plaintext |
||||
|
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/custompython/bin |
||||
|
``` |
||||
|
|
||||
|
์ด๋ ๊ฒ ํ๋ฉด ํฐ๋ฏธ๋์ `python`์ ์
๋ ฅํ ๋, ์์คํ
์ด `/opt/custompython/bin`(๋ง์ง๋ง ๋๋ ํ ๋ฆฌ)์์ ํ์ด์ฌ ํ๋ก๊ทธ๋จ์ ์ฐพ์ ์ฌ์ฉํฉ๋๋ค. |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
//// tab | Windows |
||||
|
|
||||
|
ํ์ด์ฌ์ ์ค์นํ๊ณ ๊ทธ๊ฒ์ด `C:\opt\custompython\bin` ๋๋ ํ ๋ฆฌ์ ์๋ค๊ณ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค. |
||||
|
|
||||
|
`PATH` ํ๊ฒฝ ๋ณ์๋ฅผ ์
๋ฐ์ดํธํ๋๋ก "์"๋ผ๊ณ ํ๋ฉด ์ค์น ๊ด๋ฆฌ์๊ฐ `C:\opt\custompython\bin`์ `PATH` ํ๊ฒฝ ๋ณ์์ ์ถ๊ฐํฉ๋๋ค. |
||||
|
|
||||
|
```plaintext |
||||
|
C:\Program Files\Python312\Scripts;C:\Program Files\Python312;C:\Windows\System32;C:\opt\custompython\bin |
||||
|
``` |
||||
|
|
||||
|
์ด๋ ๊ฒ ํ๋ฉด ํฐ๋ฏธ๋์ `python`์ ์
๋ ฅํ ๋, ์์คํ
์ด `C:\opt\custompython\bin`(๋ง์ง๋ง ๋๋ ํ ๋ฆฌ)์์ ํ์ด์ฌ ํ๋ก๊ทธ๋จ์ ์ฐพ์ ์ฌ์ฉํฉ๋๋ค. |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
๊ทธ๋์, ๋ค์๊ณผ ๊ฐ์ด ์
๋ ฅํ๋ค๋ฉด: |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
$ python |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// tab | Linux, macOS |
||||
|
|
||||
|
์์คํ
์ `/opt/custompython/bin`์์ `python` ํ๋ก๊ทธ๋จ์ **์ฐพ์** ์คํํฉ๋๋ค. |
||||
|
|
||||
|
๋ค์๊ณผ ๊ฐ์ด ์
๋ ฅํ๋ ๊ฒ๊ณผ ๊ฑฐ์ ๊ฐ์ต๋๋ค: |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
$ /opt/custompython/bin/python |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
//// tab | Windows |
||||
|
|
||||
|
์์คํ
์ `C:\opt\custompython\bin\python`์์ `python` ํ๋ก๊ทธ๋จ์ **์ฐพ์** ์คํํฉ๋๋ค. |
||||
|
|
||||
|
๋ค์๊ณผ ๊ฐ์ด ์
๋ ฅํ๋ ๊ฒ๊ณผ ๊ฑฐ์ ๊ฐ์ต๋๋ค: |
||||
|
|
||||
|
<div class="termy"> |
||||
|
|
||||
|
```console |
||||
|
$ C:\opt\custompython\bin\python |
||||
|
``` |
||||
|
|
||||
|
</div> |
||||
|
|
||||
|
//// |
||||
|
|
||||
|
์ด ์ ๋ณด๋ [๊ฐ์ ํ๊ฒฝ](virtual-environments.md){.internal-link target=\_blank} ์ ๋ํด ์์๋ณผ ๋ ์ ์ฉํ ๊ฒ์
๋๋ค. |
||||
|
|
||||
|
## ๊ฒฐ๋ก |
||||
|
|
||||
|
์ด ๋ฌธ์๋ฅผ ์ฝ๊ณ **ํ๊ฒฝ ๋ณ์**๊ฐ ๋ฌด์์ด๊ณ ํ์ด์ฌ์์ ์ด๋ป๊ฒ ์ฌ์ฉํ๋์ง ๊ธฐ๋ณธ์ ์ผ๋ก ์ดํดํ์
จ์ ๊ฒ๋๋ค. |
||||
|
|
||||
|
๋ํ <a href="https://ko.wikipedia.org/wiki/ํ๊ฒฝ_๋ณ์" class="external-link" target="_blank">ํ๊ฒฝ ๋ณ์์ ๋ํ ์ํคํผ๋์(ํ๊ตญ์ด)</a>์์ ์ด์ ๋ํด ์์ธํ ์์๋ณผ ์ ์์ต๋๋ค. |
||||
|
|
||||
|
๋ง์ ๊ฒฝ์ฐ์์, ํ๊ฒฝ ๋ณ์๊ฐ ์ด๋ป๊ฒ ์ ์ฉํ๊ณ ์ ์ฉ ๊ฐ๋ฅํ์ง ๋ฐ๋ก ๋ช
ํํ๊ฒ ์ ์๋ ์์ต๋๋ค. ํ์ง๋ง ๊ฐ๋ฐํ ๋ ๋ค์ํ ์๋๋ฆฌ์ค์์ ๊ณ์ ๋ํ๋๋ฏ๋ก ์ด์ ๋ํด ์๋ ๊ฒ์ด ์ข์ต๋๋ค. |
||||
|
|
||||
|
์๋ฅผ ๋ค์ด, ๋ค์ ์น์
์ธ [๊ฐ์ ํ๊ฒฝ](virtual-environments.md)์์ ์ด ์ ๋ณด๊ฐ ํ์ํฉ๋๋ค. |
Loadingโฆ
Reference in new issue