2025年9月3日 星期三

Ubuntu 22.04.3 新酷音中文輸入法安裝紀錄

 

安裝系統

  1. 最小安裝, 安裝更新, 不安裝第三方套件
  2. 英文
  3. 時區台北

中文語言包

時區選台北之後,內建語言是lzh很奇怪

 

成&設定語言成zh_TW

sudo locale-gen zh_TW.UTF-8
sudo localectl set-locale LANG=zh_TW.UTF-8
這裡需要重啟才會整個系統生效,不過待會再一起重啟,我們先去裝語言套件才會有中文輸入法。
 
 
Region & Language,→ Manage installed languages → 彈出Language Support視窗
 
Language Support內安裝繁體中文語言包

點擊Details會發現都是英文語系套件,不是我們要的中文套件

點擊下方Install / Remove Languages按鈕 → 彈出Installed Languages視窗

找到Chinese (traditional)並勾選,按右下角Apply

 

設定系統語言

離開Language Support視窗,回到Region & Language,這時點擊下方語言選擇按鈕,會發現已經有中文,請點擊它讓勾勾跑到中文 → 再點右上角Select來套用。

重啟系統

到這裡就可以重新啟動系統

安裝中文輸入法

請不要改成中文目錄

重啟之後Ubuntu會問你是否要改成中文目錄名稱,請務必選不要,避免一些應用程式無法存取

在Launcher應用程式清單找到設定值(之前是Settings)→左半選單中點地區與語言

 

新增鍵盤的輸入來源

左半選單中點鍵盤→點擊輸入來源下方的+號按鈕→彈跳出加入輸入來源對話方塊

加入輸入來源對話方塊,點擊中文(台灣)→可以看到中文(新酷音)

點擊中文(新酷音)→右上角加入 

 

可以看到完成新增的輸入來源已有英文和中文

Ubuntu 22.04.3內建是使用Window + Space做輸入法切換

 

改輸入法切換快捷鍵

點擊下方鍵盤快捷鍵檢視與自訂快捷鍵按鈕→彈跳鍵盤快捷鍵視窗→點擊輸入

這裡就可以點擊想要修改的切換輸入法的快捷鍵功能


參考資料

https://hackmd.io/@3OnqnT1fTvGgrRoxGGdA-g/S1lmxWMGj

 

資料來源:https://hackmd.io/@uoStF0JnQ2KW_h7HNvalFA/ryTtdp9pn#Ubuntu-22043-%E6%96%B0%E9%85%B7%E9%9F%B3%E4%B8%AD%E6%96%87%E8%BC%B8%E5%85%A5%E6%B3%95%E5%AE%89%E8%A3%9D%E7%B4%80%E9%8C%84

2025年8月29日 星期五

開源磁碟加密軟體:VeraCrypt

 https://ithelp.ithome.com.tw/upload/images/20191008/20118848mrXu4rrmSZ.png

在現今網路通訊方式發達,以及多種隨身存裝置的方便性,這些都成為資料外洩的可能管道。那麼在資料保全的方法上,除了檔案加密這種操作方式之外,有沒有更簡單可以一次保護較多檔案與文件安全性的作法?

有的,其中一種方法是採用磁碟加密軟體來做保護。


方案介紹

在開源軟體的世界中,VeraCrypt 是相當多人使用的磁碟加密軟體,它是基於另一套更早已經停止維護的 TrueCrypt 而來,並修正原 TrueCrypt 的相關安全問題。

在資料保護的要求上,VeraCrypt 提供了多種實用的功能讓我們選用:

  • 跨平台支援 Windows、Linux、macOS
  • 可建立實體磁碟上的加密區域
  • 可建立加密虛擬磁碟檔案並掛載使用
  • 自動、即時且透明化的加密
  • 支援 CPU 硬體加速
  • 支援繁體中文介面
  • 可使用 GUI 或是 CLI 操作

它可以提供相當容易又好用的加密保護,對於存放機密資料是很不錯的解決方案。


安裝方式

做為一個應用軟體,VeraCrypt 的安裝方式與大多數軟體相同,下載後點兩下與下一步就可以安裝完成。

如果沒有自動出現繁體中文介面,可以點選功能表的 [Settings] -> [Language...],選擇 [繁體中文],不過它裡面有兩個,應該要選倒數第三個才是。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848yMhWjkGpPu.png
選擇繁體中文介面


主要功能

在這篇文章裡,我們以最主要兩個功能做說明:實體加密磁碟與虛擬加密磁碟檔案

建立實體加密磁碟

最基本的用法,是針對一個實體的磁碟做加密,通常我會利用 USB 隨身碟做加密,確保它即便遺失了整支隨身碟的內容仍然是受到保護的。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848IdK8rRvJWw.png
VeraCrypt 主畫面

按下主畫面的 [建立加密區] 按鈕,進來後的畫面請選擇 [Encrypt a non-system partition/drive],下一步選擇 [標準 VeraCrypt 加密區],再下一步就會來到選擇磁碟機的介面,請記得選擇正確的磁碟,以免發生憾事。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848NzmEDBcNED.png
準備選擇預計加密磁碟機

https://ithelp.ithome.com.tw/upload/images/20191008/201188487s9dOmacGx.png
選擇正確加密磁碟機

