Learning TinyDB on Ubuntu - 01 set up learning environment

230 阅读2分钟

Create a Virtual Ubuntu System

 Download the official ubuntu system from Download Ubuntu Desktop | Download | Ubuntu and VirtualBox from Downloads – Oracle VM VirtualBox , follow the VirtualBox instructions and create a virtual Ubuntu system.

Clone TinyDB Project

To clone a project from github, we need to generate a ssh key on the ubuntu system and upload it to github account. Usually, the ssh keys are saved in ~/.ssh.

ssh-keygen -t rsa -b 4096 -f ~/.ssh/key_name

```
replace key_name with any name you like

Remember what you enter during the process, it will be used later when cloning the project. Then, in ~/.ssh we will find key_name and key_name.pub, key_name is the private key and the key_name.pub is the public key which can be opened with vim and copied. In github-settings-SSH-GPG keys, click New SSH key, select Authentication Key and paste the key_name.pub to the input box below.

Then git clone the TinyDB project to the destined folder.

cd /path/to/destination/folder
git init
git clone git@github.com:msiemens/tinydb.git

Initialize a Virtual Python Environment 

Pycharm

Download pycharm community edition from Other Versions - PyCharm Community Edition

tar -xzf pycharm-community.tar.gz -C /path/to/destination/folder

```
replace pycharm-community.tar.gz with the actual name of your downloaded file

Then we can open the TinyDB project with Pycharm by 

cd /path/to/pycharm/bin
./pycharm.sh /path/to/tinydb

Then set a virtual python environment. Click File-Settings or Ctrl+Alt+s to open the Settings window.

 Add interpreter and choose the Virtualenv Environment or Conda Environment and set the Conda Excutable as /path/to/anaconda3/bin/conda, then follow the instructions.

Anaconda

Download Anaconda from Anaconda | The World’s Most Popular Data Science Platform and install it.

sudo bash anaconda.sh

```
replace anaconda.sh with the actual name of your downloaded file

During the installation, you will be asked about the place the settle the anaconda3 files. I chose /usr/anaconda3. Then, we can simply add the conda path to the ubuntu system by

export PATH="/path/to/anaconda3/bin:$PATH"

However, it is not saved to the PATH file and after a reboot, we have to reset it again. Therefore, we should find the default PATH and add the conda path to it by

sudo vim /etc/environment

and add /path/to/anaconda3/bin to it. Then create a venv for the tinydb project by

conda create -n venv_name python=3.11

remember to add python=X.XX or the created venv won't locate at /path/to/anacond3/envs. After created this venv, you can link it to pycharm or other ide.

Other Python IDE

Vim

Vim is a highly configurable, powerful text editor, which can be simply installed by

sudo apt install vim

However, without specific plugins, vim is not friendly to python coder. Therefore, we need to install plugins with Vundle.

Create .vimrc with vim under ~ and paste the code below.

" Vim configuration file

" Disable compatibility mode
set nocompatible     " be iMproved, required
filetype off         " required

" You can ignore it if the plugins you clone from git do not need your account
let g:github_user = 'github_account'
let g:github_access_token = 'github_password'

set expandtab
set hiftwidth=4
set tabstop=4
set softtabstop=4

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

"List your plugins here (the git route to their repositories)
Plugin 'nvie/vim-flake8'
Plugin 'davidhalter/jedi-vim'
Plugin 'tpope/vim-surround'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-abolish'

call vundle#end()
filetype plugin indent on

After editing the file, save it and enter :PluginInstall to install these plugins or enter :PluginUpdate to update these plugins. If you want to sperate the window into 2 parts for vim and terminal, you can enter :term.