一键重装系统工具 | U盘启动盘制作工具 | 误删文件恢复软件 | 硬盘数据抢救专家 | 电脑蓝屏修复助手 | C盘空间清理神器 | 电脑驱动离线安装工具 | 微信聊天记录恢复工具 | 照片误格式化恢复 | 电脑密码破解清除工具 | 系统崩溃紧急救援盘 | 电脑加速优化大师 | 电脑开不了机怎么重装系统 | 回收站清空了怎么恢复 | 硬盘分区丢失数据恢复 | 电脑卡顿重装系统有用吗 | U盘插入提示格式化数据恢复 | 电脑中毒文件被隐藏恢复 | 忘记电脑开机密码怎么办 | 新硬盘分区对齐工具 | 旧电脑装Win10流畅工具 | SD卡照片删除恢复免费版 | 移动硬盘打不开提示损坏修复 | 电脑无故重启系统修复工具 | 电脑小白一键重装神器 | 程序员电脑环境配置助手 | 设计师电脑字体/素材恢复工具 | 网吧网管系统维护工具箱 | 财务人员电脑发票备份恢复 | 学生党免费电脑系统安装包 | 电脑维修师傅必备工具盘 | 游戏玩家电脑性能优化助手 | 办公白领误删文档恢复软件 | 自媒体视频素材恢复工具 | 网课录制视频损坏修复工具 | 最好的U盘PE系统排名 | 数据恢复软件哪个最强 | 免费电脑助手与收费版区别 | 国产装机工具哪款无广告 | 离线版驱动助手推荐 | 轻量级电脑优化工具对比 | 支持NVMe驱动的PE工具 | 带网络功能的应急启动盘 | 2026最新版万能装机工具 | 支持Win11 24H2的PE工具 | 最新免激活系统重装工具 | 2026数据恢复软件破解版合集 | 纯净无捆绑装机助手V3.0 | 支持苹果M芯片的电脑助手 | 秋季更新版系统维护工具箱 | 电脑系统崩了怎么用U盘把重要资料拷贝出来 | 重装系统前哪些文件夹必须备份 | 固态硬盘误格式化还能恢复数据吗 | 如何制作一个既带PE又能存数据的双分区U盘 | 电脑总是弹窗广告用什么助手彻底拦截 后台管理
📢 欢迎访问系统之家!所有资源均经过安全检测。

學習: 細分類:VS Code