進入下一步後,請選擇 [Create encrypt volume and format it],讓他整個磁碟重新格式化並予以加密。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848q5n6XqcWc4.png
選擇加密選項

這個步驟用以選擇要做加密的演算法需要使用到什麼程度,越強力的加密演算法越安全但也多少影響效能。若對於效能有所疑慮,VeraCrypt 也提供了 Benchmark 效能測試工具,可以依據所選的演算法、緩衝區大小等進行測試,依據結果再決定要選用什麼加密演算法。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848BQqvZ8RPcC.png
輸入加密區密碼

接下來請輸入要加密用的密碼,這個密碼非常重要,不要太過簡單也不要讓自己遺失或忘記,一旦遺失了密碼可說是神仙也難救。除了密碼之外,VeraCrypt 也支援多加一道金鑰機制,將密碼與金鑰分別保存,兩支相符方能解鎖,雖較為麻煩,但卻大大增加資料安全的保護能力。

再下一步會要求選擇格式化的檔案系統等選項,在這個畫面多多移動滑鼠可以產生更高強度的加密金鑰,接著請選擇後按下 [格式化] 按鈕即可開始進行製作加密磁碟。

掛載實體加密磁碟

製作完成加密磁碟以後,這個隨身碟是無法直接使用的,需要用 VeraCrypt 掛載並輸入密碼或金鑰檔才能使用。

在主畫面先選取列表中的一個磁碟機代號,再按下 [選擇磁碟機],進入選擇畫面。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848V3q9uNwPIk.png
選擇要掛載的加密磁碟

選擇完成按下 [確定],回到主畫面再按最下方的 [掛載] 按鈕,他會要求輸入密碼或提供金鑰檔,請依據情況提供上去。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848QO6IxWxQtI.png
掛載加密磁碟並提供密碼或金鑰檔

經過上面的步驟,即可將這個加密磁碟掛載到範例中的 U: 磁碟機代號並開始使用了,當使用完畢不需再使用時,可以在該磁碟機代號上按滑鼠右鍵,再點選 [卸載] 即可卸除。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848NUXLqvDgjD.png
掛載加密磁碟成功

建立虛擬加密磁碟檔案

另一種作法,是產生一個虛擬磁碟的檔案,要使用的時候再掛載起來用即可,好處是使用方便,移轉容易,還可以依據不同需求切出不同的虛擬磁碟檔案,我個人也比較喜歡這個作法。

大多數的操作都與 建立實體加密磁碟 差不多,僅說明不同之處。

在第一個步驟時要改成選擇 [Create an encrypted file container],一路來到指定加密區存放位置的畫面,請輸入路徑以及檔案名稱。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848IAHiVFXPYR.png
準備選擇虛擬密磁碟檔案存放位置

接著來到加密區大小的畫面,可以指定要產生出來的虛擬磁碟容量要多大,請依據實際情況輸入。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848ephTZc7g1P.png
準備選擇虛擬密磁碟容量

依照畫面指示完成後,就會在指定的路徑下產生一個虛擬磁碟檔案。

掛載虛擬加密磁碟檔案

同樣的過程,只差別在主畫面操作時選擇 [選擇檔案],選取檔案後再按下 [掛載],依據與實體加密磁碟相同的操作模式即可完成。

https://ithelp.ithome.com.tw/upload/images/20191008/20118848xRk6rWHSfy.png
準備選擇掛載虛擬加密磁碟檔案


進階使用

如果覺得經常操作掛載與卸載的動作浪費不少時間,也可以考慮使用 VeraCrypt 所提供的 CLI 指令模式,搭配批次檔來使用就會方便許多。

這裡提供我常用的指令與參數,可依據需求自己調整,範例適用於 Windows 作業系統。

掛載虛擬加密磁碟檔案

VeraCrypt.exe /q /a /b /m rm /v "testcryptdiskfile"

若沒有指定 /a 參數後的值,它會自己找一個代號掛載上來。

卸載虛擬加密磁碟檔案

VeraCrypt.exe /q /d /b

若沒有指定 /d 參數後的值,它會把所有已經掛載到系統上的實體與虛擬加密磁碟全部卸載。


結論

過去曾經需要保護某些重要文件檔,使用加密壓縮檔的方式保存,但這種方式在使用壓縮檔內檔案時會造成資料落地的問題 (因為壓縮軟體會先把它解密到暫存資料夾)。

為了解決這個問題,後來採用虛擬加密磁碟檔案的方式掛載起來使用,檔案直接在該虛擬磁碟機裡操作,就解決了當時所面臨的問題。

對於重要的機密檔案,使用 VeraCrypt 可以很好的協助我們提升安全性,當然若想要更進一步,還可以再把裡面的檔案也使用檔案自身的加密機制 (例 Office 或 PDF 文件檔),做到雙層保護的能力。當然,可別把密碼給忘了。


參考資料



資料來源:https://ithelp.ithome.com.tw/m/articles/10225959

2025年8月26日 星期二

S.T.A.R. 運用在管理職能 招募面談技巧-突破未來人才荒

 Situation 情境

    情境描述、參與人
    事件:最大的挑戰、最有成就感
    原因:什麼原因而有這樣的事件
    現狀:當時狀況如何
    人員:影響了哪些人

Task 任務

    任務:個人負責事項
    目標:要達到什麼目標

