Try   HackMD
tags: jptw thesis technology ubuntu

Notes for set-up project on Ubuntu

System Environment

Python / Python3

// check python version 
$ python -V
$ which python

// upgrade python version
$ sudo apt update -y
$ sudo apt install python3.7

// point to python3.7
$ sudo rm /usr/bin/python3
$ sudo ln -s python3.7 /usr/bin/python3
$ alias python3='/usr/bin/python3' #if command not point to correct version

Ref:
[1] How to Upgrade to Python 3.7 on Ubuntu 18.04/18.10
[2] How to make 'python' program command execute Python 3?

Virtual environment

$ sudo apt-get install virtualenv
$ virtualenv -p /usr/bin/python3.7 venv
$ source venv/bin/activate
$ deactivate

Packages Issues

pyaudio

$ sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
$ sudo apt-get install ffmpeg libav-tools
$ sudo pip install pyaudio

Ref: pyaudio-ubuntu-install.md

MariaDB

Installation

$ sudo apt-get install mariadb-server
$ sudo apt-get install mariadb-client
$ sudo systemctl status mariadb

// after installation, you can pip install mysqlclient
(venv)$ pip install mysqlclient

Ref:
[1] [MariaDB][Linux] Ubuntu 18.04安裝MariaDB(MySQL)及基本配置、移除指令

Issues:
[1] why 'pip install mysqlclient' not working in ubuntu 18.04 LTS
[2] Mysql連線的過程中出現Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

In Django APP

settings.py

'default': {
    'NAME': your_db_name,
    'ENGINE': 'django.db.backends.mysql',
    'USER': your_username,
    'PASSWORD': your_password,
    'HOST': 'localhost',
    'PORT': '3306',
    'OPTIONS': {
        'init_command' : 'set storage_engine=INNODB, \
                          sql_mode="STRICT_TRANS_TABLES", \
                          innodb_strict_mode=ON',
        'charset': 'utf8mb4',
    }
},

Remote setting

$ sudo ufw allow 3306/tcp
$ sudo service ufw restart
$ sudo service mysql restart

Ref: How to Allow Remote MySQL Database Connection

Issue

Access an external hard drive from cmd

$ sudo fdisk -l
$ sudo mkdir /media/harddrive
$ sudo mount /dev/sdb /media/harddrive

Environment variables

$ export ENV_NAME=value
$ printenv 
$ echo $ENV_NAME

Ref: EnvironmentVariables