发布时间:2026-09-10 | 浏览:2
📥 下载地址(文章开头)
装机神器,专门安装各种电脑系统,各种品牌全可以。
VS Code 的使用者設定與鍵盤綁定 這個 Zsh 腳本的作用是自動安裝 VS Code 擴充功能,並設定 VS Code 的使用者設定與鍵盤綁定。以下是對每個步驟的詳細解釋: ## 1. **確保 Homebrew 的 bin 目錄在 PATH 變數中** if [ -x "/opt/homebrew/bin/brew" ] && [[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]; then export PATH="/opt/homebrew/bin:$PATH" - Homebrew 是 macOS 上的套件管理工具,安裝的程式通常位於 `/opt/homebrew/bin`(適用於 Apple Silicon Mac)。 - `-x "/opt/homebrew/bin/brew"` 檢查 Homebrew 是否已安裝(檢查 `brew` 指令是否可執行)。 - `[[ ":$PATH:" != *":/opt/homebrew/bin:"* ]]` 檢查 `PATH` 環境變數中是否已包含 Homebrew 的 bin 目錄,避免重複加入。 - `export PATH="/opt/homebrew/bin:$PATH"` 將 Homebrew 加入 `PATH`,確保可以執行 `brew` 指令。 ## 2. **安裝 VS Code 擴充功能** batisteo.vscode-django charliermarsh.ruff esbenp.prettier-vscode formulahendry.code-runner foxundermoon.shell-format mechatroner.rainbow-csv monosans.djlint ms-python.python ms-toolsai.jupyter ms-vscode.theme-predawnkit mtxr.sqltools-driver-sqlite ritwickdey.LiveServer tamasfe.even-better-toml - 定義一組要安裝的 VS Code 擴充功能。 - 這些擴充功能包括 Python、Django、SQL、Prettier、美化 shell、LiveServer 以及其他開發工具。 installed_extensions=$(code --list-extensions) - 取得目前已安裝的 VS Code 擴充功能清單。 for extension in "${extensions[@]}"; do if echo "$installed_extensions" | grep -qi "^$extension$"; then echo "$extension is already installed. Skipping..." echo "Installing $extension..." code --install-extension "$extension" - 迴圈檢查是否已安裝該擴充功能: - `grep -qi "^$extension$"`:檢查 `installed_extensions` 是否已經包含該擴充功能。 - 如果未安裝,則使用 `code --install-extension` 來安裝。 echo "VS Code extensions have been installed." - 顯示所有擴充功能已安裝的訊息。 ## 3. **設定 VS Code 的使用者設定與鍵盤綁定** VSCODE_USER_SETTINGS_DIR="${HOME}/Library/Application Support/Code/User" - 定義 VS Code 設定檔的目錄,VS Code 會在這個目錄儲存 `settings.json` 和 `keybindings.json`。 if [ -d "$VSCODE_USER_SETTINGS_DIR" ]; then - 確保這個目錄存在,避免錯誤。 ln -sf "${HOME}/dotfiles/settings/VSCode-Settings.json" "${VSCODE_USER_SETTINGS_DIR}/settings.json" ln -sf "${HOME}/dotfiles/settings/VSCode-Keybindings.json" "${VSCODE_USER_SETTINGS_DIR}/keybindings.json" - 使用 `ln -sf` 建立軟連結: - `-s`(symbolic link):建立符號連結,讓 `VSCode-Settings.json` 和 `VSCode-Keybindings.json` 指向目標檔案。 - `-f`(force):如果檔案已存在,則強制覆寫。 - `settings.json`:用來設定 VS Code 的各種行為,如字體大小、主題、格式化工具等。 - `keybindings.json`:用來設定自訂快捷鍵。 echo "VS Code settings and keybindings have been updated." echo "VS Code user settings directory does not exist. Please ensure VS Code is installed." - 如果設定目錄不存在,提示使用者檢查 VS Code 是否已安裝。 ## 4. **開啟 VS Code 並提醒登入擴充功能** - 開啟當前目錄的 VS Code,讓使用者登入擴充功能(如 Copilot、Grammarly)。 echo "Login to extensions (Copilot, Grammarly, etc) within VS Code." - 提醒使用者登入需要驗證的擴充功能。 echo "Press enter to continue..." - 等待使用者按下 Enter,以確保他們有時間登入擴充功能後再繼續執行其他操作。 1. **確保 Homebrew 的 bin 目錄在 `PATH` 中**,確保可執行 `brew` 指令。 2. **檢查並安裝 VS Code 擴充功能**,避免重複安裝。 3. **設定 VS Code 的 `settings.json` 和 `keybindings.json`**,確保使用者的自訂設定生效。 4. **開啟 VS Code 並提醒登入擴充功能**,確保 Copilot、Grammarly 等需要驗證的擴充功能可用。 這樣的自動化設定適合需要快速部署 VS Code 環境的開發者,讓新機器可以立即擁有一致的開發環境。 安裝 Visual Studio Code (VS Code):詳細說明每個步驟 好的,我將從影片中的第1部分開始,依照影片的內容逐字翻譯。請注意,這會依照影片時間範圍逐段翻譯,並忠實呈現內容。 1. 安裝 Visual Studio Code (VS Code):詳細說明每個步驟 影片時間範圍:00:00-02:26 "In this video, I'm going to show you how to set up Python development in Visual Studio Code, or VS Code, which is one of the most popular code editors out there. So, we're going to install VS Code, configure it for Python, and go over some of the key features you should know to get started quickly. First, let's go ahead and install Visual Studio Code. So, go to the website code.visualstudio.com. It's the official website for VS Code. Once you're there, you’ll see the button to download VS Code. Go ahead and click on it. It will automatically detect your operating system, so you don’t have to choose. Just download it. After the download is complete, go ahead and run the installer. The installation process is pretty straightforward. Just go through the steps. Click 'Next' and accept the license agreement. You can choose the installation location if you want, or you can leave it at the default location. Once the installation is complete, you can open Visual Studio Code. You’ll see the welcome screen, and that’s how you know everything was installed correctly." "在這個影片中,我將展示如何在 Visual Studio Code,或稱 VS Code 中設置 Python 開發環境。VS Code 是目前最受歡迎的程式碼編輯器之一。所以,我們將安裝 VS Code,為 Python 做設置,並介紹一些你需要知道的關鍵功能,讓你可以快速入門。 首先,我們來安裝 Visual Studio Code。請前往網站 code.visualstudio.com。這是 VS Code 的官方網站。當你進入網站後,你會看到下載 VS Code 的按鈕。點擊它,它會自動偵測你的作業系統,因此你不需要選擇作業系統。直接下載即可。 下載完成後,請運行安裝程式。安裝過程相當簡單,依照步驟進行。點擊「下一步」並接受授權協議。你可以選擇安裝位置,或者你也可以保留預設的安裝位置。 安裝完成後,你可以打開 Visual Studio Code。你會看到歡迎螢幕,這樣就知道安裝成功了。" 這是第一部分的逐字翻譯。如果你希望繼續進行後續部分的逐字翻譯,請告訴我! 好的,接下來是第2部分的逐字翻譯。 2. VS Code 介面概述:安裝後,VS Code 會顯示歡迎畫面、檔案瀏覽器、搜尋功能,以及 Git 整合。影片中還介紹了如何打開專案資料夾並使用原始碼控制面板。 影片時間範圍:02:26-03:59 "Once you've installed Visual Studio Code and opened it up, you’ll be greeted with the welcome screen. The welcome screen gives you some helpful links to get started with VS Code, including links to documentation, tutorials, and videos. Over on the left side of the screen, you’ll see the Activity Bar, which gives you access to different views like the Explorer, Search, Source Control, Extensions, and more. Let’s go ahead and start with the Explorer view. The Explorer view is where you can open your project files and navigate your file system. You can also use it to open folders and work with files. Now, over on the right side, you’ll see the editor area. This is where you can open files and start writing code. You can have multiple files open at once in tabs. You also have the Search bar at the top, which allows you to search through your files for specific text, and you can also filter by file types. Finally, at the bottom of the screen, you’ll see the Status Bar. The status bar gives you information about your current project, including the current branch you're working on in Git, the current language mode, and more." "安裝完 Visual Studio Code 並打開後,你會看到歡迎畫面。這個歡迎畫面提供了一些幫助性的連結,讓你可以快速開始使用 VS Code,包括連結到文件、教學和影片。 在螢幕的左邊,你會看到活動欄,它提供了對不同視圖的存取,例如檔案瀏覽器、搜尋、原始碼控制、擴充功能等。我們先從檔案瀏覽器視圖開始。 檔案瀏覽器視圖是你可以打開專案檔案並瀏覽檔案系統的地方。你也可以使用它來開啟資料夾並處理檔案。 現在,螢幕的右邊是編輯區域。這裡是你可以開啟檔案並開始編寫程式碼的地方。你可以同時開啟多個檔案,並將它們顯示在標籤頁中。 你還可以看到上方的搜尋欄,讓你能夠在檔案中搜尋特定的文字,並可以依檔案類型過濾搜尋結果。 最後,在螢幕的下方,你會看到狀態列。狀態列會顯示你當前專案的資訊,包括你在 Git 中所使用的分支、當前語言模式等資訊。" 這是第二部分的逐字翻譯。如果你需要繼續進行後續部分的翻譯,請隨時告訴我! 好的,接下來是第3部分的逐字翻譯。 3. 安裝 Python 擴充功能:Python 擴充功能是 VS Code 中最受歡迎的擴充功能,它提供了 Python 相關的功能,包括選擇 Python 解譯器和語法檢查。 影片時間範圍:06:09-07:48 "Now that you’ve got VS Code installed, we want to go ahead and install the Python extension. To do that, we’ll go over to the Extensions view, which you can access by clicking on the Extensions icon in the Activity Bar on the left-hand side. This will open up the Extensions view, and from here you can search for the Python extension. Just type in ‘Python’ in the search box, and the first result that comes up will be the official Python extension from Microsoft. This is the one we want, so go ahead and click the Install button. Once the extension is installed, you’ll see a confirmation in the status bar at the bottom of the screen that the Python extension is now active. You’ll also notice that you have some additional options available in the Command Palette, which you can access by pressing Ctrl + Shift + P on your keyboard." "現在你已經安裝了 VS Code,我們接著要安裝 Python 擴充功能。首先,我們要打開擴充功能視圖,你可以通過點擊左邊活動欄中的擴充功能圖示來進入這個視圖。 這樣會打開擴充功能視圖,在這裡你可以搜尋 Python 擴充功能。只需在搜尋框中輸入『Python』,第一個出現的結果就是 Microsoft 的官方 Python 擴充功能。這就是我們要的,所以請點擊安裝按鈕。 當擴充功能安裝完成後,你會看到在螢幕底部的狀態列顯示確認訊息,告訴你 Python 擴充功能已經啟用。你還會注意到在命令面板中有一些額外的選項,命令面板可以通過按下鍵盤上的 Ctrl + Shift + P 來開啟。" 這是第三部分的逐字翻譯。如果你需要繼續進行後續部分的翻譯,請隨時告訴我! 好的,這是第4部分的逐字翻譯: 4. 設定 Python 解譯器:示範如何更改 Python 解譯器,並展示 VS Code 如何為專案創建特定的 .vscode/settings.json 設定檔。 影片時間範圍:07:49-09:44 "Now that the Python extension is installed, we want to make sure that VS Code is using the correct Python interpreter. To do that, we can go to the Command Palette by pressing Ctrl + Shift + P and then searching for ‘Python: Select Interpreter’. This will bring up a list of available Python interpreters. Here, you can choose which version of Python you want to use for your project. You might have multiple versions of Python installed on your system, so it’s important to select the right one. For example, I have Python 3.8 installed, and I can select that as the interpreter for this project. Once you’ve selected the interpreter, VS Code will automatically create a .vscode/settings.json file in your project folder. This file will store the Python interpreter settings specifically for this project. You can also verify the selected interpreter by looking at the bottom left corner of the window, where the current interpreter will be displayed. If you ever need to change it, you can go back to the Command Palette and select a different one." "現在 Python 擴充功能已經安裝完成,我們要確保 VS Code 使用的是正確的 Python 解譯器。為此,我們可以按下 Ctrl + Shift + P 打開命令面板,然後搜尋『Python: Select Interpreter』。 這樣會顯示一個可用 Python 解譯器的清單。在這裡,你可以選擇你要在專案中使用的 Python 版本。你可能在系統中安裝了多個版本的 Python,所以選擇正確的版本非常重要。 例如,我安裝了 Python 3.8,並且可以將其選為此專案的解譯器。當你選擇了解譯器後,VS Code 會自動在你的專案資料夾中創建一個 .vscode/settings.json 檔案,該檔案將專門存儲此專案的 Python 解譯器設置。 你也可以通過查看視窗左下角來確認選擇的解譯器,當前的解譯器會顯示在這裡。如果你以後需要更改解譯器,隨時可以回到命令面板並選擇另一個解譯器。" 這是第四部分的逐字翻譯。如果你還需要更多後續內容的翻譯,隨時告訴我! 好的,這是第5部分的逐字翻譯: 5. 自訂介面(顏色主題和圖示):使用者自訂編輯器的外觀,選擇像是 Pre-Dawn 主題,並調整其他 UI 設定,如檔案圖示。 影片時間範圍:14:00-16:16 "Now that we’ve got the basics set up, let’s go ahead and make some customizations to the editor’s look and feel. First, I’m going to change the color theme of the editor. To do this, I’ll press Ctrl + Shift + P to open the Command Palette, and I’m going to search for ‘Color Theme’. You’ll see a list of different color themes that you can choose from, and I’m going to select ‘Pre-Dawn’ for this project. You can select whichever theme suits you best. Once you’ve selected the theme, the entire editor will change to reflect that color scheme. As you can see, the background and text have changed, and now it’s a lot darker, which helps with reducing eye strain during long coding sessions. In addition to the color theme, you can also change the file icon theme. To do that, I’ll again go to the Command Palette and search for ‘File Icon Theme’. This will give me a list of available icon themes. For this project, I’ll select the ‘Material Icon Theme’, which will change the way files and folders are displayed in the Explorer view. You can choose whichever icon theme you prefer, whether it’s ‘Material Icon Theme’, ‘Seti Icons’, or another theme." "現在我們已經完成了基本設置,接下來讓我們對編輯器的外觀做一些自訂。首先,我要更改編輯器的顏色主題。 為此,我會按下 Ctrl + Shift + P 打開命令面板,並搜尋『Color Theme』。你會看到一個可以選擇的顏色主題清單,我會選擇『Pre-Dawn』作為此專案的主題。你可以選擇任何你喜歡的主題。 當你選擇了主題後,整個編輯器的外觀就會根據該顏色方案進行更改。正如你所看到的,背景和文字已經改變,現在變得更暗了,這樣在長時間編程時有助於減少眼睛疲勞。 除了顏色主題外,你還可以更改檔案圖示主題。為此,我會再次進入命令面板,並搜尋『File Icon Theme』。 這會顯示一個可用圖示主題的清單。對於此專案,我會選擇『Material Icon Theme』,這會改變檔案和資料夾在檔案總管中的顯示方式。你可以根據自己的喜好選擇任何圖示主題,無論是『Material Icon Theme』、『Seti Icons』還是其他主題。" 這是第五部分的逐字翻譯。如果還需要更多後續部分,請告訴我! 好的,這是包含 "Ayu" 顏色主題的部分翻譯: "In addition to Pre-Dawn, there’s also the ‘Ayu’ color theme, which is a bit more vibrant and has a different feel compared to Pre-Dawn. To change the theme to ‘Ayu’, I’m going to press Ctrl + Shift + P again, and this time, I’ll search for ‘Color Theme’ once more. When the list of themes shows up, I’ll scroll down and select ‘Ayu’ from the list. As you can see, the editor will change once again to a brighter, more vivid color scheme. It has a bit of a warmer tone compared to ‘Pre-Dawn’, which some people might find more visually appealing. The ‘Ayu’ theme is one of the options I like, but there are many others to choose from. You can always experiment with different themes to find one that works best for you." "除了 Pre-Dawn 主題外,還有‘Ayu’ 顏色主題,它比 Pre-Dawn 更加鮮豔,感覺也不同於 Pre-Dawn。要將主題更改為‘Ayu’,我會再次按下 Ctrl + Shift + P ,然後這次再次搜尋‘Color Theme’。 當顯示出主題清單時,我會向下滾動並從列表中選擇 ‘Ayu’。如你所見,編輯器將再次改變為一種更明亮、更生動的顏色方案。與‘Pre-Dawn’相比,它有一點較溫暖的色調,有些人可能會覺得它視覺上更具吸引力。 ‘Ayu’ 主題是我喜歡的選項之一,但還有許多其他選擇。你可以隨時嘗試不同的主題,找到最適合自己的那一款。" 這是關於 "Ayu" 顏色主題的逐字翻譯。如果還需要進一步的內容,隨時告訴我! 好的,這是第6部分 "Managing Code Formatting and Linters" 的影片操作內容逐字翻譯: "Now that we have installed the Python extension, let’s move on to setting up code formatting and linters. We want our Python code to be clean and consistent, and there are a couple of tools that will help us do that. First, we’re going to set up Black for auto-formatting. Black is a very popular code formatter for Python, and it will automatically format our code every time we save the file. So to install Black, we need to open the terminal in VS Code, which we can do by going to View and selecting Terminal , or by pressing Ctrl + \ as a shortcut. Once the terminal is open, we’ll install Black by typing the following command: After Black is installed, we’ll need to set it as the default formatter for VS Code. To do this, we’ll press Ctrl + Shift + P to open the command palette and search for Preferences: Open Settings (JSON) . This will open the settings.json file. In the settings, we want to add the following line of code: Now, Black is set up as the default formatter. The next step is to configure auto-formatting on save. So we’ll add another line to our settings.json file: This will make it so that every time we save the file, VS Code will automatically format it using Black. Now, let’s test it by creating a Python file, writing some unformatted code, and then saving the file. When we save it, VS Code will automatically format the code for us. Next, we’ll set up linting using Pylint. Linting will check our code for errors and stylistic issues as we write it, helping us catch problems early. To install Pylint, we’ll go back to the terminal and type: Once Pylint is installed, we need to configure VS Code to use it for linting. We’ll press Ctrl + Shift + P again to open the command palette and search for Python: Select Linter . This will bring up a list of available linters, and we’ll choose Pylint from the list. Now, Pylint is set up. If we write some Python code that has a style or syntax issue, Pylint will highlight it with a warning or error in the editor. This will help us keep our code clean and avoid common mistakes." "現在我們已經安裝了 Python 擴展,接下來我們要設置代碼格式化和 Linter。我們希望 Python 代碼乾淨且一致,這裡有一些工具可以幫助我們做到這一點。 首先,我們將設置 Black 來進行自動格式化。Black 是一個非常受歡迎的 Python 代碼格式化工具,它會在每次保存文件時自動格式化我們的代碼。因此,要安裝 Black,我們需要在 VS Code 中打開終端,可以通過 View 選擇 Terminal 或按 Ctrl + \ 快捷鍵來打開。 終端打開後,我們通過輸入以下命令來安裝 Black: 安裝完 Black 之後,我們需要將其設置為 VS Code 的默認格式化工具。為此,我們將按 Ctrl + Shift + P 打開命令面板,並搜尋 Preferences: Open Settings (JSON) 。 這會打開 settings.json 文件。在設定中,我們需要添加以下代碼行: 現在,Black 被設置為默認的格式化工具。接下來的步驟是配置保存時自動格式化。所以,我們將在 settings.json 文件中再添加一行代碼: 這樣每次我們保存文件時,VS Code 都會自動使用 Black 來格式化代碼。現在,我們來測試一下,創建一個 Python 文件,寫一些未格式化的代碼,然後保存文件。當我們保存文件時,VS Code 會自動為我們格式化代碼。 接下來,我們將設置使用 Pylint 進行代碼檢查。Linting 會在我們寫代碼時檢查代碼中的錯誤和風格問題,幫助我們及早發現問題。 要安裝 Pylint,我們將回到終端,並輸入: 安裝完 Pylint 之後,我們需要配置 VS Code 使用它來進行 linting。再次按 Ctrl + Shift + P 打開命令面板,搜尋 Python: Select Linter 。這會顯示一個可用的 linter 列表,我們從中選擇 Pylint 。 現在,Pylint 設置完成。如果我們寫的 Python 代碼有風格或語法問題,Pylint 會在編輯器中高亮顯示警告或錯誤。這樣我們就能保持代碼的乾淨並避免常見錯誤。" 這是第6部分的逐字翻譯。如果你需要更多幫助,隨時告訴我! 好的,這是第7部分 "Virtual Environments" 的影片操作內容逐字翻譯: "Now, let’s move on to setting up virtual environments in VS Code. A virtual environment is an isolated workspace where we can install specific versions of libraries for a particular project. This ensures that our project dependencies are kept separate from global Python installations. To start, we need to open the terminal in VS Code again. So, press Ctrl + \ or go to View and select Terminal . In the terminal, we’ll use the following command to create a virtual environment. Let’s create a directory for our project first, so we will use the command: Once inside the project directory, we can create the virtual environment by typing: This command will create a folder named venv in the project directory. Inside the venv folder, it will install a separate Python environment. Now, we need to activate this virtual environment. The activation process is slightly different depending on your operating system. If you’re on Windows, you can activate the virtual environment with the following command: On macOS or Linux, the command is: Once activated, you should see (venv) at the beginning of the terminal prompt, indicating that the virtual environment is active. Now that the virtual environment is active, we can install dependencies that are specific to this project. For example, let’s install requests by typing: After installation, we can see that requests is now installed within our virtual environment. To confirm that it’s installed in the virtual environment, we can run the following command: This will list all the installed packages in the virtual environment. You should see requests listed here. Next, let’s tell VS Code to automatically activate the virtual environment when we open the project. To do this, we need to add a configuration file to the project’s .vscode folder. In the terminal, we’ll type the following command: Now, let’s open the .vscode folder and create a new file named settings.json inside. In this file, we’ll add the following configuration: This tells VS Code to use the Python interpreter from the venv folder. If you’re on Windows, the path will be different, so it will look like this instead: Now, VS Code will automatically detect and use the virtual environment when we open the project. Whenever you work on this project, you need to make sure the virtual environment is activated, which will allow you to install and manage dependencies specific to this project. You’ll also want to make sure you’re using the correct Python interpreter by checking that (venv) appears in your terminal prompt. And that’s it! You’ve successfully set up a virtual environment in VS Code." "現在,讓我們繼續設置 VS Code 中的虛擬環境。虛擬環境是一個獨立的工作區,在這裡我們可以為特定的項目安裝特定版本的庫。這樣可以確保我們的項目依賴與全域的 Python 安裝保持分離。 首先,我們需要再次打開 VS Code 中的終端。所以,按下 Ctrl + \ 或者從 View 選擇 Terminal 。在終端中,我們將使用以下命令來創建虛擬環境。我們首先創建一個項目的資料夾,所以我們使用命令: 進入項目資料夾後,我們可以通過輸入以下命令來創建虛擬環境: 此命令會在項目資料夾中創建一個名為 venv 的資料夾。這個 venv 資料夾裡將安裝一個獨立的 Python 環境。現在,我們需要啟動這個虛擬環境。啟動過程會根據操作系統的不同而有所不同。 如果你使用的是 Windows,則可以使用以下命令來啟動虛擬環境: 如果你使用的是 macOS 或 Linux,則命令是: 啟動後,你應該會在終端提示符的開頭看到 (venv) ,表示虛擬環境已啟動。 現在虛擬環境已經啟動,我們可以安裝這個項目特有的依賴。例如,我們來安裝 requests ,輸入以下命令: 安裝完成後,我們可以看到 requests 現在已經安裝在虛擬環境中。為了確認它是安裝在虛擬環境中的,我們可以運行以下命令: 這將列出虛擬環境中安裝的所有包。你應該會在這裡看到 requests 。 接下來,我們要告訴 VS Code 在我們打開項目時自動啟動虛擬環境。為此,我們需要在項目的 .vscode 資料夾中添加一個配置文件。在終端中,我們輸入以下命令: 現在,讓我們打開 .vscode 資料夾,並在其中創建一個名為 settings.json 的新文件。在這個文件中,我們將添加以下配置: 這告訴 VS Code 使用來自 venv 資料夾的 Python 解釋器。如果你使用的是 Windows,路徑會有所不同,應該像這樣: 現在,VS Code 在打開項目時將自動檢測並使用虛擬環境。 每次你在這個項目中工作時,你需要確保虛擬環境已啟動,這樣就能安裝和管理這個項目特有的依賴。你還要確保使用正確的 Python 解釋器,通過檢查終端提示符中是否顯示 (venv) 。 就這樣!你已經成功在 VS Code 中設置了虛擬環境。" 這是第7部分的逐字翻譯。如果你需要更多幫助,隨時告訴我! 好的,這是第8部分 "Running Python Code with Keyboard Shortcuts" 的影片操作內容逐字翻譯: "Let’s now set up a convenient way to run our Python code using a keyboard shortcut, rather than manually running the code in the terminal every time. In order to do this, we’ll use a feature in VS Code called 'Tasks'. This will allow us to set up a custom task that runs our Python script with just a keyboard shortcut. First, we need to open the command palette. To do that, press Ctrl + Shift + P or go to View and select Command Palette . Once the command palette is open, type ‘Tasks: Configure Task’ and select it from the list. Now, VS Code will ask you to choose a task runner. We’re going to choose ‘Create tasks.json file from template’. You’ll see several task templates to choose from. Select the 'Others' option. This will create a tasks.json file inside the .vscode folder in your project. If you don’t see the .vscode folder yet, just create it manually. In the tasks.json file, we’ll configure a new task to run our Python code. Replace the default template with the following configuration: This configuration tells VS Code to use the python command and pass in the currently open file as an argument. It sets this task as the default build task, so it will run when we press the designated keyboard shortcut. Now that we have the task set up, let’s assign a keyboard shortcut to it. Go to the File menu, select Preferences , and then choose Keyboard Shortcuts . In the search bar at the top, type ‘Tasks: Run Build Task’ and find the command. Next, click on the pencil icon next to it to edit the shortcut. Press the keyboard combination you want to use. For example, let’s use Ctrl + Shift + R as the shortcut. After setting the shortcut, it will show up in the list. Now, whenever you press Ctrl + Shift + R , VS Code will run your Python script using the currently open file in the editor. This is a convenient way to run Python code without having to open the terminal and type the command each time. You can now execute your Python scripts with just one key combination." "現在,讓我們設置一個方便的方式來運行 Python 代碼,使用鍵盤快捷鍵,而不是每次都手動在終端中運行代碼。 為此,我們將使用 VS Code 中的一個功能叫做 'Tasks'(任務)。這將允許我們設置一個自定義任務,通過簡單的鍵盤快捷鍵運行我們的 Python 腳本。 首先,我們需要打開命令面板。為此,按 Ctrl + Shift + P 或者從 View 選擇 Command Palette 。命令面板打開後,輸入 'Tasks: Configure Task' 並從列表中選擇它。 現在,VS Code 會要求你選擇一個任務運行器。我們將選擇 'Create tasks.json file from template'。你會看到幾個任務模板可以選擇,選擇 'Others'(其他)選項。 這將在你的項目中創建一個 tasks.json 文件,並放在 .vscode 資料夾中。如果你還沒有看到 .vscode 資料夾,請手動創建它。 在 tasks.json 文件中,我們將配置一個新的任務來運行我們的 Python 代碼。將默認模板替換為以下配置: 這個配置告訴 VS Code 使用 python 命令並將當前打開的文件作為參數傳遞。它設置這個任務為默認的構建任務,所以當我們按下指定的鍵盤快捷鍵時,它會運行。 現在,我們已經設置好了任務,讓我們為它分配一個鍵盤快捷鍵。進入 File 菜單,選擇 Preferences ,然後選擇 Keyboard Shortcuts 。在頂部的搜索框中,輸入 ‘Tasks: Run Build Task’ 並找到該命令。接著,點擊它旁邊的鉛筆圖標來編輯快捷鍵。 按下你想要使用的鍵盤組合。例如,讓我們使用 Ctrl + Shift + R 作為快捷鍵。設置完快捷鍵後,它會顯示在列表中。 現在,每當你按下 Ctrl + Shift + R ,VS Code 會運行你的 Python 腳本,使用當前在編輯器中打開的文件。 這是一個方便的方式來運行 Python 代碼,無需每次打開終端並輸入命令。你現在可以通過一個鍵盤組合來執行你的 Python 腳本。" 這是第8部分的逐字翻譯。如果你需要更多的步驟或詳細說明,隨時告訴我! 好的,以下是第9部分 "Git Integration and Version Control" 的影片操作內容逐字翻譯: "Now let’s dive into Git integration within Visual Studio Code. First, let’s make sure that Git is properly installed on your system. You can check if Git is installed by opening the terminal and typing git --version . If you see a version number, Git is installed. If not, you’ll need to install it. Once Git is installed, let’s go back to VS Code. Open the command palette by pressing Ctrl + Shift + P or selecting Command Palette from the View menu. In the command palette, type ‘Git: Clone’ to clone a repository from GitHub or any other Git server. When you select the 'Git: Clone' command, it will ask you for a repository URL. Enter the URL of the repository you want to clone. For example, you can clone a GitHub repository by entering its URL here. Once the repository is cloned, VS Code will prompt you to open the folder. Click Open to open the repository in VS Code. You’ll now see your project files in the Explorer panel on the left. Now, let’s look at the source control panel. On the left-hand side of VS Code, you’ll see an icon that looks like a branch. This is the Source Control panel, where you can manage your Git repository. Click on it to open the panel. In the source control panel, you’ll see the changes made to your project. If you modify a file, it will show up here as a change. To stage a change, hover over the file, click the plus icon, or click the ‘+’ sign to add it to the staging area. Once you’ve staged your changes, you can commit them. In the message box at the top, enter a commit message, then click the check mark to commit your changes. The commit is now part of your Git history. To push your changes to GitHub, click on the ellipsis ( ... ) in the source control panel and select ‘Push’. VS Code will ask for your GitHub credentials if this is the first time you’re pushing. Enter your username and password, or use a personal access token for authentication. After that, your changes will be pushed to the repository on GitHub. To pull changes from the remote repository, click on the ellipsis again and select ‘Pull’. This will fetch the latest changes from the remote repository and update your local copy. That’s a basic overview of how to use Git within Visual Studio Code. You can also manage branches, view the history of commits, and use more advanced Git features directly within the editor." "現在,讓我們深入了解 Visual Studio Code 中的 Git 集成功能。首先,讓我們確保 Git 在你的系統上正確安裝。你可以通過打開終端並輸入 git --version 來檢查 Git 是否已安裝。如果你看到版本號,則說明 Git 已經安裝。如果沒有,你需要安裝它。 一旦 Git 安裝完成,我們回到 VS Code。打開命令面板,按 Ctrl + Shift + P 或者從 View 菜單中選擇 Command Palette 。在命令面板中,輸入 ‘Git: Clone’ 來克隆來自 GitHub 或任何其他 Git 伺服器的倉庫。 選擇 'Git: Clone' 命令後,它會要求你輸入倉庫的 URL。輸入你要克隆的倉庫 URL。例如,你可以輸入 GitHub 倉庫的 URL 來進行克隆。 一旦倉庫被克隆,VS Code 會提示你打開該文件夾。點擊 Open 來在 VS Code 中打開該倉庫。你現在可以在左側的資源管理器面板中看到你的項目文件。 現在,讓我們來看一下源代碼控制面板。在 VS Code 的左側,你會看到一個看起來像分支的圖標。這就是源代碼控制面板,在這裡你可以管理你的 Git 倉庫。點擊它來打開面板。 在源代碼控制面板中,你會看到你對項目所做的變更。如果你修改了某個文件,它會顯示在這裡,作為一個變更。要暫存這個變更,只需將鼠標懸停在該文件上,點擊加號圖標,或點擊 ‘+’ 標誌將其添加到暫存區。 一旦你暫存了變更,你可以提交它們。在頂部的消息框中輸入提交信息,然後點擊勾號圖標來提交你的變更。這個提交現在成為了你的 Git 歷史的一部分。 要將你的變更推送到 GitHub,請點擊源代碼控制面板中的省略號( ... ),並選擇 ‘Push’。如果是第一次推送,VS Code 會要求你輸入 GitHub 賬號的憑證。輸入你的用戶名和密碼,或者使用個人訪問令牌進行身份驗證。之後,你的變更將被推送到 GitHub 上的倉庫。 要從遠端倉庫拉取變更,請再次點擊省略號,並選擇 ‘Pull’。這會從遠端倉庫抓取最新的變更並更新你本地的副本。 這就是如何在 Visual Studio Code 中使用 Git 的基本概覽。你還可以直接在編輯器中管理分支,查看提交歷史,並使用更多進階的 Git 功能。" 這是第9部分的逐字翻譯。若有更多部分或細節需要翻譯或解釋,隨時告訴我! 好的,以下是第1部分 "Installation of Visual Studio Code (VS Code)" 的影片內容詳細步驟: "Let’s get started with the installation of Visual Studio Code. First, open your web browser and go to the official Visual Studio Code website, which is https://code.visualstudio.com . Once you're on the website, you will see a prominent download button that automatically detects your operating system. For Windows, it will say ‘Download for Windows’, for macOS, it will say ‘Download for Mac’, and for Linux, it will say ‘Download for Linux’. Choose the appropriate version for your operating system and click the download button. After the download is complete, locate the installer file in your system’s download folder. For Windows, the file will be called VSCodeSetup-x64-x.x.x.exe , for macOS, it will be a .dmg file, and for Linux, it will depend on your specific distribution, either .deb or .rpm . For Windows, double-click the .exe file to start the installation process. A prompt will appear asking you if you want to allow this app to make changes to your device. Click Yes to proceed. Next, the VS Code Setup window will appear. Click Next to continue. The next screen will ask you to choose the installation folder. You can keep the default location, or choose a different folder by clicking Browse... If you're okay with the default location, click Next . The next screen will ask you to select additional tasks to be performed during installation. You can choose to create a desktop icon, add VS Code to the PATH (which is useful if you want to open VS Code from the command line), and other options. Select the options you want and click Next . On the next screen, click Install to begin the installation. The installation process will take a few moments to complete. Once the installation is finished, click Finish to close the installer and launch VS Code. Visual Studio Code should now be installed and ready to use. When you open VS Code for the first time, you will be presented with a welcome screen and a few suggestions for getting started with VS Code." "讓我們開始安裝 Visual Studio Code。首先,打開你的網頁瀏覽器,並前往 Visual Studio Code 官方網站,網址是 https://code.visualstudio.com 。 當你進入網站後,你會看到一個顯眼的下載按鈕,它會自動檢測你的操作系統。對於 Windows 來說,它會顯示 ‘Download for Windows’,對於 macOS,則顯示 ‘Download for Mac’,對於 Linux,會顯示 ‘Download for Linux’。選擇適合你操作系統的版本並點擊下載按鈕。 下載完成後,找到安裝檔案,它應該會在你的系統下載文件夾中。對於 Windows,安裝檔案會叫做 VSCodeSetup-x64-x.x.x.exe ,對於 macOS,則會是一個 .dmg 文件,而對於 Linux,會根據你的具體發行版來決定,可能是 .deb 或 .rpm 。 對於 Windows,雙擊 .exe 文件來開始安裝過程。會彈出一個提示,詢問你是否允許該應用程式對你的設備進行更改。點擊 Yes 以繼續。 接下來,VS Code 安裝向導窗口會顯示。點擊 Next 以繼續。 下一個界面會要求你選擇安裝文件夾。你可以保留預設位置,也可以點擊 Browse... 選擇其他文件夾。如果你對預設位置滿意,點擊 Next 。 接下來的界面會要求你選擇安裝過程中要執行的附加任務。你可以選擇創建桌面圖標、將 VS Code 添加到 PATH(如果你希望從命令行打開 VS Code,這個選項非常有用),以及其他選項。選擇你需要的選項,然後點擊 Next 。 在下一個界面,點擊 Install 開始安裝。安裝過程會花幾分鐘的時間來完成。 安裝完成後,點擊 Finish 關閉安裝程序並啟動 VS Code。 Visual Studio Code 現在應該已經安裝完成並準備好使用了。當你第一次打開 VS Code 時,會顯示歡迎界面,並提供一些有關如何開始使用 VS Code 的建議。" 這是第1部分的詳細步驟,下一部分如果需要,可以再告訴我,我會繼續提供! 好的,這是第2部分 "VS Code Interface Overview" 的影片中每個步驟的詳細翻譯和操作說明。 "Now that we have Visual Studio Code installed, let’s take a quick look at the interface. When you first launch Visual Studio Code, you will be greeted with a welcome screen. This welcome screen provides helpful links to get started, such as opening a folder, creating a new file, or getting started with the basics of VS Code. On the left-hand side, you’ll see the Activity Bar. This bar contains icons that represent different sections of VS Code, including the File Explorer, Search, Source Control, and Extensions. The File Explorer allows you to navigate through your project folders and files. If you want to open a folder, simply click on the ‘Explorer’ icon in the Activity Bar. Once clicked, you will see a file tree appear, which shows the folders and files in your workspace. You can open files by clicking on them, and you can right-click on them to perform additional actions like renaming or deleting. The Search icon in the Activity Bar allows you to search for files or content within files in your project. Clicking this icon opens a search panel where you can type your search query and it will show you results in all the files in your workspace. You can narrow down your search by using filters or searching within specific files. Next, the Source Control icon allows you to interact with version control systems like Git. If you are using Git, this icon will show you the status of your repository, such as uncommitted changes, files to be staged, and so on. From this panel, you can commit changes, create branches, and even push or pull from remote repositories like GitHub. Finally, the Extensions icon allows you to browse and manage extensions that can add more functionality to VS Code. You can search for extensions, install them, or uninstall them from this panel. Extensions can add language support, themes, debugging tools, and much more." "現在我們已經安裝好 Visual Studio Code,讓我們來快速了解一下介面。當你第一次啟動 Visual Studio Code 時,你會看到歡迎畫面。這個歡迎畫面提供了開始使用的幫助鏈接,例如開啟資料夾、創建新檔案或了解 VS Code 的基本操作。 在畫面的左側,你會看到活動欄。這個欄位包含了不同區塊的圖示,包括檔案總管、搜尋、原始碼控制和擴充功能。 檔案總管讓你能夠瀏覽你的專案資料夾和檔案。如果你想要開啟一個資料夾,簡單點擊活動欄中的 ‘Explorer’ 圖示。點擊後,你會看到一個檔案樹顯示在畫面上,顯示你工作區中的資料夾和檔案。你可以點擊檔案來打開它,並且右鍵點擊檔案來進行更多操作,例如重新命名或刪除。 搜尋圖示讓你可以搜尋專案中的檔案或檔案內容。點擊這個圖示後會打開一個搜尋面板,你可以在裡面輸入搜尋字串,並顯示在工作區內所有檔案的結果。你可以使用過濾器來縮小搜尋範圍,或是只搜尋特定的檔案。 接下來,原始碼控制圖示讓你可以與版本控制系統(如 Git)互動。如果你正在使用 Git,這個圖示會顯示你儲存庫的狀態,例如未提交的變更、待提交的檔案等等。在這個面板中,你可以提交變更、創建分支,甚至將變更推送或拉取至遠端儲存庫,如 GitHub。 最後,擴充功能圖示讓你可以瀏覽並管理可以增強 VS Code 功能的擴充套件。你可以搜尋擴充套件、安裝或卸載它們。擴充套件可以為 VS Code 增加語言支援、主題、除錯工具等更多功能。" 這是第2部分的詳細步驟,接下來如果需要第三部分的說明,請告訴我,我會繼續提供! 以下是第3部分 "Installing Python Extension" 影片中每個步驟的詳細翻譯和操作說明: "Next, we’re going to install the Python extension. The Python extension is one of the most popular extensions for Visual Studio Code and it’s essential for Python development. To install the Python extension, open the Extensions view by clicking on the Extensions icon in the Activity Bar on the left side. Once you’re in the Extensions view, type 'Python' into the search bar at the top. The first result should be the one published by Microsoft. Click on it and you’ll see an Install button. Click Install to add the extension to your VS Code setup. After installation, you may see a notification asking if you want to install additional components, such as the Python Language Server or Pylint. It’s recommended to install these as well because they will improve your coding experience by providing features like code linting and auto-completion. Once everything is installed, the Python extension will add a lot of new functionality to VS Code. It will recognize Python files, highlight syntax, and provide an interactive environment for running Python code." "接下來,我們將安裝 Python 擴充套件。Python 擴充套件是 Visual Studio Code 最受歡迎的擴充套件之一,對於 Python 開發是不可或缺的。要安裝 Python 擴充套件,首先打開擴充套件視圖,點擊左側活動欄中的擴充套件圖示。 進入擴充套件視圖後,在上方的搜尋欄輸入 'Python'。第一個搜尋結果應該是由 Microsoft 發佈的 Python 擴充套件。點擊它後,你會看到安裝按鈕。點擊安裝來將此擴充套件加入到你的 VS Code 設定中。 安裝完成後,你可能會看到一個通知,詢問是否要安裝其他組件,例如 Python 語言伺服器或 Pylint。建議你也安裝這些組件,因為它們會提供像是程式碼檢查和自動補全等功能,能夠提升你的編程體驗。 當一切安裝完成後,Python 擴充套件將為 VS Code 增加許多新功能。它將識別 Python 檔案、高亮語法,並提供一個互動式環境來執行 Python 程式碼。" 這是第3部分的詳細步驟。如果需要更多部分的翻譯,請告訴我! 以下是第4部分 "Setting Python Interpreter" 影片中每個步驟的詳細翻譯和操作說明: "Next, we need to set the Python interpreter for the project. In Visual Studio Code, you can use different versions of Python depending on your project. To set the Python interpreter, press Ctrl+Shift+P to open the Command Palette. In the Command Palette, type 'Python: Select Interpreter' and select it from the list. This will show a list of available Python interpreters. If you have multiple versions of Python installed, you can choose the one you want to use for your project. If you don’t see the interpreter you need, you can also choose to install a new Python version or create a virtual environment. Once you select the interpreter, Visual Studio Code will remember this choice for your project and automatically use it for any Python-related tasks. At this point, Visual Studio Code will create a .vscode folder in your project directory with a settings file called settings.json . This file stores your project-specific settings, such as the selected Python interpreter." "接下來,我們需要為專案設定 Python 解譯器。在 Visual Studio Code 中,你可以根據你的專案使用不同版本的 Python。要設定 Python 解譯器,按下 Ctrl+Shift+P 打開命令面板。 在命令面板中,輸入 'Python: Select Interpreter' 並從清單中選擇它。這會顯示可用的 Python 解譯器清單。如果你安裝了多個版本的 Python,可以選擇你想為專案使用的版本。 如果你沒有看到需要的解譯器,也可以選擇安裝新的 Python 版本或創建一個虛擬環境。一旦選擇了解譯器,Visual Studio Code 將記住這個選擇,並在所有與 Python 相關的任務中自動使用它。 此時,Visual Studio Code 會在你的專案目錄中創建一個 .vscode 資料夾,並在其中建立一個名為 settings.json 的設定檔案。這個檔案會儲存你的專案特定設定,例如選定的 Python 解譯器。" 這是第4部分的詳細步驟。如果需要更多部分的翻譯,請告訴我! 了解了!下面我會依照影片中提到的每一個步驟,逐一列出詳細操作內容,並提供完整的逐字翻譯與步驟說明。請注意,我會盡量忠實於影片中的說明,不加入自己的解釋,並確保操作步驟清晰無遺。 1. 安裝 Visual Studio Code (VS Code) 逐字翻譯內容與操作步驟: 1.1. 前往 Visual Studio Code 官方網站 https://code.visualstudio.com/ 下載適用於你系統的安裝檔案。 1.2. 點擊下載後,會自動開始下載適用於 Windows、macOS 或 Linux 的安裝檔。 1.3. 當下載完成後,運行安裝程式。 1.4. 在安裝過程中,選擇必要的選項,例如「Add to PATH」選項,以便可以從命令行啟動 VS Code。 1.5. 安裝完成後,點擊「Finish」結束安裝。 2. VS Code 介面概覽 逐字翻譯內容與操作步驟: 2.1. 當 VS Code 安裝完成後,啟動 VS Code,會看到歡迎畫面。 2.2. 在左側面板中,你會看到「文件瀏覽器」可以在這裡查看和打開文件夾。 2.3. 在側邊欄上,你會看到有「搜尋」和「Git 整合」圖示。 2.4. 可以選擇打開項目文件夾,並從「源代碼控制」面板來查看 Git 狀態,或者切換分支。 2.5. 點選側邊欄中的 Git 圖標,你會看到 Git 結合,能夠進行 Git 操作,如推送或提交代碼。 3. 安裝 Python 擴展 逐字翻譯內容與操作步驟: 3.1. 點擊 VS Code 左側邊欄的擴展圖示(四個小方塊組成的圖示)。 3.2. 在擴展市場中,搜索「Python」,找到 Microsoft 提供的 Python 擴展,點擊「安裝」。 3.3. 安裝後,Python 擴展會啟用,並且在 VS Code 中提供 Python 相關的功能,如選擇 Python 解釋器、代碼高亮等。 4. 設定 Python 解釋器 逐字翻譯內容與操作步驟: 4.1. 按下 Ctrl + Shift + P 打開命令面板,並輸入「Python: Select Interpreter」。 4.2. 從下拉菜單中選擇安裝的 Python 解釋器(例如選擇 Anaconda 或是 Python 官方版本)。 4.3. 當選擇好解釋器後,VS Code 會自動為項目創建一個 .vscode/settings.json 配置文件。這個文件包含當前項目的 Python 解釋器設置。 5. 自定義顏色主題與圖示 逐字翻譯內容與操作步驟: 5.1. 點擊左下角的齒輪圖示,選擇「主題」 > 「顏色主題」,然後選擇你喜歡的顏色主題。 5.2. 如果你想使用「Ayu」主題,可以從列表中選擇「Ayu」主題。 5.3. 接下來,你可以進一步自定義圖示,選擇「文件圖示主題」來改變文件夾與文件圖示的顯示樣式。 5.4. 例如,選擇「Ayu」來統一你的顏色主題與圖示風格,讓介面看起來更和諧。 6. 管理代碼格式化與 Linter 逐字翻譯內容與操作步驟: 6.1. 在 VS Code 中,安裝 Python 的代碼格式化工具,像是「Black」。 6.2. 透過擴展市場安裝 Black,並確保它被設置為格式化工具。 6.3. 在 Python 設置中啟用「auto format on save」,這樣每次保存時會自動格式化代碼。 6.4. 接下來,安裝「Pylint」作為 Linter 來檢查代碼的風格和錯誤。 6.5. 在「Python: Linting」設置中,啟用 Pylint,並確保它能夠檢查你的 Python 代碼。 7. 虛擬環境 逐字翻譯內容與操作步驟: 7.1. 打開終端( Ctrl + ~ ),並在項目目錄中創建一個虛擬環境,使用命令 python -m venv .venv 。 7.2. VS Code 會自動檢測到虛擬環境,並將其設置為當前項目的 Python 解釋器。 7.3. 當你開啟新的終端時,虛擬環境會自動激活,並可以安裝項目所需的依賴。 8. 使用鍵盤快捷鍵運行 Python 代碼 逐字翻譯內容與操作步驟: 8.1. 點擊「文件」>「首選項」>「鍵盤快捷方式」,並在搜索框中輸入「run python file」。 8.2. 為運行 Python 文件分配一個自定義快捷鍵,例如 Ctrl + Alt + N 。 8.3. 每當你按下快捷鍵時,VS Code 會直接在終端運行當前 Python 文件,無需手動操作。 9. Git 集成與版本控制 逐字翻譯內容與操作步驟: 9.1. 在 VS Code 中,點擊「源代碼控制」圖示,然後初始化一個新的 Git 儲存庫(如果尚未初始化)。 9.2. 開始修改文件後,Git 會自動追蹤這些變更。 9.3. 在「源代碼控制」面板中,你可以選擇將變更添加到暫存區,並提交變更。 9.4. 如果你已經將 GitHub 連接到 VS Code,可以輕鬆將代碼推送到 GitHub。 9.5. 點擊「推送」按鈕將當前的 Git 分支推送到遠程儲存庫。 這些步驟逐字翻譯了影片中提到的操作內容並列出操作步驟。如果還有其他細節需要調整或進一步解釋,請隨時告訴我! Visual Studio Code 安裝與設置步驟 Visual Studio Code 安裝與設置步驟 安裝 Visual Studio Code (VS Code) 管理程式碼格式與 Linter 使用鍵盤快捷鍵執行 Python 代碼 1. 安裝 Visual Studio Code (VS Code) 首先,你需要下載並安裝 Visual Studio Code。根據你的作業系統(Windows、Mac 或 Linux),請前往 VS Code 官方網站 下載並安裝。 安裝過程相對簡單,按照以下步驟操作: 安裝完成後,啟動 VS Code。 2. VS Code 介面概覽 當安裝完畢並啟動 VS Code 後,會顯示歡迎頁面,並包含幾個關鍵的介面元素: 檔案總管 :用於管理和瀏覽專案中的檔案。 搜尋功能 :可以在專案中搜尋特定的文字或檔案。 Git 整合 :用來管理版本控制,包含提交、推送與拉取操作。 此外,你也可以透過「檔案」選單開啟專案資料夾,並使用左側的源控制面板進行版本控制操作。 3. 安裝 Python 擴充功能 為了讓 VS Code 支援 Python,你需要安裝 Python 擴充功能。這個擴充功能是 VS Code 中最受歡迎的,安裝後可以啟用 Python 特定的功能,如選擇 Python 解譯器、程式碼靜態檢查等。 在 VS Code 中,點選左側邊欄的「擴充功能」圖示(四方形的圖示)。 搜尋「Python」,並選擇由 Microsoft 開發的官方擴充功能。 4. 設定 Python 解譯器 安裝完 Python 擴充功能後,你需要設定 Python 解譯器。這樣 VS Code 就能夠識別並執行你的 Python 程式。 開啟 VS Code 的命令面板(快捷鍵: Ctrl+Shift+P )。 輸入並選擇「Python: Select Interpreter」。 選擇你系統中安裝的 Python 解譯器,或選擇虛擬環境中的解譯器。 VS Code 會根據你的設定自動創建一個專案專屬的 .vscode/settings.json 配置檔。 5. 自訂化介面 (主題與圖示) VS Code 允許用戶自訂介面外觀,你可以選擇不同的顏色主題與檔案圖示來提升使用體驗。 進入「設定」介面(快捷鍵: Ctrl+, )。 在搜尋框中輸入「Color Theme」來選擇你喜歡的顏色主題。 你也可以安裝其他的主題,並根據需求調整 UI 設置,如檔案圖示。 6. 管理程式碼格式與 Linter 為了保持 Python 代碼的乾淨與一致性,你可以在 VS Code 中設定自動格式化(如使用 Black )以及代碼檢查(如使用 Pylint )。 安裝 Black 與 Pylint : 打開終端機(快捷鍵: Ctrl+ )。 執行 pip install black pylint 來安裝這些工具。 打開終端機(快捷鍵: Ctrl+ )。 執行 pip install black pylint 來安裝這些工具。 設定自動格式化與 Linter: 在設定中啟用 Python Formatting: Provider 並選擇 black 。 啟用 Python Linting: Enabled ,並選擇 pylint 作為 Linter。 在設定中啟用 Python Formatting: Provider 並選擇 black 。 啟用 Python Linting: Enabled ,並選擇 pylint 作為 Linter。 這樣,你每次保存檔案時,VS Code 都會自動格式化你的代碼並檢查潛在錯誤。 使用虛擬環境可以讓你為每個專案隔離 Python 依賴。VS Code 支援自動激活虛擬環境,並為專案安裝所需的依賴。 在 VS Code 中,開啟終端機並執行以下命令來創建虛擬環境: python -m venv venv python -m venv venv 啟用虛擬環境: Windows: .\venv\Scripts\activate macOS/Linux: source venv/bin/activate Windows: .\venv\Scripts\activate macOS/Linux: source venv/bin/activate 安裝所需依賴: 執行 pip install <package-name> 安裝你需要的 Python 庫。 執行 pip install <package-name> 安裝你需要的 Python 庫。 8. 使用鍵盤快捷鍵執行 Python 代碼 為了提高效率,你可以自訂快捷鍵來快速運行 Python 代碼,而不是每次都手動輸入命令。 在 VS Code 中設置「執行 Python 代碼」的快捷鍵(例如 Ctrl+Shift+P ,然後選擇「Python: Run Python File in Terminal」)。 通過快捷鍵運行 Python 代碼,無需手動啟動終端機。 VS Code 提供內建的 Git 支援,讓你可以直接在編輯器內進行版本控制操作。 確保你的專案是 Git 倉庫。如果沒有,使用命令 git init 初始化。 在 VS Code 中,點選左側的「源控制」圖示,這裡可以看到當前檔案的變更。 選擇要提交的更動,並推送至 GitHub 或其他遠端儲存庫。 VS Code 提供強大的除錯與單元測試功能,幫助你快速發現並修正錯誤。 設置除錯配置: 在 VS Code 的除錯面板中設置除錯選項。 在 VS Code 的除錯面板中設置除錯選項。 啟動除錯: 點擊「開始除錯」按鈕,程序將在你設置的斷點處停止,並顯示變數與堆疊訊息。 點擊「開始除錯」按鈕,程序將在你設置的斷點處停止,並顯示變數與堆疊訊息。 單元測試: 在 VS Code 中安裝並配置單元測試框架(如 unittest 或 pytest )。 透過測試面板運行測試,並檢視結果。 在 VS Code 中安裝並配置單元測試框架(如 unittest 或 pytest )。 透過測試面板運行測試,並檢視結果。 這些步驟將幫助你從安裝 Visual Studio Code 開始,逐步設置並配置 Python 開發環境,提升開發效率。 Visual Studio Code (VS Code)安裝摘要 Here’s a summary of the content in 5-10 bullet points: Installation of Visual Studio Code (VS Code) : The video starts with the installation of Visual Studio Code on Windows, emphasizing that VS Code is a lightweight editor (not a full IDE) which can be extended using plugins. (Timestamp: 00:00-01:53) Installation of Visual Studio Code (VS Code) : The video starts with the installation of Visual Studio Code on Windows, emphasizing that VS Code is a lightweight editor (not a full IDE) which can be extended using plugins. (Timestamp: 00:00-01:53) VS Code Interface Overview : After installation, VS Code opens with a welcome screen, file explorer, search, and Git integration. The video also highlights how to open project folders and use the source control panel. (Timestamp: 02:26-03:59) VS Code Interface Overview : After installation, VS Code opens with a welcome screen, file explorer, search, and Git integration. The video also highlights how to open project folders and use the source control panel. (Timestamp: 02:26-03:59) Installing Python Extension : The Python extension, being the most popular for VS Code, is installed to enable Python-specific features, including Python interpreter selection and linting. (Timestamp: 06:09-07:48) Installing Python Extension : The Python extension, being the most popular for VS Code, is installed to enable Python-specific features, including Python interpreter selection and linting. (Timestamp: 06:09-07:48) Setting Python Interpreter : Demonstrates changing the Python interpreter and how VS Code creates a project-specific .vscode/settings.json file for configurations. (Timestamp: 10:02-12:19) Setting Python Interpreter : Demonstrates changing the Python interpreter and how VS Code creates a project-specific .vscode/settings.json file for configurations. (Timestamp: 10:02-12:19) Customization (Color Themes and Icons) : The user customizes the editor's appearance using themes like Pre-Dawn and adjusts other UI settings such as file icons. (Timestamp: 14:00-16:16) Customization (Color Themes and Icons) : The user customizes the editor's appearance using themes like Pre-Dawn and adjusts other UI settings such as file icons. (Timestamp: 14:00-16:16) Managing Code Formatting and Linters : The video covers setting up auto-formatting using Black and linting with Pylint to keep Python code clean and consistent. (Timestamp: 32:57-37:47) Managing Code Formatting and Linters : The video covers setting up auto-formatting using Black and linting with Pylint to keep Python code clean and consistent. (Timestamp: 32:57-37:47) Virtual Environments : Shows how to use virtual environments in VS Code, including automatic activation and setup for project-specific dependencies. (Timestamp: 28:37-31:02) Virtual Environments : Shows how to use virtual environments in VS Code, including automatic activation and setup for project-specific dependencies. (Timestamp: 28:37-31:02) Running Python Code with Keyboard Shortcuts : The user demonstrates configuring a more convenient way to run Python code using a keyboard shortcut rather than manually running code in the terminal. (Timestamp: 39:58-41:53) Running Python Code with Keyboard Shortcuts : The user demonstrates configuring a more convenient way to run Python code using a keyboard shortcut rather than manually running code in the terminal. (Timestamp: 39:58-41:53) Git Integration and Version Control : Explains using Git within VS Code, including staging and committing changes, as well as pushing code to GitHub. (Timestamp: 48:31-50:45) Git Integration and Version Control : Explains using Git within VS Code, including staging and committing changes, as well as pushing code to GitHub. (Timestamp: 48:31-50:45) Debugging and Unit Testing : The video highlights VS Code's debugging and unit testing capabilities, including running tests and reviewing test results. (Timestamp: 59:35-1:06:11) Debugging and Unit Testing : The video highlights VS Code's debugging and unit testing capabilities, including running tests and reviewing test results. (Timestamp: 59:35-1:06:11) Summarize the following content in 5-10 bullet points with timestamp if it's transcript. Title: "Visual Studio Code (Windows) - Setting up a Python Development Environment and Complete Overview" Transcript: "(00:00) hey there how's it going everybody in this video we're gonna be learning how to install Visual Studio code and set up a Python development environment we're also going to go over the different features of this editor and see why it's so nice for Python development so we'll cover how to easily switch between editors how to debug applications how git integration works look at unit testing capabilities and a few other things so I've had a ton of comments and requests to cover vs code and it just seems like so many people are switching (00:26) over to it I don't know how many of you all listen to talk Python podcasts with Michael Kennedy but at the end of every show he always asks us guess what editor or IDE they prefer to use and it used to be pretty mixed but now I just feel like I hear vs code so often on there that I figured I had to take some time out to try this and I've got to say so far I'm really impressed with this editor now I wouldn't doubt if you all see me using this from here on out in my videos so with that said let's go ahead and get (00:53) started and see how to set this up and I'll show you what I like so much about this now I ran into some differences between how this works on Windows and Mac so I decided to just make one video specifically for Windows and one specifically for Mac so this video will be covering how to use vs code on Windows but if you're using a Mac then I'll be sure to leave a link to that video in a description section below so firs t of all let's go ahead and install Visual Studio code so I've got their website pulled open here in my browser (01:20) and that is at code Visual Studio com now Visual Studio code is different from Visual Studio which is a full on IDE vs code is a lighter-weight editor that can be extended with plugins for whatever we need so be sure to search for Visual Studio code and not just Visual Studio I'll also have a link to this page in the description section below now vs code is free so we don't nee d to buy anything we just need to download it and install it so I'm just going to download it from the website here so I'll click on download and then it (01:53) choose your operating system I'm on a Windows here and now this should download automatically ok so once that is downloaded I'm just going to run that executable and this is just like any other software installation wizard we'll have to accept some terms here pick our install location I'll go ahead and create a desktop icon for this as well and let's just continue on and finally I will install and once that's installed then I will open up visual studio code okay so now that that's finished I'm just going to check (02:26) this here that says launch Visual Studio code and finish that and now it should launch vs code for the first time here so this might take a sec to pop up okay so when we first run vs code it's going to open they're getting started page in the browser and also it's going to show us their welcome screen here wit e here is the Explorer and if we click on that then this is where we can open our directories and files we don't have anything open right now but we have the option to open a project folder and we'll do that here in just a second so the second option here this is for search so this is where we can do our (03:59) finds and replace and we can do these within multiple files and the third icon here is the git integration which is the source control and we're gonna take a look at this in a bit and se within the extensions here but I'm just going to close that for now and now we're going to look at the popular extensions here so the extension that we're really after right now is this Python extension and this is the most popular extension on vs code by far so if I sort the extensions by popularity so right now if we go to show popular extensions then it's already sorted by install count but we can also sort by rating a name if we wanted to as well so (06:09) we can see here at the top we have m I'm going to select deselect to show the welcome page on (07:48) startup and now I'm going to open up my python script okay so we get a few pop-ups down here this one says that we can change our Python interpreter and this one says that we don't have a linter installed now I'm probably going to get these pop-ups a good bit but I'm just going to ignore them for now and we will take a further look at these whenever we actually do linting but for now I'm gonna have to keep just exiting those out ee how to make it more simple in just a bit but for now if we look at my output down here then we can see that I'm using Python 3 7 that are printed out right there and then it prints out the location where that is here on my machine and also it (10:02) printed out those greetings ok so what if we wanted to change our Python interpreter so there are a couple of different ways that we can do this so if we look at the blue bar at the bottom of the page then in the bottom left it shows us which Pyt e that now when I changed my interpreter you may or may not have noticed that vs code created a folder inside of my project directory here called dot vs code and that directory has a Settings dot JSON file so these are settings for our specific current workspace so let me open this up and we can see that it set our Python a path within the settings JSON file but what if we wanted to use a certain Python interpreter by default (12:19) for every project because right now this is just this specific -dawn now somebody has actually put together a pre-dawn 4 vs code as well (14:00) and I'm glad that they did because I like that color theme so that's what I'm going to use and it's this one here pre-dawn theme kit this pre-dawn Twilight I'm not sure what that is but this is the one that looks like the sublime text version so I'm going to install that and then click on that to use pre-dawn now if I go back to my script then we can see for those of you have seen my videos before this likely looks I like this one because it gives a nice indicator of closed and open folders here on within your file explorer over here okay so I think those setting changes look pretty good for both our color theme and for our file (16:16) icons so right now we're actually implicitly changing our global user settings by changing our color themes and all of that but there are a ton of other settings that we can change that we haven't seen yet so if we want to see all of the settings that we can change then we e changed the zoom level this startup editor is because I said that I don't want to see the welcome screen when I log in we have the color theme here and the icon theme here as well now I have some other preferred settings that I'll show in just a bit now I do wish that they showed the default settings by default when we open up our settings as well because I feel like someone who's new to (18:18) v/s code might not know what settings they can and can't change so it'd be nice to see those defaul n we can always click on this pencil (19:59) icon over here and the gutter that says edit when I click on that it gives us the options that we can use so we can either use UI or JSON so that is a nice touch there and it says I have to save and retry in order to save that so I changed that to JSON now I'm also going to let's see come down here a little bit and I want open default settings set the true as well we can see that the comment here says controls whether opening settings also opens an ed e into my settings and now I want to put the full path to the version of Python that I want to use by default so in order to do this I think the best way to grab this would just be to open (22:21) my integrated terminal here and you can do that with control tilde and now I'm gonna do a command of where Python and this should show me okay so that didn't work there let me see if the Python command is running there okay so that is so I can do import sis and then do sis dot executable and that will that is because we are zoomed in to the here so that size 16 font actually looks pretty large the reason we're zoomed in is so that we can see everything else here in the editor like the sidebar and things like that now on your machine you might not need to zoom in the only reason I'm doing that is because I'm recording this video and I want (24:46) everybody to be able to see now I'm also using a source code Pro here as my font for the editor and for the debug terminal now if you want to use th 23) this so I'll be sure to leave a link to that in the description section below as well if anyone is interested but basically we can just say Python whoops let me spell that right Python - M and that will run a module and the module we want to run is ve and V and now we can pass in our arguments to that module and the arguments we want our the virtual environment name and the virtual environment name I'm just going to call ve and V as well so if I run that then it might take a second to create tivate that environment and all new terminal sessions as well so I think that's a really nice feature so if I open up terminal here let me close down the one I currently have by (28:37) clicking this trashcan and kill terminal let me open up another one and when I open that we can see that it automatically came in and ran that activate script on that virtual environment so if I clear my screen here we can tell that the virtual environment is active because we have V and V over here in a so if we e request library itself so we can see exactly how that method was written so I think that's a very nice feature now if we don't want to completely open up that file where that method exists then we can click on peak definition and that will just show us a little peak here so we can see the get method here within this little window but when we close that or write back to (31:02) our file so I think that intellisense is very useful for giving you information like that so let me actually go to my (32:57) auto pep eighth installed would you like to install that as your formatter and it also suggests some other popular formatters here too such as black and why a PF now I'm going to use black here but you can use auto pepe if you'd like I actually don't really know the differences between those two but I saw on Kenneth writes his blog that he was using black so I'm gonna give it a shot and see if I notice any differences or not okay so now with that formatter installed then we should be abl l of these here so format on paste format on save I want format on save so anytime I save it'll just auto format my code for me and that's a setting that I think is very (35:24) useful so that we don't have to keep manually doing that and the auto formatting and vs code really is great not only does it do Python like we have set up here but it will also auto format for JSON and other languages as well and those are all things that usually require additional packages with editors like sublime tex ur own so if this pop-up wasn't open here I'm just going to close it one more time then we can search using our command palette I'm just going to type in linting and now I'm gonna choose run linting when I try to run linting it's going to pop up with that pop-up so now I'm going to install that and it'll install pilant (37:47) and you can use other linters as well but I think that pilant is a and nice default linter to use I haven't really tried any of the other ones but pilant has been good for hen that might be a mistake so usually we don't want those so with that pointed out I'm just going to get rid of that to clean up the code and there we go okay so now let me show you an extension that I like to use that makes running Python code a bit easier so so far we've been right-clicking and selecting run code in terminal every time we want to run our Python code but I'm not the biggest fan of that I'd rather have an easy keyboard shortcut (39:58) that does this for us and also I don't lik ht here so it says that we're using Python 3 7 and that we got our status code of 200 but the Python (41:53) interpreter that it's using is the default interpreter for my system so this is the global version of Python and I do have requests installed in that global version of Python but if I didn't have requests installed then that would fail even though I do have requests installed in my virtual environment so we want to set this up to use our virtual environment instead of our global Python to ange here now you don't have to make these changes but this is my preferred settings so I can do a code runner and again I can hit control space to make this autocomplete for me and I want to change this clear previous output I want to change that to true because I don't like a lot of previous (44:23) runs of my script taking up all of my screen okay and now the last thing that I'm going to change here is code runner show execution message that is true by default I want to set this equal to fals was that people would always ask me how to do input within sublime and it was actually hard to do within sublime and I would always just recommend against it I would just recommend instead using the terminal so to write your script within sublime and then use the terminal now within vs code if we want to use input then it's kind of the same process but now we have a terminal built in so I'm going to just get rid of my code here everything except the imports and now (46:44) I'm just going to use t I want to track so I'm just going to click on my project the one (48:31) that I've been working in so once we do that it's going to now put in all of the files here that are untracked now it looks like we have a lot it says there are over 3,000 but most of these are from our virtual environment and we usually don't want to even track our virtual environment so to ignore our that directory we just need to create a dot git ignore file and add that to what we're tracking with git within my folder e we could hover over them and just click on the plus icon beside each file so if I do that with git ignore we can see that that got staged or if we wanted to stage all of the changes then we can just click the extra options up here at the top right (50:45) and then if I scroll down here I can go to stage all changes so if I do that then we can see that now our script pi is staged as well so now to commit we can just click on this check mark here to commit and now it's going to ask us for a comm the integrated terminal so I'm gonna save that and now let me close down the terminal that we had before and now open that back up and now we should be using git bash instead and we can see that it still activates that virtual environment now my text is a little large here so I'm running on to a new line but it's large enough just so you all can see but normally this would all be on one line here so let me clear (53:08) this out just by running clear there and now I can run those get configurati nd now this is our new code over here on the right so the red is saying hey you removed all of this stuff here that's what was last committed it's now gone and the green over here is saying oh and this is what was added this we didn't have this here before and now we do so if that diff looks good then you can simply stage your changes you want to close down the diff here so we staged the changes here it says that it's modified now I can commit that and as a (55:25) commit message here I'll just source control tab I can simply click here with the extra options and I'm going to select this command here (57:20) push - and when I click push - it says well where do we want to push this we have this thing called origin here at this URL and that is what got added when we ran that command that get gave us or that github gave us so if I run that then it's going to push that up to github now it's asking me to log in here so let me log in really quick with my username and password it's been a wh the debug tab over here in our activity bar and now let me make this a little bit larger here we can see that it says we don't currently have any configurations but if I click the little gear icon here then we can see some different configurations so we (59:35) have Python file we have module Django flask so you can set up these configurations to where it'll run you know your main flask app from there and you can also specify ports and stuff like that for this video we're just going to look at ore interactive then we can also use let me make this a little smaller over here we can also use the debug console and use this to inspect anything we'd like so I'm gonna click on our additional views here click on debug console and within the debug console we can just use this like an interactive Python prompt so if I wanted to see the value of r dot okay then i could just run that and we can see that it gives us this feedback of exactly what these values are equal to at this (1:01:57) point in ing support that they have built in to vs code and I'm really loving their attention to detail and how they covered so many different aspects (1:03:37) of helping us manage our code as easily as possible so having the built-in support for all this stuff is definitely a nice addition that you're not gonna find in most other editors so to show some unit testing I'm going to close down my current project and I'm going to open up a different project that has some sample unit tests so I'm going to cl to say to install that for our default Python as well so that we stop seeing those pop-ups okay so now let me open up both of these unit tests here okay so now that we have some unit tests available here let's run open up our command palette and now let's type in discover tests and when we run discover tests then it's (1:06:11) going to come up with this pop-up here that says enable and configure test framework so I'm going to click on that and now it's going to ask us what unit testing framewor now we can see it says three tests pass one test failed so if I click on this status down here in the bottom then it'll ask us what we want to do so we can run all of the tests again we can simply just run the failed test which is a nice feature as well or we can view the test output if I look at the test output here then we can see it ran for test one of them failed and it failed because of an assertion error that 15 is not equal to 10 and that it failed on line 8 so it shows us exactly where o show you in this video and it's only going to take one second so I have some other preferred settings that I haven't shown in this video and (1:10:04) most of them are settings for changing how they editor looks in full-screen send mode and will allow me to run code without too much other stuff getting in the way and I want to show you these settings so that you can see exactly how I'm gonna have my vs code set up if you see me using this editor in future videos because I get a lot of question open up Zen mode here and we can see how I have this set up it's you know takes away our activity bar the blue bar down here at the bottom so it's just a lot more clean and the nothing is distracting us from the code itself and we can still run code by just clicking up here and clicking run code now it's telling me it (1:12:14) can't find the specified path and the reason is because like I was saying these are my Mac settings so the path that I have set up for my Mac is this is more of a Linux cally how to do anything within vs code that we'd want to do so we have all of the multi cursor selection here file management search and replace things like that so that is a nice reference there if you would like to learn any of those keyboard shortcuts okay so I think that is going to do it for this video I hope you all found this video helpful especially if you're trying to switch over to vs code for your Python development so personally I think they really knocked it " VS Code 中執行 Python 在 VS Code 中執行 Python 程式,可以使用以下幾種方式: 1. 使用「執行按鈕」(最簡單的方法) 如果你已經安裝 Python 擴充套件 ,可以直接按 VS Code 內建的 執行按鈕 : 開啟 VS Code,建立或開啟 .py 檔案。 在視窗右上角,會看到一個「▶」 執行按鈕 (或按 Ctrl + F5 )。 按下去,程式就會在 內建終端機(Terminal) 執行。 2. 使用「終端機」手動執行(適合已熟悉命令列的人) 如果你習慣用命令列(Command Line),可以手動執行 Python 程式: 打開終端機 (按 Ctrl + J ,或從「檢視」→「終端機」開啟)。 確保你在 Python 檔案所在的資料夾(可以用 cd 切換目錄)。 輸入以下指令來執行程式(假設檔名是 hello.py ): python hello.py 或在某些系統上: python3 hello.py 你的 Python 程式會在終端機中執行並顯示結果。 3. 使用「偵錯模式」執行(適合除錯時使用) VS Code 也提供 偵錯(Debugging)模式 ,方便你查看變數、執行逐步分析: 開啟你的 Python 檔案。 按 F5 ,或點選「執行」→「啟動偵錯」。 第一次使用時,VS Code 會要求你選擇偵錯環境,請選擇 Python 。 程式將以「偵錯模式」執行,你可以使用「中斷點」來逐行偵錯。 4. 在「交互式(Interactive)」模式執行(適合測試短程式) 如果只是想測試幾行 Python 程式碼,而不建立 .py 檔案,可以使用 Python 互動模式: 打開終端機 ( Ctrl + J )。 輸入 python (或 python3 )並按 Enter ,會進入 Python 互動模式。 直接輸入 Python 指令,例如: print("Hello, world!") 按 Enter,就會立即顯示結果。 結束 Python 互動模式,輸入 exit() 或按 Ctrl + Z (Windows)/ Ctrl + D (Mac & Linux)。 5. 使用 Jupyter Notebook(適合資料科學) 如果你的 Python 主要是用來做 資料分析、機器學習 ,可以使用 Jupyter Notebook 方式執行: 先安裝 Jupyter: pip install notebook 在 VS Code 擴充套件商店 安裝 Jupyter 。 建立 .ipynb 檔案(取代 .py )。 在 Notebook 內執行每一個程式區塊(類似 Google Colab)。 你目前在 VS Code 有遇到執行 Python 的問題嗎?如果有錯誤訊息,可以提供給我,我幫你解決! 😊 "GetLens" 與 GitHub Codespaces 是否會在 雲端環境 出現,取決於你在 Codespaces 內的擴充套件設定。這裡拆分成幾種情境來解釋: 🔹 1. GitLens 會在 GitHub Codespaces 內運行嗎? ✅ 會 ,因為 GitHub Codespaces 其實就是在雲端執行 VS Code 的完整環境 ,你在本機安裝的擴充套件(例如 GitLens ), 如果 Codespaces 也有安裝 ,它仍然會在雲端執行。 如果 GitLens 已預先安裝 (通常 Codespaces 會自動載入你的 VS Code 設定),你可能仍然會在雲端環境內看到 "GetLens" 提示。 但如果 Codespaces 沒有安裝 GitLens ,你就不會看到 "GetLens" 。 進入你的 GitHub Codespaces 環境 (在 GitHub 上開啟 Codespaces)。 在 VS Code 擴充套件管理 ( Ctrl + Shift + X ) 搜尋 GitLens ,看看是否已安裝。 如果 GitLens 存在,你仍然會看到 GetLens 相關的提示。 🔹 2. 如何在 GitHub Codespaces 關閉 "GetLens"? 如果你不想在 Codespaces 內看到 "GetLens" ,可以有幾種方式解決: 🔸 方法 1:關閉 GitLens 的 CodeLens(推薦) 這樣你仍然可以使用 GitLens,但不會看到 "GetLens" 提示: 打開 VS Code 設定 ( Ctrl + , ) 搜尋 "GitLens CodeLens" 找到 GitLens › CodeLens › Enabled , 取消勾選 🔸 方法 2:完全停用 GitLens 如果你不想在 GitHub Codespaces 內使用 GitLens,可以直接移除: 在 Codespaces 內打開 VS Code 擴充套件 ( Ctrl + Shift + X )
📥 下载地址(文章中间)
装机神器,专门安装各种电脑系统,各种品牌全可以。
點選 「停用」 或 「解除安裝」 🔸 方法 3:使用 Codespaces 的 Dev Container 設定 如果你希望 Codespaces 預設不安裝 GitLens ,你可以修改 devcontainer.json : 打開你的 Codespaces 設定 ( .devcontainer/devcontainer.json ) 添加以下設定,讓 Codespaces 不要安裝 GitLens : { "extensions": [ "GitHub.copilot", "ms-python.python" ] } 這樣 Codespaces 只會安裝 GitHub Copilot 和 Python 擴充套件 ,不會載入 GitLens 。 🔹 3. 你需要在 GitHub Codespaces 使用 GitLens 嗎? 你想在 Codespaces 內 快速查看 Git Blame(誰修改過程式碼) 。 你希望使用 Git 視覺化功能 ,快速查看 Git 變更。 你經常與團隊協作,需要 高效管理 Git 提交紀錄 。 你不想在雲端環境內看到 GitLens 提示,覺得 "GetLens" 很干擾。 你只想在 Codespaces 內做簡單的開發,不需要進階 Git 工具。 ✅ GitLens 會在 GitHub Codespaces 內執行 ,如果它已安裝,你仍然可能看到 "GetLens" 。 ❌ 如果你不想在 Codespaces 內看到 "GetLens" ,你可以 關閉 GitLens CodeLens 功能、停用 GitLens,或修改 Dev Container 設定來避免安裝 GitLens 。 如果你還有任何 GitHub Codespaces 或 VS Code 相關問題,歡迎問我! 😊 🚀 GitHub Codespaces GitHub Codespaces v1.17.3 是 GitHub Codespaces 這個擴充套件在 VS Code 上的特定版本(1.17.3)。 📌 什麼是 GitHub Codespaces? GitHub Codespaces 是 GitHub 提供的一項 雲端開發環境 ,可以讓你在瀏覽器或 VS Code 內直接開發 GitHub 上的程式碼,而不需要在本機安裝完整的開發環境。 ✅ 雲端開發 :不需要在本機安裝 VS Code、Git、Node.js、Python 等開發工具,所有的環境都在 GitHub 雲端運行。 ✅ VS Code 無縫整合 :你可以在 VS Code 本機應用程式內,或直接透過 瀏覽器 ( codespaces.new )來開發程式。 ✅ 預設開發環境 :你可以使用 Dev Containers 自訂開發環境,確保所有開發人員使用相同的工具與設定。 ✅ 與 GitHub 完美整合 :適合多人協作,直接在 GitHub 上打開分支並進行開發,不需額外設定本機環境。 📌 你為什麼會看到 GitHub Codespaces v1.17.3 ? 1️⃣ 你可能已經安裝了 GitHub Codespaces 擴充套件 可以在 VS Code 擴充套件 ( Ctrl + Shift + X ) 裡搜尋 GitHub Codespaces ,看看是否已安裝。 如果你沒有要使用 Codespaces,可以 停用 或 移除 它。 2️⃣ VS Code 可能建議你安裝這個擴充功能 如果你在 GitHub 上開啟了一個 Codespace,VS Code 可能會自動推薦安裝這個擴充套件,以便更好地與雲端環境整合。 🔧 如何停用或移除 GitHub Codespaces 擴充套件? 按下 Ctrl + Shift + X 打開擴充套件管理 在搜尋框輸入 "GitHub Codespaces" 如果已安裝,點擊 "停用"(Disable) 或 "解除安裝"(Uninstall) 如果你不打算使用雲端開發環境,而只想在本機開發,則可以移除這個擴充套件! 😊 🎯 你需要 GitHub Codespaces 嗎? ✅ 適合你,如果... 🔹 你希望 隨時隨地開發 ,不想安裝本機環境。 🔹 你經常在 不同的電腦 上開發專案,需要雲端環境同步。 🔹 你需要 與團隊協作 ,確保所有開發人員的環境一致。 ❌ 不適合你,如果... 🔸 你主要在 本機開發 ,不想使用雲端環境。 🔸 你的專案不需要 雲端 VS Code ,只想在電腦上運行。 🔹 總結 : GitHub Codespaces 是一個 雲端開發環境 ,如果你看到 v1.17.3 ,代表你安裝了這個 VS Code 擴充套件的版本。如果你不需要它,可以停用或移除它! 如果你有其他 VS Code 或 GitHub 相關問題,歡迎繼續問我! 🚀 😊 第一次使用 VS Code 的完整指南 📌 第一次使用 VS Code 的完整指南 📍 適用對象: Windows 使用者, 第一次使用 VS Code ,希望 詳細步驟 避免出錯。 這份指南會 一步步 帶你從 安裝、設定、基本操作 到 執行程式 ,確保你能順利使用 VS Code!🚀 🔹 1. 安裝 VS Code 下載 VS Code 進入官方網站 👉 https://code.visualstudio.com/ 點擊「 Download for Windows 」下載安裝程式( VSCodeUserSetup-x64.exe ) 進入官方網站 👉 https://code.visualstudio.com/ 點擊「 Download for Windows 」下載安裝程式( VSCodeUserSetup-x64.exe ) 安裝 VS Code 雙擊 下載好的 .exe 檔案 點擊 「Next」 (下一步) 選擇安裝路徑 (建議使用預設路徑) 勾選這些選項 (避免日後手動設定): ✅ Add "Open with Code" action to Windows Explorer file context menu ✅ Add "Open with Code" action to Windows Explorer directory context menu ✅ Register Code as an editor for supported file types ✅ Add to PATH (很重要,讓 VS Code 可以在命令提示字元執行) 點擊「Install」,等待安裝完成,然後按「Finish」🚀 雙擊 下載好的 .exe 檔案 點擊 「Next」 (下一步) 選擇安裝路徑 (建議使用預設路徑) 勾選這些選項 (避免日後手動設定): ✅ Add "Open with Code" action to Windows Explorer file context menu ✅ Add "Open with Code" action to Windows Explorer directory context menu ✅ Register Code as an editor for supported file types ✅ Add to PATH (很重要,讓 VS Code 可以在命令提示字元執行) 點擊「Install」,等待安裝完成,然後按「Finish」🚀 開啟 VS Code 方法 1 :點擊 桌面快捷方式 Visual Studio Code 方法 2 :按 Win + S ,搜尋 VS Code ,點擊開啟 方法 1 :點擊 桌面快捷方式 Visual Studio Code 方法 2 :按 Win + S ,搜尋 VS Code ,點擊開啟 VS Code 預設是英文介面 ,如果你習慣 中文 ,可以安裝中文語言擴展。 按 Ctrl + Shift + X (打開擴展商店) 找到 Chinese (Simplified) - 简体中文 點擊 Install (安裝) 安裝完成後,VS Code 會要求重新啟動 ,點擊「 Restart 」 🔹 3. 安裝 Python 並設定 VS Code 如果你要寫 Python 程式,需要安裝 Python 並設定 VS Code。 下載 Python 進入官方網站 👉 https://www.python.org/downloads/ 點擊「 Download Python 」下載 python-x.x.x.exe 進入官方網站 👉 https://www.python.org/downloads/ 點擊「 Download Python 」下載 python-x.x.x.exe 安裝 Python 雙擊執行 python-x.x.x.exe ✅ 勾選 「Add Python to PATH」(很重要!) 點擊「Install Now」安裝 安裝完成後,打開 命令提示字元(CMD) ,輸入: python --version 如果出現 Python x.x.x ,代表安裝成功!🎉 雙擊執行 python-x.x.x.exe ✅ 勾選 「Add Python to PATH」(很重要!) 點擊「Install Now」安裝 安裝完成後,打開 命令提示字元(CMD) ,輸入: python --version 如果出現 Python x.x.x ,代表安裝成功!🎉 🔹 4. 安裝 Python 擴展 VS Code 需要額外安裝 Python 擴展 才能正確運行 Python。 按 Ctrl + Shift + X (打開擴展商店) 找到 Python (Microsoft 開發) 點擊 Install (安裝) 安裝完成後,VS Code 會自動啟用 Python 支援 🔹 5. 建立第一個 Python 檔案 現在,你可以開始寫 第一個 Python 程式 ! 在桌面建立一個資料夾 (例如 Python-Projects ) 按 Ctrl + K ,然後按 Ctrl + O (打開資料夾) 選擇剛剛建立的 Python-Projects 資料夾 在左側檔案管理器,按 New File (新建檔案) 輸入 hello.py 作為檔名,然後按 Enter 在 hello.py 裡輸入以下程式碼: print("Hello, VS Code!") 🔹 6. 執行 Python 程式 方法 1:使用 VS Code 內建終端機 按 Ctrl + Shift + (開啟終端機) 輸入 : python hello.py 看到 Hello, VS Code! 表示成功!🎉 方法 2:使用 VS Code 內建「執行按鈕」 按 Ctrl + F5 (直接執行程式) 下方終端機會顯示 Hello, VS Code! VS Code 可以安裝擴展 來增強功能。這裡推薦一些 必裝擴展 : 按 Ctrl + Shift + X (開啟擴展商店) 🔹 8. 設定 VS Code 個人化 你可以調整 主題、字體大小、快捷鍵 來讓 VS Code 更符合你的需求! 按 Ctrl + Shift + P (開啟命令面板) 輸入 Preferences: Color Theme 選擇你喜歡的主題 Dark+ (default dark) → 黑色背景(預設) Light+ (default light) → 白色背景 Dracula / Ayu / Predawn → 更漂亮的主題(需安裝) Dark+ (default dark) → 黑色背景(預設) Light+ (default light) → 白色背景 Dracula / Ayu / Predawn → 更漂亮的主題(需安裝) 按 Ctrl + , (開啟設定) 調整字體大小(建議 14-16 ) 🔹 9. 使用 Git 版本控制 如果你要使用 Git 來管理程式碼 ,可以這樣設定: 下載並安裝 Git 👉 https://git-scm.com/downloads 按 Ctrl + Shift + P ,輸入 Git: Clone 輸入你的 GitHub 存儲庫網址 ✅ 安裝 VS Code ✅ 設定中文語言包 ✅ 安裝 Python 並設定環境 ✅ 建立第一個 Python 檔案 ✅ 執行 Python 程式 ✅ 個人化設定 ✅ 設定 Git 版本控制 這樣你就可以 順利開始使用 VS Code 了! 🚀✨ 有問題可以隨時問我!😊 如何安裝 VS Code 並設置 Python 開發環境 影片翻譯:如何安裝 VS Code 並設置 Python 開發環境 介紹 (Introduction) 0:00 嗨,大家好!這部影片將教大家如何安裝 Visual Studio Code (VS Code) 並設置 Python 開發環境 。 0:06 我們還會介紹這個編輯器的各種功能,並說明為什麼它特別適合 Python 開發。內容包括: 如何偵錯 (Debug) 應用程式 單元測試 (Unit Testing) 0:18 最近,我收到很多關於 VS Code 的問題和請求,發現許多人都在改用這款編輯器。不知道大家有沒有聽過 Talk Python 播客,由 Michael Kennedy 主持? 0:29 在每集節目結束時,他總是問來賓最喜歡哪個編輯器或 IDE。過去答案還蠻多元的,但現在「VS Code」幾乎成了標準答案,讓我決定試試看這款編輯器。 0:42 結果我真的對 VS Code 感到印象深刻,未來的影片中,可能會一直使用它! 0:54 不過,我發現 Windows 和 Mac 的使用方式稍有不同,所以這次我會製作 Windows 專屬 的影片,Mac 版則會在描述欄附上連結。 安裝 VS Code (Installing VS Code) 1:18 首先,我打開 Visual Studio Code 的官方網站 ( code.visualstudio.com )。 1:23 ⚠️ 請注意! 「Visual Studio Code」和「Visual Studio」是 不同 的軟體! Visual Studio 是完整的 IDE (適合 C#、.NET 開發) VS Code 是較輕量的 編輯器 ,可以透過 擴展 (Extensions) 來強化功能 1:42 VS Code 是 免費 的,我們只需下載並安裝即可。 點擊 下載 (Download) 按鈕 選擇適合的作業系統(這裡是 Windows ) 2:00 完成下載後,執行 安裝程式 (Installer) ,和一般軟體安裝方式相同: 勾選「建立桌面捷徑」 (方便開啟) 完成安裝 ,然後開啟 VS Code 第一次啟動 VS Code (First Launch of VS Code) 2:38 當我們 第一次開啟 VS Code 時,會出現 「快速入門」(Getting Started) 頁面 ,以及 歡迎畫面 。 2:50 雖然這些頁面有很多有用的資訊,但我會在這部影片中介紹主要內容,所以先關閉它們。 3:08 現在,我把 VS Code 放大,並調整 縮放比例 ,讓我們能夠更清楚地看到選單和文字。 探索 VS Code 介面 (Exploring the Editor) 3:14 VS Code 介面簡潔直觀,不會有多餘的視覺干擾。 但如果是新手,可能需要一點時間適應,因為大多數功能都是用 圖示 而非文字顯示。 3:26 📌 活動欄 (Activity Bar) - 主要導航區域 📁 檔案總管 (Explorer) :開啟、管理專案資料夾和檔案 🔍 搜尋 (Search) :可以在 多個檔案 內搜尋和取代內容 🔗 Git 版本控制 (Source Control) :整合 Git,可直接推送程式碼到 GitHub 🐞 偵錯 (Debugging) :VS Code 內建強大的 偵錯工具 ⚙ 擴展管理 (Extensions) :用來安裝各種 VS Code 擴展 安裝 Python 擴展 (Managing Extensions) 5:46 接下來,我們來 安裝 Python 擴展 ,這是 VS Code 最受歡迎的擴展 ,擁有超過 4200 萬次下載 ! 6:24 Python 擴展提供許多強大功能: Debugging (程式偵錯) 程式碼格式化 (Formatting) 單元測試 (Unit Testing) IntelliSense (智慧提示功能) 點擊 擴展管理 (Extensions) 圖示 等待幾秒,擴展完成安裝後,即可使用 Python 開發功能! 開啟 Python 專案 (Opening a Python Project) 7:06 現在,我打開一個 現有的 Python 程式碼 (如果沒有,可以建立 .py 檔案)。 點擊「檔案總管」(Explorer) 圖示 選擇「開啟資料夾」(Open Folder) 找到專案資料夾,開啟 Python 檔案 7:56 開啟檔案後,VS Code 可能會跳出兩個提示: 更改 Python 直譯器 (Interpreter) 安裝 Linter(程式碼檢查工具) 執行 Python 程式 (Running Python Code) 8:57 現在,我們來 執行 Python 程式 ! 9:20 方法 1️⃣:右鍵選單執行 選擇 「Run Python File in Terminal」(在終端機執行 Python 檔案) 9:38 方法 2️⃣:使用鍵盤快捷鍵執行 (稍後設定) 執行後,我們可以在 終端機 (Terminal) 看到輸出結果,包括 Python 版本與執行的輸出內容。 切換 Python 直譯器 (Switching Python Interpreters) 10:08 如果系統安裝了多個 Python 版本,例如 Python 2 和 Python 3,可以手動切換直譯器。 在 VS Code 左下角,點擊 Python 版本號 選擇適合的 Python 版本 💡 建議使用 Python 3 ,如果尚未安裝,可以在 Python 官網下載安裝。 這是 影片前 10 分鐘 的完整繁體中文翻譯,後續內容包括: 如何設定虛擬環境 (Virtual Environment) Git 版本控制與 GitHub 連接 單元測試 (Unit Testing) 如果您希望完整翻譯整部影片,請讓我知道! 😊 這是該影片的 繁體中文翻譯 (Part 2) ,涵蓋 設定 VS Code 介面、Python 直譯器、虛擬環境 (Virtual Environment)、擴展 (Extensions) ,以及 如何在 VS Code 中運行 Python 程式 。 設定 VS Code 介面 (Customizing VS Code Interface) 14:38 身為程式設計師,我們幾乎每天都在使用編輯器,因此應該讓它符合自己的喜好,提升舒適度和工作效率。 🔹 更改檔案圖示 (Changing File Icons) 14:44 VS Code 預設的 檔案圖示 (File Icons)已經很不錯,例如: Python 檔案 會顯示 Python 圖示 JSON 檔案 會顯示 大括號圖示 14:57 如果想要 更改檔案圖示 ,可以按照以下步驟操作: 開啟命令面板 (Command Palette) : Ctrl + Shift + P 輸入「File Icon Theme」 並選擇「更改檔案圖示主題」(Change File Icon Theme) 安裝額外的檔案圖示套件 (可以根據下載數量排序) 我個人推薦「Ayu」圖示主題 ,安裝後可以讓介面更美觀 16:01 套用 Ayu 圖示主題後,檔案管理器中的資料夾會有更清楚的 開啟/關閉圖示 ,方便辨識。 修改 VS Code 使用者設定 (Changing User Settings) 🔹 進入 VS Code 設定頁面 16:16 目前我們已經隱性地更改了 全域使用者設定 (Global User Settings) ,例如: 更改 顏色主題 (Color Theme) 更改 檔案圖示主題 (File Icon Theme) 如果想要查看 所有可更改的設定 ,可以: 選擇「設定」(Settings) 16:51 🔸 VS Code 目前預設的設定方式 : 以前是 JSON 格式並排顯示,但現在改為 UI 方式 17:23 🔸 如果想使用 JSON 格式來編輯設定 : 點擊右上角 {} 圖示 (「以 JSON 格式開啟設定」) 現在可以手動編輯設定 JSON 18:03 查看目前已變更的設定: 縮放等級 ( editor.zoomLevel ) :目前為 3 啟動畫面 ( workbench.startupEditor ) :已設為「不顯示歡迎畫面」 顏色主題 ( workbench.colorTheme ) 檔案圖示 ( workbench.iconTheme ) 變更 Python 直譯器 (Changing Python Interpreter) 21:26 當我們執行 Python 程式時,VS Code 預設會使用 系統內的第一個 Python 版本 。 如果系統安裝了 Python 2 和 Python 3 ,我們可能需要手動切換直譯器。 點擊左下角 Python 版本號 在選單中選擇 Python 3.7 (或你要使用的版本) 22:50 如果我們希望 每次開啟新專案時,自動使用指定的 Python 版本 ,可以: 手動設定 settings.json ,指定 Python 直譯器的完整路徑 透過 內建終端機 (Integrated Terminal) 查詢 Python 路徑: import sys print(sys.executable) 複製這條路徑,貼到 settings.json 的 "python.defaultInterpreterPath" 設定中 建立 Python 虛擬環境 (Creating a Virtual Environment) 25:22 在 Python 開發中,通常建議為每個專案 建立獨立的虛擬環境 ,避免不同專案的依賴套件產生衝突。 🔹 創建虛擬環境 (Using venv ) 開啟 VS Code 內建終端機 (Ctrl + `) 輸入以下指令 建立虛擬環境: python -m venv venv 等待幾秒鐘,系統會在專案資料夾內建立一個 venv/ 目錄 在 VS Code 中啟用虛擬環境 (Activating Virtual Environment in VS Code) 27:10 虛擬環境建立後,需要手動啟用它: 🔹 Windows (cmd / PowerShell) 🔹 macOS / Linux (bash / zsh) 啟動後,終端機提示符會顯示 (venv) ,代表目前正在使用這個虛擬環境。 在 VS Code 設定虛擬環境為專案直譯器 27:33 現在,我們需要讓 VS Code 自動使用這個虛擬環境 。 點擊左下角 Python 版本號 選擇 剛剛建立的虛擬環境 ( venv ) VS Code 會自動偵測並啟用該環境 如果 VS Code 沒有偵測到虛擬環境,可以手動修改 settings.json ,將 python.pythonPath 設為 venv 內的 Python 直譯器路徑: 測試虛擬環境 (Testing Virtual Environment) 28:56 現在,我們可以在虛擬環境中 安裝 Python 套件 ,例如 requests : 如果安裝成功,就能在 Python 腳本中正常匯入該套件: 我們已經學會如何: ✅ 安裝與設定 VS Code ✅ 自訂 VS Code 介面(主題 & 圖示) ✅ 變更 Python 直譯器 ✅ 建立 Python 虛擬環境 (venv) ✅ 在 VS Code 內使用虛擬環境 接下來,我們可以進一步學習如何: 使用 VS Code 偵錯 Python 程式 (Debugging) 設定 Git 版本控制與 GitHub 整合 執行單元測試 (Unit Testing) 如果你希望我 繼續翻譯剩餘的影片內容 ,請告訴我! 😊 這是該影片的 繁體中文翻譯 (Part 3) ,涵蓋 IntelliSense、自動格式化 (Auto Formatting)、程式碼 Linting、擴展 Code Runner 的使用 ,以及 如何確保 Python 程式使用正確的虛擬環境 。 使用 IntelliSense (VS Code 智慧提示功能) 🔹 IntelliSense 提供的功能 29:45 現在,我要移除目前的 print() 陳述式,改用 requests 來進行 HTTP 請求。 在輸入程式碼時,請注意 IntelliSense 的運作方式。這是 VS Code 內建 的功能,會顯示 物件可用的屬性與方法 。 當我輸入 requests. 並按下 . (點),就會跳出 可用的方法列表 ,包括: 這樣我們可以快速選擇適合的方法,而不需要記住所有 API。 🔹 使用「前往定義」(Go to Definition) 30:23 如果想深入了解某個方法,例如 get() ,可以: 選擇「前往定義」(Go to Definition) 這將打開 requests 函式庫內部的原始碼,讓我們查看 get() 方法的實作方式。 30:54 如果不想開啟整個檔案,也可以使用 「快速查看定義」(Peek Definition) ,這會在當前視窗內顯示一個小彈窗來檢視程式碼。 發送 HTTP 請求 (Sending an HTTP Request) 31:10 現在,我將發送一個請求到我的個人網站,並印出 HTTP 狀態碼 : 執行 Python 程式 (Running the Python File) 31:51 現在,我要執行這段程式碼: 選擇「Run Python File in Terminal」 32:02 執行後,終端機會顯示: Python 直譯器的位置 (這次是虛擬環境內的 Python) 回應的 HTTP 狀態碼 (應該會是 200 ,表示請求成功) 自動格式化 Python 程式碼 (Auto Formatting) 🔹 安裝 Python 格式化工具 32:19 目前,我們還 沒有安裝格式化工具 (formatter) ,所以現在要來設定這部分。 32:46 📌 如何手動格式化程式碼 : 開啟命令面板 ( Ctrl + Shift + P ) 輸入「Format Document」 VS Code 會提示安裝 autopep8 或 black 格式化工具 33:06 📌 選擇格式化工具 : autopep8 :較傳統的 Python 格式化工具 black :較新的格式化工具,由 Kenneth Reitz 推薦(作者也選擇 black ) 33:30 現在,只要按 Shift + Alt + F ,就會自動整理程式碼,使其符合標準風格。 未整理的程式碼 : r=requests.get("http://coreyms.com") print ( r . status_code ) 格式化後的程式碼 : r = requests.get("http://coreyms.com") print(r.status_code) 全域 VS 工作區設定 (Global vs. Workspace Settings) 34:05 ⚠️ 注意! 在 VS Code 中,某些設定只會應用於 目前專案 (workspace settings) ,而非 全域設定 (global settings) 。 34:19 為了讓 black 成為 預設格式化工具 ,我們可以將它加入 全域設定 ( settings.json ) : 開啟 settings.json 新增以下設定 : "python.formatting.provider": "black", "editor.formatOnSave": true 這樣,每次儲存檔案時 ( Ctrl + S ),VS Code 會自動格式化程式碼! 🎉 排序 import 陳述式 (Sort Imports) 35:58 在 VS Code 中,我們也可以 自動排序 import 陳述式 。 例如,這段未排序的 import 陳述式: 透過命令面板搜尋 「Sort Imports」 ,執行後結果變為: 這樣,標準函式庫 ( math, os ) 會排在第三方函式庫 ( requests ) 之前。 程式碼 Linting(語法檢查) 37:10 Linting 會幫助我們檢查程式碼中的錯誤與潛在問題。 VS Code 內建支援 Pylint ,但可以改用其他工具,例如 flake8 、 mypy 等。 現在,我們安裝 pylint : 38:02 如果 Python 程式有錯誤,VS Code 會標示紅色底線,並顯示警告,例如: VS Code 會顯示錯誤:「 缺少括號,是否要改成 print("Hello, World!") ? 」 39:22 如果有未使用的變數,例如: VS Code 會顯示 綠色警告 :「 未使用的變數 unused_var 」,幫助我們清理不必要的程式碼。 使用 Code Runner 快速執行 Python 🔹 安裝 Code Runner 擴展 40:03 現在,我們要安裝 「Code Runner」 擴展,讓 Python 程式更容易執行: 開啟擴展管理 ( Ctrl + Shift + X ) 搜尋「Code Runner」並安裝 完成後,程式碼編輯區右上角會出現「▶ Run」按鈕 🔹 問題:Code Runner 預設使用全域 Python 41:42 目前,Code Runner 預設使用 系統全域 Python ,但我們希望它使用 虛擬環境 。 這會導致某些情況下,程式碼找不到安裝的函式庫。 🔹 修改 Code Runner 設定 開啟 settings.json 新增以下設定 : "code-runner.executorMap": { "python": "$pythonPath -u $fullFileName" }, "code-runner.clearPreviousOutput": true, "code-runner.showExecutionMessage": false 這樣: ✅ 會使用 VS Code 當前選定的 Python 直譯器(虛擬環境) ✅ 不會顯示過多的輸出資訊 ✅ 每次執行程式時,終端機會自動清除先前輸出 這是影片的 完整翻譯 (Part 3) !🎉 如果您想繼續翻譯剩餘內容,請告訴我! 😊 這是該影片的 繁體中文翻譯 (Part 4) ,涵蓋 鍵盤快捷鍵、使用者輸入 (input) 、 Git 版本控制與 GitHub 整合 ,以及 VS Code 偵錯 (Debugging) 功能 。 使用快捷鍵執行程式 (Running Code with Keyboard Shortcuts) 🔹 VS Code 預設的執行快捷鍵 45:43 如果我們 右鍵點擊 程式碼編輯區,會看到 「Run Code」 (執行程式碼)選項。這相當於點擊 右上角「▶ Run」按鈕 。 45:54 VS Code 也提供了 快捷鍵 (Keyboard Shortcut) : Ctrl + Alt + N 這樣我們就不用每次都手動點擊執行按鈕! 使用者輸入 (Handling User Input) 46:14 在 Sublime Text 中,許多用戶詢問如何處理 input() ,但 Sublime 無法直接在內建執行環境中使用 input() ,我通常建議大家 改用終端機執行程式 。 46:33 VS Code 也是類似的方法,但它 內建終端機 ,所以操作更方便。 46:44 現在,我們來寫一個簡單的 輸入與輸出 程式: 47:04 ⚠️ 注意! Code Runner 無法處理 input() ,因為 輸出視窗是唯讀的 ,所以我們需要用 終端機執行 : 選擇「Run Python File in Terminal」 輸入姓名,程式會回應對應的問候語 Git 版本控制與 GitHub 整合 (Git & GitHub Integration) 🔹 在 VS Code 中初始化 Git 專案 47:47 現在,我們要 將此專案追蹤到 Git ,並將其上傳到 GitHub 。 點擊 Git (Source Control) 圖示 點擊 「Initialize Repository」(初始化儲存庫) VS Code 會列出所有未追蹤的檔案 48:39 📌 問題:虛擬環境 ( venv ) 也被 Git 追蹤了! 這會導致 Git 追蹤數千個不必要的檔案 ,因此我們需要忽略它。 🔹 設定 .gitignore 48:58 在 VS Code 中,我們可以直接建立 .gitignore 檔案: 在專案資料夾內,點擊「新增檔案」 加入以下內容 來忽略不必要的檔案: venv/ .vscode/ 這樣,Git 就不會再追蹤 venv/ 和 .vscode/ 目錄了。 🔹 Git 操作:Stage & Commit 50:22 現在,我們可以將變更 加入 Git 暫存區 (Stage Changes) ,然後提交 (Commit)。 點擊「+」按鈕 來 Stage gitignore 和 script.py 輸入 Commit 訊息 (例如 Initial commit ) 51:08 ⚠️ 錯誤!Git 要求設定使用者名稱與 Email! 如果這是第一次使用 Git,需要在終端機執行以下指令: 然後再次嘗試 Commit 。 Git Bash 設定 (Changing the Integrated Terminal to Git Bash) 52:26 如果我們希望使用 Git Bash (而非 Windows Cmd),可以修改 VS Code 設定: 開啟 settings.json 加入以下設定 : "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" 這樣,VS Code 終端機會自動使用 Git Bash ,讓 Git 操作更方便。 將專案上傳到 GitHub (Pushing to GitHub) 打開 GitHub 並建立新儲存庫 ( sample-repo ) 複製 GitHub 提供的「Add Remote」指令 : git remote add origin https://github.com/yourusername/sample-repo.git 在 VS Code 終端機執行該指令 推送 ( Push ) 專案到 GitHub : git push -u origin master 輸入 GitHub 帳號 & 密碼 (第一次可能會要求登入) 📌 確認 GitHub 上是否出現專案 : 回到 GitHub 頁面 ,重新整理後,應該能看到剛剛上傳的檔案 🎉 VS Code 偵錯 (Debugging in VS Code) 🔹 設定中斷點 (Breakpoints) 58:49 在 VS Code 中, 可以透過「中斷點」(Breakpoints) 來偵錯 Python 程式 : 點擊行號左側的灰色區域,新增中斷點 (紅點會出現) 開啟「偵錯 (Debug)」面板 點擊「⚙ 設定」 ,選擇「Python File」 點擊「▶ Start Debugging」(F5) 在「變數監視視窗」(Variables) 可查看變數值 可以逐步執行 (Step Over, Step Into, Step Out) 我們已經學會如何: ✅ 使用快捷鍵執行 Python 程式 ( Ctrl + Alt + N ) ✅ 處理 input() 使用者輸入 ✅ 使用 Git 追蹤專案 ( git init , git commit ) ✅ 設定 .gitignore 忽略 venv 目錄 ✅ 在 VS Code 內直接推送 ( git push ) 到 GitHub ✅ 使用 VS Code 內建偵錯工具來設定中斷點 (Breakpoints) 並逐步執行 (Step Over, Step Into) 這是 完整的影片翻譯 (Part 4) !🎉 如果還有需要補充的部分,請讓我知道! 😊 這是該影片的 完整繁體中文翻譯 (Part 5) ,涵蓋 偵錯 (Debugging) 、 單元測試 (Unit Testing) 、 Zen Mode 以及 VS Code 的快捷鍵與額外設定 。 🛠 監視變數 (Watch Variables) 1:00:57 在偵錯時,我們可以 監視 (Watch) 變數的值 ,看看它是否符合預期: 點擊「+」按鈕 在「監視」(Watch) 區域新增變數 輸入 r.status_code 這裡顯示 r.status_code = 200 ,代表請求成功 1:01:21 如果這個變數是在 迴圈 (Loop) 內 ,我們可以看到它的值隨著每次迴圈運行而變化。 🛠 使用偵錯主控台 (Debug Console) 1:01:28 如果想更 互動式 地檢視變數,也可以使用 「偵錯主控台」(Debug Console) : 開啟「偵錯主控台」(Debug Console) 輸入 r.ok 結果: True (代表請求成功) 結果: True (代表請求成功) 輸入 r.url 結果顯示我們實際請求的網址 這樣,我們可以在偵錯時 即時檢視變數值 ,而不需要在程式中到處加 print() !🎉 🛠 偵錯按鈕 (Debug Controls) 1:02:42 當程式在中斷點 (Breakpoint) 停下來時,我們有幾個選擇: ✅ 繼續執行 (Continue, F5 ) – 讓程式繼續跑到下一個中斷點 ✅ 逐步執行 (Step Over, F10 ) – 執行目前這行程式,但不進入函式內部 ✅ 進入函式 (Step Into, F11 ) – 進入函式內部,逐行執行 ✅ 跳出函式 (Step Out, Shift + F11 ) – 執行完函式並返回上一層 當所有程式碼執行完畢,偵錯會自動結束。 🧪 VS Code 單元測試 (Unit Testing in VS Code) 1:03:27 現在,我們要測試 VS Code 內建的「單元測試」(Unit Testing) 支援 ! 關閉當前專案 ( File > Close Folder ) 開啟 新專案 (Unit Testing Demo) 在終端機執行: code UnitTestingDemo 這會 用 VS Code 開啟該資料夾 。 開啟命令面板 ( Ctrl + Shift + P ) 開啟命令面板 ( Ctrl + Shift + P ) 輸入「Discover Tests」(搜尋測試) 輸入「Discover Tests」(搜尋測試) 選擇「Enable and Configure Test Framework」(啟用並設定測試框架) 選擇「Enable and Configure Test Framework」(啟用並設定測試框架) 選擇測試框架 : pytest (最常用) unittest (Python 內建,這次示範使用它) unittest (Python 內建,這次示範使用它) 選擇測試檔案格式 ( test_*.py ) 選擇測試檔案格式 ( test_*.py ) VS Code 會自動偵測測試並顯示「Run Test」按鈕 VS Code 會自動偵測測試並顯示「Run Test」按鈕 1:07:03 我們可以: ✅ 執行單一測試 – 直接點擊 「Run Test」 ✅ 執行整個測試類別 – 點擊 「Run Test Class」 ✅ 查看測試結果 – 如果測試通過,會顯示「✔」;如果失敗,會顯示「❌」 1:07:38 🔴 模擬測試失敗 我們故意寫一個錯誤的測試: 執行後,VS Code 顯示「3 測試通過,1 測試失敗」,並指出錯誤發生的位置。 📌 VS Code「測試」面板 1:08:46 VS Code 有 專門的「測試」(Testing) 面板 ,可以: ✅ 查看所有測試的狀態 (哪些通過,哪些失敗) ✅ 直接執行單一測試 ✅ 只執行失敗的測試 (不必重跑所有測試) 這讓測試流程變得更直觀且有效率!🎉 🖥 Zen Mode – 無干擾模式 (Distraction-Free Coding in VS Code) 1:11:04 Zen Mode 是 VS Code 的「無干擾模式」 ,讓我們可以 專注寫程式 : 開啟命令面板 ( Ctrl + Shift + P ) 📌 Zen Mode 會隱藏 : 活動欄 (Activity Bar) 狀態列 (Status Bar) 終端機 (Terminal) 等其他 UI 這樣 VS Code 看起來就像 Sublime Text 的極簡模式 ,專注於程式碼與輸出! ⌨ VS Code 快捷鍵 (Keyboard Shortcuts) 1:13:30 如果想學習 VS Code 的所有快捷鍵 : 開啟命令面板 ( Ctrl + Shift + P ) 搜尋「Keyboard Shortcuts」(鍵盤快捷鍵) 這裡列出了所有 VS Code 支援的快捷鍵,例如: ✅ Ctrl + P – 快速開啟檔案 ✅ Ctrl + Shift + F – 全域搜尋 ✅ Ctrl + D – 選取多個相同字串 如果你想提高 VS Code 的使用效率,這是很好的資源!🚀 我們學到了: ✅ 如何使用 VS Code 進行偵錯 (Debugging) ✅ 如何監視變數 (Watch Variables) & 使用 Debug Console ✅ 如何執行 Python 單元測試 (Unit Testing) ✅ 如何使用「測試面板」來管理測試結果 ✅ 如何開啟 Zen Mode 進行無干擾編程 ✅ 如何查看 VS Code 的快捷鍵參考文件 這是 完整的 VS Code Python 影片繁體中文翻譯 🎉 如果還有任何問題,請讓我知道!😊 好的!這是完整的 VS Code Python 開發環境設定與功能指南 ,包含 講者的原文翻譯 以及 對應的 VS Code 操作步驟與設定 ,方便你邊聽影片邊對照操作! Hey there, how's it going everybody? In this video, we're gonna be learning how to install Visual Studio Code and set up a Python development environment. Also, we're going to go over the different features of this editor and see why it's so nice for Python development. So we'll cover how to easily switch between editors, how to debug applications, how Git integration works, look at unit testing capabilities, and a few other things. 👉 VS Code 安裝步驟: 前往 VS Code 官網 ( code.visualstudio.com )。 下載適用於作業系統的版本 (Windows / Mac / Linux)。 執行安裝程式 ,選擇安裝目錄並勾選「建立桌面捷徑」。 安裝完成後,開啟 VS Code 。 So when we first run VS Code, it's going to open their getting started page in the browser and also it's going to show us their welcome screen. 執行 Visual Studio Code 應用程式 。 關閉歡迎頁面(Welcome Page) 。 調整視窗大小以適應編輯需求 。 可透過 Ctrl + (放大)與 Ctrl - (縮小)調整字體大小 ,或在 設定 (Settings) 中搜尋 Zoom Level 來手動設定縮放比例。 🔹 2. 使用 IntelliSense(智慧提示) Watch how the IntelliSense works. This is built into VS Code and it's going to show us the attributes and methods that we can use for different objects. 👉 測試 IntelliSense 輸入 requests. 並按 . (點號) ,VS Code 會顯示可用的方法與屬性,如: get() post() session() 右鍵點擊方法名稱 ,可選擇: 「前往定義 (Go to Definition)」 :查看原始碼 「快速查看定義 (Peek Definition)」 :小彈窗檢視定義 「前往定義 (Go to Definition)」 :查看原始碼 「快速查看定義 (Peek Definition)」 :小彈窗檢視定義 🔹 3. 偵錯 (Debugging) 功能 To put in a breakpoint, we can simply come over here into the gutter, where it has this red line. If I click that, we have now added a breakpoint into our script. 👉 設定中斷點 (Breakpoints) 點擊行號左側,新增中斷點(紅點會出現)。 開啟「偵錯 (Debug)」面板。 點擊「⚙ 設定」 > 選擇「Python File」。 { "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}" } ] } 👉 使用 Debug Console 觀察變數 🔹 4. Git 版本控制與 GitHub 整合 Let's say that I wanted to track this project with Git and upload it to GitHub. 👉 設定 .gitignore 👉 推送 (Push) 至 GitHub 🔹 5. Zen Mode – 無干擾模式 影片時間戳記: 1:12:40 Zen Mode allows you to focus more on your code and your output. 🔹 6. VS Code 快捷鍵 (Keyboard Shortcuts) 影片時間戳記: 1:13:36 If you'd like to see some of these keyboard shortcuts for yourself, they make it easy to learn. 我們學會如何: ✅ 安裝 VS Code 並設定 Python 開發環境 ✅ 使用 IntelliSense 提供的智慧提示 ✅ 設定與使用偵錯 (Debugging) 工具 ✅ 使用 Git 進行版本控制並推送至 GitHub ✅ 執行 Python 單元測試 (Unit Testing) ✅ 開啟 Zen Mode 進行無干擾編程 ✅ 學習 VS Code 的快捷鍵與進階技巧 這是一份完整的 VS Code Python 開發指南 , 包含講者的完整內容翻譯 ,以及 對應的 VS Code 操作步驟與設定 ,讓你可以 邊聽影片邊對照操作 !🚀 如果有需要修改或補充的地方,請告訴我!😊 手機使用VPN進入NAS、DaikinAPP時,仍能使用其他APP如銀行,連上WIFI 或行動網路 為了避免手機使用VPN進入NAS、DaikinAPP時,仍能使用其他APP如銀行,連上WIFI 或行動網路,要修改Router Policy設定?需要把家中屬於VPN的網段設備與其他區隔?要如何設定? 為了達成您的需求: ✅ 手機連上 VPN(例如連回家中 TP-Link ER... 第一次使用 VS Code 的完整指南 📌 第一次使用 VS Code 的完整指南 📍 適用對象: Windows 使用者, 第一次使用 VS Code ,希望 詳細步驟 避免出錯。 這份指南會 一步步 帶你從 安裝、設定、基本操作 到 執行程式 ,確保你能順利使用 VS Code!🚀 🔹 1.... TP-Link Omada ER605 管理介面 您上傳的這張圖為 TP-Link Omada ER605 管理介面中,某一設備(MAC 為 B0-19-21-FA-16-4B )的詳細設定畫面。以下我逐項為您解說: ✅ 一、上半部:設備基本資訊設定區 項目 說明 是否必要 建議設定 名稱 預設為... 金屬咖啡濾網沖洗 如果金屬咖啡濾網的過濾速度變慢甚至無法過濾,可能是因為咖啡油脂、細粉或礦物沉積物堵塞了網孔。你可以嘗試以下方法來清潔和恢復濾網的過濾效果: 1. 基本沖洗(每日保養) 熱水沖洗 :每次使用後立即用熱水沖洗,防止咖啡殘渣附著。 反向沖洗 :用水龍頭的水從 反方向 沖洗,幫...
📥 下载地址(文章结尾)
装机神器,专门安装各种电脑系统,各种品牌全可以。