Python virtual environment and packages on Ubuntu


--For more information, please visit Official Tutorial. --Python Virtual Environment and Packages on Windows

Building a virtual environment with venv

Python environment installation

$ sudo apt update && upgrade
$ sudo apt install python3-pip
$ sudo python3 -m pip install pip -U
$ sudo apt install python3-venv
$ sudo apt install python3-tk

Virtual environment construction

$ python3 -m venv myapp

Enable virtual environment

$ cd myapp
$ source bin/activate
(myapp) $ pip install pip --upgrade
(myapp) $ pip install setuptools --upgrade

Installation of machine learning related packages

(myapp) $ pip install numpy
(myapp) $ pip install pandas
(myapp) $ pip install matplotlib
(myapp) $ pip install pillow
(myapp) $ pip install IPython
(myapp) $ pip install tensorflow
(myapp) $ pip install scikit-learn
(myapp) $ pip install scipy
(myapp) $ pip install jupyter

Check installed packages

(myapp) $ pip freeze

Disable virtual environment

(myapp) $ deactivate

Delete virtual environment

$ cd ..
$ rm -fR myapp

Operation check


import numpy as np
import matplotlib.pyplot as plt

def relu(x):
    return np.maximum(0, x)

x = np.arange(-5.0, 5.0, 0.1)
y = relu(x)
plt.plot(x, y)
plt.ylim(-0.5, 5.5)


import pandas as pd

df = pd.DataFrame({
    "Name": ["Braund, Mr. Owen Harris",
        "Allen, Mr. William Henry",
        "Bonnell, Miss. Elizabeth"],
    "Age": [22, 35, 58],
    "Sex": ["male", "male", "female"]}



import tkinter as tk

root = tk.Tk()
root.title('Hello World!')


from sklearn import svm
from sklearn import datasets

digits = datasets.load_digits()
clf = svm.SVC(gamma=0.001, C=100)[:-1],[:-1])
ans = clf.predict([-1:])

print(f'Target Number : {[-1]}')
print(f'Predict Number: {ans[0]}')


from scipy import misc
import matplotlib.pyplot as plt

face = misc.face()


from __future__ import absolute_import, division, print_function, unicode_literals

#Install TensorFlow

import tensorflow as tf

mnist = tf.keras.datasets.mnist

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

model = tf.keras.models.Sequential([
  tf.keras.layers.Flatten(input_shape=(28, 28)),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dense(10, activation='softmax')

              metrics=['accuracy']), y_train, epochs=5)

model.evaluate(x_test,  y_test, verbose=2)


$ jupyter notebook

SSH connection

ssh server installation

$ sudo apt install openssh-server

in conclusion

――It is recommended because you can try various things in a virtual environment.

Recommended Posts

Python virtual environment and packages on Ubuntu
Build Python3 and OpenCV environment on Ubuntu 18.04
[Venv] Create a python virtual environment on Ubuntu
Prepare Python development environment on Ubuntu
Building a Python environment on Ubuntu
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
OpenCV3 & Python3 environment construction on Ubuntu
How to build a new python virtual environment on Ubuntu
Steps to install Python environment on Ubuntu
Creating a python virtual environment on Windows
Created Ubuntu, Python, OpenCV environment on Docker
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Python packages and modules
python virtual environment Pipenv
virtual environment in python
build Python on Ubuntu
Install Python 3.3 on Ubuntu 12.04
Virtual environment with Python 3.6
Ubuntu18.04.05 Creating a python virtual environment in LTS
Build python environment with pyenv on EC2 (ubuntu)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Install python package in personal environment on Ubuntu
[Node-RED] Execute Python on Anaconda virtual environment from Node-RED [Anaconda] [Python]
Install MongoDB on Ubuntu 16.04 and operate via python
Create a Python virtual development environment on Windows
Use matplotlib on Ubuntu 12 & Python
Python: Creating a virtual environment (venv), starting and stopping
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a python virtual environment with virtualenv and virtualenvwrapper
Understand Python packages and modules
Put Python 3.x on Ubuntu
Build python3 environment with ubuntu 16.04
I made a Python3 environment on Ubuntu with direnv.
Build Python environment on Windows
Python environment construction and TensorFlow
Install OpenCV on Ubuntu + python
Building a Python virtual environment
Building and enabling a python virtual environment, etc. (venv)
Build a python virtual environment with virtualenv and virtualenvwrapper
Build python environment on windows
Introducing TensorFlow on Ubuntu + Python 2.7
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Manage Python runtime packages and development environment packages with Poetry
venv: Python virtual environment management
python package dependencies and virtual environment management tool Poetry
Create a decent shell and python environment on Windows
python standard virtual environment venv
Building a Python virtual environment
Set up python and machine learning libraries on Ubuntu
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Build an Ubuntu python development environment on Google Cloud Platform
Building a Python environment on a Mac and using Jupyter lab
Install python3 and scientific calculation library on Ubuntu (virtualenv + pip)
Install CaboCha in Ubuntu environment and call it with Python.
Create a virtual environment for python on mac [Very easy]
Until building a Python development environment using pyenv on Ubuntu 20.04
Overview of Python virtual environment and how to create it
Building a Python environment on Mac
Environment construction of python and opencv
Virtual Environment Version Control Summary Python
Install Python 3.8 on Ubuntu 18.04 (OS standard)