Difference between revisions of "ML: Python Virtual Environment"

From OnnoWiki
Jump to navigation Jump to search
(Created page with "Berikut langkah sederhana di Ubuntu: mkdir -p ~/Apps/Python cd ~/Apps/Python Install paket dasar: sudo apt update sudo apt install -y python3 python3-pip python3-venv p...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Berikut langkah sederhana di Ubuntu:
+
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.
  
mkdir -p ~/Apps/Python
+
Miniconda adalah installer minimal untuk `conda`, Python, dan paket dasar saja. ([Anaconda][1])
cd ~/Apps/Python
 
  
Install paket dasar:
+
== 1. Install dependency dasar==
  
 
  sudo apt update
 
  sudo apt update
  sudo apt install -y python3 python3-pip python3-venv python3-dev build-essential
+
  sudo apt install -y wget curl bzip2 ca-certificates
  
Buat virtual environment:
 
  
python3 -m venv venv
+
== 2. Download installer Miniconda==
  
Aktifkan virtual environment:
+
cd ~/Downloads
 +
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
  
source venv/bin/activate
+
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])
  
Upgrade pip:
+
== 3. Jalankan installer==
  
  pip install --upgrade pip setuptools wheel
+
  bash Miniconda3-latest-Linux-x86_64.sh
  
Install library Python untuk coding, ML, Keras, Pandas, NumPy, dan Jupyter:
+
Saat muncul pertanyaan:
  
  pip install numpy pandas matplotlib scikit-learn tensorflow keras jupyter notebook ipykernel
+
  Please, press ENTER to continue
  
 +
Tekan '''Enter'''.
  
Tambahkan kernel Jupyter:
+
Saat muncul lisensi, tekan `q` untuk keluar dari tampilan lisensi, lalu ketik:
  
  python -m ipykernel install --user --name python-ml --display-name "Python ML"
+
  yes
  
Jalankan Jupyter Notebook:
+
Saat ditanya lokasi instalasi, terima default:
  
  jupyter notebook
+
  /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'))"
  
Nanti browser akan terbuka. Pilih kernel:
+
== 9. Daftarkan kernel Jupyter==
  
  Python ML
+
  python -m ipykernel install --user --name python-ml --display-name "Python ML TensorFlow"
  
Untuk masuk lagi lain waktu:
+
Jalankan Jupyter:
  
cd ~/Apps/Python
 
source venv/bin/activate
 
 
  jupyter notebook
 
  jupyter notebook
  
Tes cepat:
+
== 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"
 +
 
  
  python -c "import numpy, pandas, sklearn, tensorflow, keras; print('OK')"
+
  [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"

Latest revision as of 15:24, 28 June 2026

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

python -m ipykernel 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"