Action 行動

    實際行動、個人感受
    行動:採取哪些行動
    感受:對事件的想法、困擾
    觀察:他人的反應如何

Result 結果

    事件結果
    結果:結果如何(是否達標)
    收穫:對自己有哪些幫助
    反思:哪些地方可以更好




Wiki


STAR原則,全稱情境、任務、行動、結果原則(英語:Situation, Task, Action, Result),是一種行為面試方式。

方法

STAR面試採用行為問題開場,要求面試者提供具體經歷。[1]面試官要求詳細描述當時情況,包括相關人員與背景。接著了解面試者在該情境下的任務、職責、採取哪些行動,最後評估行動成果。[2]

典型問題包括:

  • 情境(Situation):「舉例你參與過哪些結果正面的專案。」
  • 任務(Task):「描述你在此專案中的職責。」
  • 行動(Action):「說明你採取哪些具體方法完成任務。」
  • 結果(Result):「這些行動有什麼成果?」[3]

面試官採用STAR原則,能了解面試者的行為模式,無需直接觀察其工作表現。透過情境、任務、行動、結果的架構收集具體案例,藉此掌握面試者的工作方式、現有能力、需要加強的領域。[4]

專家陶德·倫巴底(英語:Todd Lombardi)建議,STAR面試應先說明問題目的。他在行為面試時,會詢問面試者參與的專案、角色變化、如何處理期限壓力或突發狀況、面對挫折的應對方式。他認為每個人都有相關經歷,事先說明問題方向很公平,還能避免面試者困惑、回答不完整。[1][5]

反向應用

面試者亦會使用STAR原則,準備面試回應,提升錄取機率。[6][7]專家建議,面試者應將STAR回答控制在90-120秒內,時間分配為:情境(S)20秒、任務(T)15秒、行動(A)50秒、結果(R)20秒。[8]

除了用STAR架構回答行為問題,面試者也能運用此方法於應徵的其他環節:

  • 履歷撰寫:使用STAR呈現具體貢獻、量化成果。
  • 自我介紹:避免流水帳式敘述,提升表達效果。
  • 主動提問:面試尾聲的提問環節,能運用STAR思維設計問題。[8]

2025年8月20日 星期三

windows command 刪除網路芳鄰密碼,使用另一組帳號密碼登入




如果你要用 另一組帳號密碼 重新連線「網路芳鄰」(網路共享資料夾),可以在 命令提示字元 (cmd)net use


連線到網路芳鄰 (指定帳號 & 密碼)

net use \\電腦名稱或IP\共享資料夾 密碼 /user:使用者名稱

✅ 範例:

net use \\192.168.1.100\sharefolder MyPass123 /user:Administrator

如果使用網域帳號 (Domain):

net use \\192.168.1.100\sharefolder MyPass123 /user:DOMAIN\username

如果要建立網路磁碟機 (例如 Z: )

net use Z: \\192.168.1.100\sharefolder MyPass123 /user:Administrator

如果要先刪除舊的憑證再連線

有時候 Windows 已經記住舊的帳密,會導致連線不上,你可以先刪掉:

net use \\192.168.1.100\sharefolder /delete

然後再用新的帳號密碼連線。



你要刪除 Windows 記住的「網路芳鄰 / 網路共享」的帳號密碼,可以透過 命令提示字元 (cmd)PowerShell 來做。以下提供幾種方式:


方法一:使用 net use

  1. 開啟 命令提示字元 (cmd)

  2. 輸入以下指令查看目前已儲存的網路連線:

    net use
    

    會顯示目前的網路磁碟機或網路路徑。

  3. 如果你要刪除某個網路位址(例如 \\192.168.1.100\\ServerName),可以用:

    net use \\192.168.1.100 /delete
    

    或者一次刪除所有:

    net use * /delete
    

方法二:刪除 Windows 儲存的憑證 (Credential)

  1. 打開 cmd,輸入:

    cmdkey /list
    

    會列出 Windows 儲存的所有憑證 (包括網路芳鄰密碼)。

  2. 如果找到某個憑證,例如:

    Target: LegacyGeneric:target=TERMSRV/192.168.1.100
    

    你可以刪掉它:

    cmdkey /delete:TERMSRV/192.168.1.100
    

    或者刪除整個伺服器的網路憑證:

    cmdkey /delete:192.168.1.100
    

方法三:GUI 操作 (補充)

  • 控制台 → 使用者帳戶 → 認證管理員
    在這裡也能找到「Windows 認證」,手動刪除掉記住的密碼。



2025年7月31日 星期四

如何在python venv 虛擬環境裡安裝套件

 在 Python 的虛擬環境 (`venv`) 中安裝套件是管理專案依賴的常見做法,以下是詳細的步驟與注意事項:


---


### **步驟:**


1. **建立虛擬環境**

   - 使用 Python 的內建模組 `venv` 建立虛擬環境。

   - 在專案目錄中,開啟終端機並輸入以下指令:

     ```bash

     python -m venv 虛擬環境名稱

     ```

     例如:`python -m venv venv`(慣例命名為 `venv`)。

   - 這會在當前目錄下建立一個名為 `虛擬環境名稱` 的資料夾,包含獨立的 Python 環境。


