更改主機名稱後RabbitMQ無法啟動

作業系統: Windows10

更改主機名稱後,會發現rabbitmq無法啟動,這時候要重新安裝Service。
注意:需要備份的資料先備份起來

  1. 利用rabbitmq提供的bat(RabbitMQ Service - remove.bat),並且以系統管理員執行
  2. 利用rabbitmq提供的bat(RabbitMQ Service - (re)install.bat),並且以系統管理員執行重新安裝service
  3. 利用rabbitmq提供的bat(RabbitMQ Service - start.bat),並且以系統管理員執行重新安裝service啟動服務
  4. 成功後會看到log資料夾出現新的log,rabbit@(新的主機名稱).log,代表成功了。

參考: https://dennymichael.net/2014/06/16/rabbitmq-change-the-hostname/

用vim作為Python IDE

vim版本:8.2

安裝套件管理員Vundle

  1. 下載Vundle plugin manager並且放到VIM套件資料夾

    1
    git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  2. 建立套件管理檔

    1
    touch ~/.vimrc
  3. 將下面指令複製到~/.vimrc檔案裡面

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    set nocompatible              " required
    filetype off " required

    " set the runtime path to include Vundle and initialize
    set rtp+=~/.vim/bundle/Vundle.vim
    call vundle#begin()

    " alternatively, pass a path where Vundle should install plugins
    "call vundle#begin('~/some/path/here')

    " let Vundle manage Vundle, required
    Plugin 'gmarik/Vundle.vim'

    " add all your plugins here (note older versions of Vundle
    " used Bundle instead of Plugin)

    " ...

    " All of your Plugins must be added before the following line
    call vundle#end() " required
    filetype plugin indent on " required
  4. 安裝套件

    1. 先開啟vim
    2. 輸入:
    3. PluginInstall

操作

  • 分割畫面

    1. .vimrc 加入下面幾行
      1
      2
      3
      4
      5
      "split navigations
      nnoremap <C-J> <C-W><C-J>
      nnoremap <C-K> <C-W><C-K>
      nnoremap <C-L> <C-W><C-L>
      nnoremap <C-H> <C-W><C-H>
    2. ctrl加上vim的方向鍵(J下, K上, L右, H左)就可以移動到不同地方的split
  • Buffers

    • :ls可以看到buffer清單
    • 可以在輸入:ls後直接:b ,就可以不用記下buffer number
  • 程式碼收折

    • 在.vimrc加入下面幾行

      1
      2
      3
      4
      5
      6
      " Enable folding
      set foldmethod=indent
      set foldlevel=99

      " Enable folding with the spacebar
      nnoremap <space> za
    • 之後就可用空白鍵收折程式碼

    • 如果想要看到收折的程式碼的docstrings 可以在.vimrc加入這行

      1
      let g:SimpylFold_docstring_preview=1

參考:
vim 快捷鍵 : http://stackoverflow.com/a/5400978/1799408

https://www.openvim.com/
https://realpython.com/vim-and-python-a-match-made-in-heaven/

breakpoints : https://github.com/puremourning/vimspector

Visual Studio + CMake製作Python Extension

版本資訊
Visual Studio 2019
CMake 3.24
Python3.8.10

設定Opencv

  • 編譯OpenCV

  • 設定windows的環境變數 OpenCV_ROOT 到OpenCVConfig.cmake所在的資料夾(CMake 3.12之後的功能,文件

  • 從編譯好的OpenCVConfig.cmake我們可以看OpenCV提供了那些CMake變數給我們使用,可以參考這裡

  • 讓CMake複製dll文件

  • 設定CMake尋找Python.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
find_package(Python 3 REQUIRED 
COMPONENTS Interpreter Development.Module NumPy) # New in cmake 3.19

include_directories(${Python_INCLUDE_DIRS})
link_directories(${Python_LIBRARY_DIRS})
message(STATUS "Python Location: ${Python_INCLUDE_DIRS}")

include_directories(${Python_NumPy_INCLUDE_DIRS})
message(STATUS "NumPy Location: ${Python_NumPy_INCLUDE_DIRS}")

find_package(OpenCV REQUIRED)
if (OpenCV_FOUND)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
include_directories(${OpenCV_INCLUDE_DIRS})
link_libraries(${OpenCV_LIBRARIES})
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
else ()
message(FATAL_ERROR "Could not locate OpenCV")
endif()

原碼參考:

參考:
Python.h位置

CMake尋找Python

Windows下讓cmake找到OpenCV和Eigen

OpenCV

從(cmake 3.12)[https://cmake.org/cmake/help/v3.12/policy/CMP0074.html]之後,可以利用環境變數來告訴cmake套件的位置,在Windows下很方便,因為windows不像linux會把函式庫集中放在一起。設定方法就是利用設定環境變數

1
<PackageName>_ROOT

其中<PackageName>就是你的套件名稱,例如在這裡我們要設的環境變數就是OpenCV_ROOT,注意<PackageName>必須要和你寫在CMakeLists.txt裡面find_package(<PackageName>)大小寫都要一致

設定完後會看到cmake輸出找到的路徑

1
2
3
Environment variable OpenCV_ROOT is set to:

D:\lib\build_opencv

另外由於相容性的關係,cmake預設不會使用環境變數的OpenCV_ROOT,我們必須在CMakeLists.txt中設定打開這個功能

1
cmake_policy(SET CMP0074 NEW)

成功設定後可以看到cmake會有以下輸出

1
2
3
-- Found OpenCV: D:/lib/build_opencv (found version "4.6.0")
-- OpenCV library status:
-- version: 4.6.0

詳細寫法可以參考這個範例
https://gist.github.com/jenhaoyang/924698b31f7e3baede14286c67d6059a

Eigen3.4.0

使用find_package(Eigen3 REQUIRED)後需要get_target_property(EIGEN3_INCLUDE_DIR Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
,根據這個issue的寫法https://gitlab.com/libeigen/eigen/-/issues/2486


參考:
https://seanzhengw.github.io/blog/cmake/2018/04/23/cmake-find-package.html
https://cmake.org/cmake/help/v3.12/policy/CMP0074.html
https://stackoverflow.com/questions/21314893/what-is-the-default-search-path-for-find-package-in-windows-using-cmake

Ubuntu更新cmake

前一陣子在windows上編譯Nvidia triton-inference-server發現他的編譯腳本有很多方便的的操作方法,升級cmake是其中之一,注意指令中有指定ubuntu版本
cmake官方有關於apt下載的說明

1
2
3
4
5
6
7
8
9
ENV DEBIAN_FRONTEND=noninteractive
RUN apt install software-properties-common -y
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | \
gpg --dearmor - | \
tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && \
apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main' && \
apt-get update && \
apt-get install -y --no-install-recommends \
cmake-data=3.21.1-0kitware1ubuntu20.04.1 cmake=3.21.1-0kitware1ubuntu20.04.1

參考:
https://github.com/triton-inference-server/server/blob/main/Dockerfile.QA#L65

Powershell呼叫7zip

如果在powershell 發現找不到7z 指令,可以用下面的script替代

1
2
3
4
5
6
7
8
9
10
11
12
$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe"

if (-not (Test-Path -Path $7zipPath -PathType Leaf)) {
throw "7 zip file '$7zipPath' not found"
}

Set-Alias 7zip $7zipPath

$Source = "c:\BackupFrom\backMeUp.txt"
$Target = "c:\BackupFolder\backup.zip"

7zip a -v50m -mx=9 $Target $Source #-v50m 代表將檔案分割成每50MB一包

7-zip 指令參考


參考:
https://stackoverflow.com/a/25288780