DEV Community

Jain Wun
Jain Wun

Posted on

4 4

在GCP VM上開發Python


在GCP VM上開發Python

GCP預設是不會像oracle cloud/ azure幫你產生好private key

GCP Debian/ Ubuntu VM內預設都沒裝iptables,所以就不像oracle cloud的要特別去設定

Generate SSH Key Pair

可以自行幫私鑰取名 (建議用WSL2建,powershell/ cmd可能會有路徑問題)

ssh-keygen -t rsa -f ~/.ssh/[KEY_FILENAME]
Enter fullscreen mode Exit fullscreen mode

Passphrase可以避免私鑰被拿走就能登入,但是每次登入就要打密碼

先複製一下對應公鑰 (複製到等號前、含等號)

cat ~/.ssh/[key_filename].pub
Enter fullscreen mode Exit fullscreen mode

先暫時保留以下的結果

ssh-rsa [KEY VALUE] [USER_NAME]
Enter fullscreen mode Exit fullscreen mode

GCP VM Setting

不一定要用預設給的username,可以自己創過

到現有VM的設定內去找SSH Key

然後透過add item來放剛剛暫存的key-value pair

image.png

打username就好,不需要加上email

Terminal

ssh -i <key_name> <username>@<gcp_ip>
Enter fullscreen mode Exit fullscreen mode

如果用WSL2創的,實際key會在\\wsl$\Ubuntu-18.04\root\.ssh

Pycharm

Interpreter

Pycharm是我個人最常用的IDE,這裡示範直接在Pycharm中透過SSH使用GCP VM

在Pycharm就是去設定SSH Interpreter (可以順便設定Remote Host方便傳檔案)

Default interpreter (conda-forge)會在/opt/conda/bin/python

image.png

如果想用VScode連進去,也是相同的道理

Files

要在遠端server上跑code當然必須要上傳data以及code

在剛剛設定interpreter時有設定對應server路徑,上傳到那個位置即可

image.png


Reference

Google Cloud Platform (GCP) - How To SSH into your VM

Remote Coding with PyCharm and Google Cloud - DoiT International

Using GCP With PyCharm

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more