2. **啟用虛擬環境**

   - 根據作業系統,輸入以下指令來啟用虛擬環境:

     - **Windows**:

       ```bash

       虛擬環境名稱\Scripts\activate

       ```

       例如:`venv\Scripts\activate`

     - **MacOS/Linux**:

       ```bash

       source 虛擬環境名稱/bin/activate

       ```

       例如:`source venv/bin/activate`

   - 啟用後,命令列提示符會顯示虛擬環境名稱(例如 `(venv)`),表示已進入虛擬環境。


3. **安裝套件**

   - 在啟用的虛擬環境中,使用 `pip` 安裝所需的套件:

     ```bash

     pip install 套件名稱

     ```

     例如:`pip install requests`(安裝 `requests` 套件)。

   - 若需要安裝特定版本的套件,可指定版本:

     ```bash

     pip install 套件名稱==版本號

     ```

     例如:`pip install requests==2.28.1`

   - 若有多個套件要安裝,可以一次指定:

     ```bash

     pip install 套件1 套件2 套件3

     ```


4. **檢查已安裝的套件**

   - 查看虛擬環境中已安裝的套件清單:

     ```bash

     pip list

     ```

   - 確認特定套件是否安裝:

     ```bash

     pip show 套件名稱

     ```


5. **(可選)使用 requirements.txt 安裝多個套件**

   - 如果有 `requirements.txt` 文件(列出專案所需的所有套件),可以一次性安裝:

     ```bash

     pip install -r requirements.txt

     ```

   - 生成 `requirements.txt` 的方法:

     ```bash

     pip freeze > requirements.txt

     ```


6. **退出虛擬環境**

   - 安裝完成後,若要退出虛擬環境,輸入:

     ```bash

     deactivate

     ```

   - 提示符會恢復為正常狀態,表示已退出虛擬環境。


---


### **注意事項:**


1. **確認 Python 版本**

   - 虛擬環境會使用建立時的 Python 版本。確保系統中使用的 Python 版本與專案需求相符。

   - 檢查 Python 版本:

     ```bash

     python --version

     ```

   - 若有多個 Python 版本,可指定特定版本建立虛擬環境:

     ```bash

     python3.9 -m venv 虛擬環境名稱

     ```


2. **確保 pip 是虛擬環境中的版本**

   - 在虛擬環境中,`pip` 應指向虛擬環境內的版本,而非系統全域的 `pip`。

   - 檢查 `pip` 版本:

     ```bash

     pip --version

     ```

     應顯示虛擬環境的路徑,例如:`(venv)` 下的 `pip`。

   - 若需要更新虛擬環境中的 `pip`:

     ```bash

     pip install --upgrade pip

     ```


3. **套件相容性**

   - 某些套件可能不支援特定 Python 版本或作業系統,安裝前請確認相容性。

   - 可參考套件的官方文件或 PyPI 頁面,檢查支援的 Python 版本。


4. **網路連線**

   - 安裝套件需要連接到 PyPI(Python Package Index)或指定的鏡像源。確保網路暢通。

   - 若 PyPI 下載速度慢,可使用鏡像源(例如國內的清華或阿里雲鏡像):

     ```bash

     pip install 套件名稱 -i https://pypi.tuna.tsinghua.edu.cn/simple

     ```


5. **虛擬環境的隔離性**

   - 虛擬環境中的套件與系統全域環境分離,安裝的套件僅限於該虛擬環境使用。

   - 不要在虛擬環境外使用系統全域的 `pip` 安裝套件,否則可能導致版本衝突。


6. **管理 requirements.txt**

   - 定期更新 `requirements.txt` 以記錄專案依賴,方便在其他環境中重現。

   - 若套件版本衝突,可使用 `pipdeptree` 或 `pip-conflict-checker` 檢查依賴問題。


7. **儲存與分享虛擬環境**

   - 虛擬環境資料夾(例如 `venv`)不建議直接複製到其他機器,因可能包含平台特定的二進位檔案。

   - 分享專案時,僅需分享 `requirements.txt`,讓其他人在新環境中重新安裝套件。


8. **常見問題與解決方法**

   - **錯誤:`pip` 未找到**:確保已啟用虛擬環境,或檢查 Python 是否正確安裝。

   - **錯誤:套件安裝失敗**:可能是相容性問題,嘗試降低套件版本或更新 Python。

   - **權限問題**:避免使用 `sudo pip install`,因為這可能影響系統全域環境。


---


### **範例:**

假設你想在虛擬環境中安裝 `requests` 和 `numpy`:

```bash

# 建立並啟用虛擬環境

python -m venv myenv

source myenv/bin/activate  # MacOS/Linux

# 或 myenv\Scripts\activate  # Windows


# 安裝套件

pip install requests numpy


# 檢查已安裝套件

pip list


# 儲存依賴到 requirements.txt

pip freeze > requirements.txt


# 退出虛擬環境

deactivate

```


---


### **總結**

使用 `venv` 能有效隔離專案依賴,避免版本衝突。遵循以上步驟並注意相容性和環境隔離,即可順利在虛擬環境中安裝和管理套件。如需進一步協助,可提供具體問題,我會幫你分析!

導到正式電腦,比如另一台電腦,是不是要利用requirements.txt安裝出一模一樣的環境

 是的,若要在另一台電腦(正式電腦)上重建相同的 Python 虛擬環境,使用 `requirements.txt` 是標準做法。以下是詳細步驟、注意事項及可能遇到的問題:


