I don't know what the number is, but I will leave a note when I built a new machine learning (Python) environment on Ubuntu. For those who want to easily build an environment with minimal installation using Python pre-installed on the system (Ubuntu) **. Environment: Ubuntu 20.04 LTS
If you have a regular distribution of Ubuntu 20.04 LTS, Python3 should be pre-installed. Just in case, enter the following in the terminal and confirm it.
Terminal
python3 -V
Python 3.8.2
#If not installed
sudo apt install python3
Next, install pip, which is required to install various libraries.
Terminal
sudo apt install python3-pip
#Confirmation of installation
pip3 --version
Installing the library directly in Python used on your system is not recommended as it can damage your system in the worst case. Therefore, build a virtual environment so that the installation of the library does not affect the system dependency environment. To use venv with Ubuntu pre-installed Python, the following installation is required.
Terminal
sudo apt install python3-venv
Create a virtual environment before installing the library.
Terminal
#In your home directory.Create a virtual environment called ML in the venv folder
python3 -m venv .venv/ML
Execute the following to activate the created virtual environment.
Terminal
cd .venv/ML
source bin/activate
#When disabling, do the following
deactivate
We will install the library in the virtual environment. The following is an example of installing scikit-learn, matplotlib, and pandas all at once.
Terminal
pip3 install -U scikit-learn ,matplotlib, pandas
plt.show ()
.UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.
This is because Tkinter, which is required for drawing the UI on Python, is not installed. It is good to install it together.
Terminal
sudo apt install python3-tk
This is the end of environment construction.
When coding with VS Code, it is convenient to set the virtual environment created earlier as the default interpreter. If you add the following to Settings.json, the virtual environment will be automatically activated and the program will be executed.
Settings.json
"python.defaultInterpreterPath": "/home/$USERNAME/.venv/ML/bin/python3",
Recommended Posts