ML: Python Virtual Environment

From OnnoWiki
Revision as of 15:21, 28 June 2026 by Onnowpurbo (talk | contribs)
Jump to navigation Jump to search

Install Miniconda di Ubuntu 26.04 bisa langsung di home folder, tidak perlu `sudo`. Ini cocok untuk kasus Bapak karena `apt` tidak menyediakan Python 3.12, sedangkan TensorFlow belum cocok dengan Python 3.14.

Miniconda adalah installer minimal untuk `conda`, Python, dan paket dasar saja. ([Anaconda][1])

1. Install dependency dasar

sudo apt update
sudo apt install -y wget curl bzip2 ca-certificates


2. Download installer Miniconda

cd ~/Downloads
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Ini sesuai pola installer Linux resmi: `Miniconda3-latest-Linux-x86_64.sh`. Dokumentasi conda juga menjelaskan installer Linux dijalankan dengan format `bash <conda-installer-name>-latest-Linux-x86_64.sh`. ([Conda Documentation][2])

3. Jalankan installer

bash Miniconda3-latest-Linux-x86_64.sh

Saat muncul pertanyaan:

Please, press ENTER to continue

Tekan Enter.

Saat muncul lisensi, tekan `q` untuk keluar dari tampilan lisensi, lalu ketik:

yes

Saat ditanya lokasi instalasi, terima default:

/home/onno/miniconda3

Tekan Enter.

Saat ditanya:

Do you wish to update your shell profile to automatically initialize conda?

Pilih:

yes

4. Aktifkan conda

Tutup terminal lalu buka lagi.

Atau langsung jalankan:

source ~/.bashrc

Cek:

conda --version

Kalau keluar seperti:

conda 25.x.x

berarti sukses.

5. Matikan auto-activate base

Saya sarankan supaya terminal tidak selalu masuk environment `(base)`:

conda config --set auto_activate_base false

Tutup terminal lalu buka lagi.

Kalau ingin mengaktifkan conda manual:

source ~/miniconda3/etc/profile.d/conda.sh

== 6. Buat environment Python 3.12 untuk ML/TensorFlow

source ~/miniconda3/etc/profile.d/conda.sh

conda create -y -n python-ml python=3.12
conda activate python-ml

Cek:

python --version

Harus Python 3.12.x.

7. Install paket machine learning

python -m pip install --upgrade pip setuptools wheel

python -m pip install \
  numpy \
  pandas \
  matplotlib \
  scikit-learn \
  tensorflow \
  keras \
  jupyter \
  notebook \
  ipykernel

8. Test TensorFlow

python -c "import tensorflow as tf; print(tf.__version__)"

Cek GPU:

python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

9. Daftarkan kernel Jupyter

kernel install --user --name python-ml --display-name "Python ML TensorFlow"

Jalankan Jupyter:

jupyter notebook

Versi cepat: copy-paste

sudo apt update
sudo apt install -y wget curl bzip2 ca-certificates

cd ~/Downloads
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

bash Miniconda3-latest-Linux-x86_64.sh 

source ~/.bashrc 

conda config --set auto_activate_base false

source ~/miniconda3/etc/profile.d/conda.sh

conda create -y -n python-ml python=3.12
conda activate python-ml

python -m pip install --upgrade pip setuptools wheel
python -m pip install numpy pandas matplotlib scikit-learn tensorflow keras jupyter notebook ipykernel 

python -c "import tensorflow as tf; print(tf.__version__)"
python -m ipykernel install --user --name python-ml --display-name "Python ML TensorFlow"


[1]: https://www.anaconda.com/download?utm_source=chatgpt.com "Download Anaconda Distribution"
[2]: https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html?utm_source=chatgpt.com "Installing on Linux — conda 26.5.4.dev62 documentation"