---


### **一、重建虛擬環境的步驟**


#### **步驟 1:在原始電腦上匯出環境依賴**

1. **啟動原始虛擬環境**  

   在原始電腦上,進入專案的虛擬環境:

   ```bash

   source myenv/bin/activate  # Linux/macOS

   myenv\Scripts\activate     # Windows

   ```


2. **生成 `requirements.txt`**  

   使用 `pip freeze` 匯出當前環境的套件清單:

   ```bash

   pip freeze > requirements.txt

   ```

   - 這會生成一個 `requirements.txt` 檔案,記錄所有套件及其版本,例如:

     ```

     requests==2.28.1

     numpy==1.24.3

     ```


3. **檢查 `requirements.txt`**  

   - 確認檔案內容是否正確,避免包含不必要的套件。

   - 如果只需要特定套件,可手動編輯 `requirements.txt`,僅保留專案所需的依賴。


4. **傳輸檔案**  

   將專案檔案(包括 `requirements.txt`)傳送到目標電腦,例如透過 Git、USB 或雲端儲存。


---


#### **步驟 2:在目標電腦上重建環境**


1. **確認 Python 版本**  

   - 檢查目標電腦是否安裝與原始環境相同的 Python 版本(用 `python --version` 或 `python3 --version`)。

   - 如果版本不同,需先安裝正確的 Python 版本(可使用 `pyenv` 或官方安裝程式)。


2. **創建新虛擬環境**  

   在目標電腦的專案目錄下,創建新的虛擬環境:

   ```bash

   python -m venv myenv

   ```


3. **啟動虛擬環境**  

   進入新創建的虛擬環境:

   ```bash

   source myenv/bin/activate  # Linux/macOS

   myenv\Scripts\activate     # Windows

   ```


4. **安裝依賴**  

   使用 `requirements.txt` 安裝套件:

   ```bash

   pip install -r requirements.txt

   ```

   - 這會自動安裝 `requirements.txt` 中列出的所有套件及其指定版本。


5. **驗證環境**  

   - 使用 `pip list` 檢查已安裝的套件是否與 `requirements.txt` 一致。

   - 運行專案程式碼,確認環境是否正常運作。


---


### **二、注意事項**


1. **Python 版本一致性**  

   - 確保目標電腦的 Python 版本與原始環境一致(例如,Python 3.8.10)。不同版本可能導致套件不相容。

   - 若不確定原始環境的 Python 版本,可在原始環境中運行:

     ```bash

     python --version

     ```


2. **作業系統相容性**  

   - 某些套件(特別是需要編譯的套件,如 `numpy` 或 `pandas`)可能在不同作業系統(Windows、Linux、macOS)上有不同的二進位檔案。

   - 如果套件安裝失敗,可能需安裝編譯工具(如 Windows 的 Visual C++ Build Tools 或 Linux 的 `gcc`)。


3. **套件版本衝突**  

   - `requirements.txt` 記錄的是特定版本,若某套件在新環境中已更新,可能導致相容性問題。

   - 若遇到衝突,可嘗試:

     - 更新原始環境的套件(`pip install --upgrade <package>`)並重新生成 `requirements.txt`。

     - 使用 `--no-deps` 安裝特定套件,忽略依賴:

       ```bash

       pip install -r requirements.txt --no-deps

       ```


4. **網路與鏡像源**  

   - 確保目標電腦有網路連線,因為 `pip` 需要從 PyPI 下載套件。

   - 若下載速度慢,可切換到更快的鏡像源(例如中國大陸的清華源):

     ```bash

     pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

     ```


5. **環境變數與配置**  

   - 如果專案依賴特定的環境變數(如 API 金鑰、資料庫 URL),需在新電腦上手動配置。

   - 檢查是否有其他配置文件(例如 `.env` 或專案特定的設定檔案)需要一併傳輸。


6. **不要傳輸虛擬環境資料夾**  

   - 虛擬環境資料夾(`myenv/`)與作業系統和路徑綁定,直接複製可能導致無法使用。

   - 始終使用 `requirements.txt` 重建環境,而非複製整個虛擬環境。


7. **檔案編碼與路徑**  

   - 確保 `requirements.txt` 使用 UTF-8 編碼,避免在不同系統間出現亂碼。

   - Windows 用戶注意路徑長度限制(260 字元),避免將虛擬環境放在過深的目錄。


8. **版本控制最佳實務**  

   - 將 `requirements.txt` 納入版本控制(例如 Git),但排除虛擬環境資料夾(在 `.gitignore` 中加入 `myenv/` 或 `venv/`)。

   - 可為不同環境(開發、測試、正式)維護多個 `requirements` 檔案,例如 `requirements-dev.txt` 和 `requirements-prod.txt`。


---


### **三、常見問題與解決方法**


1. **問題:套件安裝失敗,提示缺少編譯工具**  

   - **解決**:安裝必要的編譯工具。例如:

     - Windows:下載 Microsoft Visual C++ Build Tools。

     - Linux:安裝 `build-essential`(Ubuntu)或 `gcc`(CentOS)。

     - macOS:安裝 Xcode Command Line Tools (`xcode-select --install`)。


2. **問題:套件版本在新環境中不可用**  

   - **解決**:檢查 PyPI 是否已移除該版本,或使用 `--index-url` 指定備用鏡像源。若仍失敗,可嘗試放寬版本要求(編輯 `requirements.txt`,移除 `==` 改用 `>=`)。


3. **問題:Jupyter Notebook 無法使用新環境**  

   - **解決**:在目標環境中安裝 `ipykernel` 並註冊:

     ```bash

     pip install ipykernel

     python -m ipykernel install --user --name=myenv

     ```


4. **問題:專案運行時缺少非 Python 依賴**  

   - **解決**:檢查是否有外部依賴(如資料庫、Redis、系統庫),並在新電腦上安裝。例如,安裝 `libpq-dev` 以支援 `psycopg2`。


---


### **四、進階建議**


1. **使用 `pipdeptree` 檢查依賴**  

   - 安裝 `pipdeptree` 查看依賴樹,確保 `requirements.txt` 不包含冗餘套件:

     ```bash

     pip install pipdeptree

     pipdeptree

     ```


2. **鎖定依賴版本**  

   - 使用 `pip-tools` 生成更嚴格的 `requirements.txt`:

     ```bash

     pip install pip-tools

     pip-compile requirements.in > requirements.txt

     ```

     - `requirements.in` 可列出主要依賴,`pip-compile` 會自動解析子依賴。


3. **容器化替代方案**  

   - 如果環境複雜或跨平台需求高,考慮使用 Docker 容器化專案,確保環境完全一致。


4. **自動化部署**  

   - 在 CI/CD 流程中,撰寫腳本自動創建虛擬環境並安裝依賴,例如:

     ```bash

     python -m venv venv

     source venv/bin/activate

     pip install -r requirements.txt

     ```


---


### **總結**


使用 `requirements.txt` 可以在目標電腦上重建一致的 Python 虛擬環境。關鍵是確保 Python 版本一致、正確傳輸 `requirements.txt`、並處理作業系統差異。遵循上述步驟和注意事項,能最大程度減少環境重建的問題。若專案複雜,考慮進階工具如 `pip-tools` 或 Docker,以提高環境的可重現性。

python venv 怎麼使用、注意事項、限制

 Python 的 `venv` 模組是用來建立和管理虛擬環境的工具,能為每個專案創建隔離的 Python 環境,避免套件衝突。以下是使用方式、注意事項和限制的詳細說明:


---


### **一、如何使用 `venv`**


1. **創建虛擬環境**  

   使用 `python -m venv <環境名稱>` 命令來創建虛擬環境。例如:

   ```bash

   python -m venv myenv

   ```

   - 這會在當前目錄下創建一個名為 `myenv` 的資料夾,包含獨立的 Python 執行檔和 `pip`。

   - 通常將虛擬環境放在專案目錄內,例如 `./venv` 或 `./env`。


2. **啟動虛擬環境**  

   啟動後,命令列會切換到該虛擬環境,使用的 Python 和 `pip` 會是環境內的版本。根據作業系統,命令如下:

   - **Windows**:

     ```bash

     myenv\Scripts\activate

     ```

   - **macOS/Linux**:

     ```bash

     source myenv/bin/activate

     ```

   - 啟動後,命令列提示符會顯示 `(myenv)`,表示已進入虛擬環境。


3. **安裝套件**  

   在虛擬環境中,使用 `pip` 安裝套件,這些套件僅安裝在當前環境中,不影響系統全局。例如:

   ```bash

   pip install requests

   ```

   - 可以用 `pip list` 查看已安裝的套件。

   - 建議使用 `requirements.txt` 記錄依賴:

     ```bash

     pip freeze > requirements.txt

     ```

     其他環境可透過 `pip install -r requirements.txt` 還原套件。


4. **退出虛擬環境**  

   輸入以下命令退出虛擬環境:

   ```bash

   deactivate

   ```


5. **刪除虛擬環境**  

   直接刪除虛擬環境資料夾即可,例如:

   ```bash

   rm -rf myenv  # Linux/macOS

   rmdir /s myenv  # Windows

   ```


---


### **二、注意事項**


1. **選擇正確的 Python 版本**  

   - 創建虛擬環境時,使用的 Python 版本取決於執行 `python -m venv` 的 Python 版本。確保使用正確的 Python(例如 `python3` 或特定版本如 `python3.8`)。

   - 可透過 `python --version` 確認當前使用的 Python 版本。


2. **虛擬環境是獨立的**  

   - 虛擬環境不包含系統全局的套件,除非明確安裝。例如,系統已安裝 `numpy`,但虛擬環境中需要重新安裝。

   - 若需要使用系統套件,可在創建時加上 `--system-site-packages`:

     ```bash

     python -m venv myenv --system-site-packages

     ```


3. **跨平台注意**  

   - 虛擬環境與作業系統和 Python 版本綁定,不能直接在不同作業系統間共用。例如,Windows 創建的環境無法在 Linux 上使用。

   - 若需跨平台,建議分享 `requirements.txt`,在目標系統重新創建環境。


4. **環境路徑管理**  

   - 虛擬環境的路徑不宜過長,特別在 Windows 上,因其有檔案路徑長度限制(約 260 字元)。

   - 避免將虛擬環境放在會被頻繁移動的目錄(如雲端同步資料夾),可能導致路徑損壞。


5. **升級 `pip`**  

   - 虛擬環境中的 `pip` 可能不是最新版本,建議啟動環境後立即升級:

     ```bash

     pip install --upgrade pip

     ```


6. **版本控制**  

   - 不要將虛擬環境資料夾(例如 `venv/`)加入 Git 等版本控制系統,通常只提交 `requirements.txt`。

   - 在 `.gitignore` 中加入 `venv/` 或 `env/`。


---


### **三、限制**


1. **不支援多版本 Python 切換**  

   - `venv` 僅使用創建時的 Python 版本。若需在同一環境中使用不同版本的 Python,需使用其他工具如 `pyenv` 或 `conda`。


2. **不支援全局套件管理**  

   - `venv` 無法直接管理系統級的 Python 套件,若需全局管理,需使用系統的 `pip` 或其他工具。


3. **不支援環境複製**  

   - 無法直接複製虛擬環境到其他目錄或機器,需重新創建並安裝依賴。


4. **依賴解析較弱**  

   - `venv` 的 `pip` 不像 `poetry` 或 `pipenv` 那樣有強大的依賴解析功能,可能在複雜專案中遇到版本衝突問題。


5. **資源占用**  

   - 每個虛擬環境都包含獨立的 Python 執行檔和標準庫,會占用一定磁碟空間(通常幾十 MB)。


---


### **四、進階使用**


1. **環境變數管理**  

   - 可以在虛擬環境的啟動腳本(如 `myenv/bin/activate` 或 `myenv\Scripts\activate.bat`)中加入環境變數,方便專案配置。

   - 例如,設定 `PYTHONPATH` 或自訂變數。


2. **與 IDE 整合**  

   - 大多數 IDE(如 VSCode、PyCharm)能自動偵測 `venv` 環境,選擇虛擬環境作為解釋器即可。


3. **使用 `venv` 進行測試**  

   - 可為不同測試場景創建多個虛擬環境,模擬不同套件版本或依賴。


4. **搭配其他工具**  

   - 若需更強大的環境管理,可結合 `pyenv`(管理 Python 版本)或 `poetry`(管理依賴和打包)。


---


### **五、常見問題**


- **Q: 為什麼啟動虛擬環境後仍使用全局 Python?**  

  A: 可能是路徑配置錯誤,檢查環境變數 `PATH` 是否優先指向虛擬環境的 `bin` 或 `Scripts` 目錄。


- **Q: 如何在 Jupyter Notebook 使用虛擬環境?**  

  A: 安裝 `ipykernel` 並註冊虛擬環境:

  ```bash

  pip install ipykernel

  python -m ipykernel install --user --name=myenv

  ```


- **Q: 如何在 CI/CD 中使用 `venv`?**  

  A: 在 CI/CD 腳本中,創建虛擬環境並用 `requirements.txt` 安裝依賴,確保一致性。


---


### **總結**


`venv` 是 Python 官方提供的輕量級虛擬環境工具,適合大多數專案需求。使用簡單,但功能相對基礎,適合需要隔離環境但不要求複雜依賴管理的場景。若需更進階的功能,可考慮 `conda`、`poetry` 或 `pipenv`。遵循上述注意事項,能有效避免常見問題並提高開發效率。

2025年7月8日 星期二

Install Google Chrome Remote Desktop on Ubuntu 24.04

 Learn how to install and configure Google Chrome Remote Desktop on Ubuntu 24.04 with this comprehensive step-by-step guide. Ensure secure and efficient remote access to your Ubuntu system from anywhere. Follow our detailed instructions and troubleshooting tips to get started.

Introduction

Remote desktop applications have revolutionized how we access and control computers from distant locations. Among these applications, Google Chrome Remote Desktop stands out due to its ease of use, reliability, and cross-platform support. This guide will walk you through the process of installing Google Chrome Remote Desktop on Ubuntu 24.04. Whether you’re a beginner or a seasoned Linux user, this comprehensive tutorial will ensure you have remote access up and running in no time.


Why Use Google Chrome Remote Desktop?

Before diving into the installation process, it’s crucial to understand why Google Chrome Remote Desktop is a preferred choice for many:

  • Cross-Platform Compatibility: It works seamlessly on Windows, macOS, Linux, and Chrome OS.
  • Security: Uses a secure connection and encryption to protect your data.
  • Free to Use: Unlike many remote desktop solutions, it is completely free.
  • Ease of Use: Simple to set up and use, even for non-technical users.

Prerequisites

To begin with, ensure you have the following:

  1. Google Chrome Browser: Google Chrome Remote Desktop requires the Chrome browser.
  2. Google Account: You’ll need a Google account to use this service.
  3. Terminal Access: Basic knowledge of using the terminal is necessary.

Google Chrome Remote Desktop on Ubuntu 24.04: Step-by-Step Guide

First things first, update your Ubuntu machine:

sudo apt update -y && sudo apt upgrade -y

Step 1: Install Google Chrome

Next, you’ll need to install the Google Chrome browser on your Ubuntu 24.04 system. Open your terminal and follow these commands:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
wget https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get install -f

The above commands will download and install the latest version of Google Chrome. The -f option in the last command fixes any dependency issues.

Chrome Remote Desktop on Ubuntu 24.04

Photo by admingeek from Infotechys

Step 2: Install Google Chrome Remote Desktop

Next, you need to add the Chrome Remote Desktop extension to your browser. Open Google Chrome and visit the Chrome Web Store. Search for “Chrome Remote Desktop” and add the extension to your browser.

Alternatively, you can use the following link to directly add the extension: Chrome Remote Desktop Extension.

Chrome Remote Desktop on Ubuntu 24.04
Click Chrome Web Store Icon
Chrome Remote Desktop on Ubuntu 24.04
Google Chrome Web Store Page
Chrome Remote Desktop on Ubuntu 24.04
Select Chrome Remote Desktop
Google Chrome Remote Desktop Extension Installed
Chrome Remote Desktop Extension Installed

Photo by admingeek from Infotechys

Step 3: Set Up Remote Desktop on Google Chrome

After installing the extension, follow these steps to set up remote access:

  • Open a new tab in Google Chrome and go to remotedesktop.google.com/access.
  • Click this Download link to download the Debian package for Chrome Remote Desktop.
  • Open your terminal and navigate to the download location. Then, install the package using:
sudo dpkg -i chrome-remote-desktop_current_amd64.deb

Step 4: Enable Remote Desktop Access

To enable remote desktop access, you may need to install and configure a desktop environment if you’re using a server version of Ubuntu without a GUI. Here’s how you can install the Xfce desktop environment:

sudo apt-get install xfce4 xfce4-goodies
sudo apt-get install -f
  • After installation, set Xfce as the default desktop environment for Chrome Remote Desktop:
sudo vim /etc/chrome-remote-desktop-session
  • Replace the content with (then, save and close the file):
exec /usr/sbin/lightdm-session 'xfce4-session'
  • Now reboot your machine:
sudo systemctl reboot

Step 5: Configure Remote Desktop

To configure Chrome Remote Desktop, follow these steps (from another Google Chrome Browser on another machine):

Setup another computer screen

Photo by admingeek from Infotechys

  • Click the Begin button to continue.
Remote Desktop Computer Setup Process: Part 2

Photo by admingeek from Infotechys

  • Now, click the Next button to continue.
Remote Desktop Computer Setup Process: Part 3

Photo by admingeek from Infotechys

  • Then, click the Authorize button to continue.
Remote Desktop Computer Setup Process: Part 4

Photo by admingeek from Infotechys

  • Copy the text under the Debian Linux textbox and paste it to the terminal on your Ubuntu 24.04 machine.
Remote Desktop Computer Setup Process: Part 5

Photo by admingeek from Infotechys

  • Press the Enter key to continue. You’ll be prompted to enter a six-digit PIN. You will need this later to remote to your Ubuntu machine after the installation completes.

Using Google Chrome Remote Desktop

Once the setup is complete, you can access your Ubuntu 24.04 system from any device with the Chrome browser and Chrome Remote Desktop extension installed. Here’s how you can connect:

Open Chrome and navigate to remotedesktop.google.com/access
Remote Desktop Computer Setup Process: Part 6

Photo by admingeek from Infotechys

Sign in with the same Google account used for setting up remote desktop.
Remote Desktop Computer Setup Process: Part 7

Photo by admingeek from Infotechys

You will see the computer name of your Ubuntu machine you set up earlier. Click on it.
Remote Desktop Computer Setup Process: Part 8

Photo by admingeek from Infotechys

Enter the PIN you created to start the remote session.

And, you’re done! You’ve now gained remote desktop access to your Ubuntu 24.04 machine.

Remote Desktop Computer Setup Process: Part 9

Photo by admingeek from Infotechys

Troubleshooting Common Issues

Even with the best instructions, issues can arise. Here are some common problems and solutions:

Problem: Unable to Start the Chrome Remote Desktop Service

Solution: Check the status of the service with:

sudo service chrome-remote-desktop start

If the service isn’t active, try restarting it:

sudo systemctl restart chrome-remote-desktop

Problem: Black Screen After Connecting

Solution: This issue often occurs due to a missing or misconfigured desktop environment. Ensure that Xfce is installed correctly and set as the default session in the /etc/chrome-remote-desktop-session file.

Problem: Connection Timeout

Solution: Ensure that your internet connection is stable. You may also need to check your firewall settings to ensure that Chrome Remote Desktop is allowed.


Advantages of Using Google Chrome Remote Desktop

Security

One of the primary concerns with remote desktop applications is security. Chrome Remote Desktop uses a secure SSL connection and requires a PIN to access your system, ensuring that your data remains protected.

Performance

Chrome Remote Desktop offers smooth performance with minimal lag, even over slower internet connections. This makes it an ideal choice for accessing your desktop applications from anywhere.


Conclusion

Google Chrome Remote Desktop is an excellent tool for anyone needing remote access to their Ubuntu 24.04 system. By following this step-by-step guide, you can easily set up and configure remote desktop access, ensuring you have control over your system from anywhere. With its robust security features and seamless performance, it’s a reliable choice for both personal and professional use.

Did you find this article useful? Your feedback is invaluable to us! Please feel free to share your thoughts in the comments section below.

資料來源:https://infotechys.com/chrome-remote-desktop-on-ubuntu-24-04/