」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > Python、Pycharm、Selenium 和 Web 驅動程式的安裝

Python、Pycharm、Selenium 和 Web 驅動程式的安裝

發佈於2024-07-29
瀏覽:374

Installation of Python, Pycharm, Selenium and Web Drivers

Installation Guide: Python, PyCharm, Selenium and Web Drivers

This guide is intended to simplify the installation process for Python, PyCharm, and Selenium. I've created this draft to help ease the difficulty many people face when searching for comprehensive installation instructions. Whether for practice or work, following these steps will ensure a smooth setup experience.

Step 1: Install Python

Windows

  1. Download Python:

    • Go to the official Python website.
    • Download the latest version of Python.
  2. Run the Installer:

    • Run the downloaded installer.
    • Check the box "Add Python to PATH".
    • Click "Install Now".
    • Click on "Disable MAX PATH LIMIT(255)".

macOS

  1. Download Python:

    • Go to the official Python website.
    • Download the latest version of Python.
  2. Run the Installer:

    • Open the downloaded .pkg file.
    • Follow the installation instructions. Sure! Here are the installation instructions for Python on macOS:

Installation Instructions for Python on macOS

Step 1: Download Python

  1. Go to the Official Python Website:

    • Open your web browser and navigate to the official Python website.
  2. Download the Latest Version:

    • The website should automatically detect your operating system and suggest the latest version for macOS.
    • Click the "Download Python [version]" button to download the installer.

Step 2: Install Python

  1. Run the Installer:

    • Once the download is complete, locate the downloaded file, typically in your Downloads folder.
    • Double-click the .pkg file to open the Python installer.
  2. Follow the Installation Steps:

    • The installer will open a new window. Click "Continue" to begin the installation process.
    • Review and agree to the license agreement.
    • Choose the installation location. The default location is usually fine.
    • Click "Install" to start the installation.
    • You may be prompted to enter your macOS password to authorize the installation. Enter your password and click "Install Software".
  3. Complete the Installation:

    • Once the installation is complete, click "Close" to exit the installer.

Step 3: Verify the Installation

  1. Open Terminal:

    • You can find Terminal in Applications > Utilities or by using Spotlight Search (Cmd Space and type "Terminal").
  2. Check Python Version:

    • In Terminal, type the following command and press Enter:
     python3 --version
    
  • You should see the version of Python you installed. For example:

     Python 3.x.x
    
  1. Check pip Version:

    • In Terminal, type the following command and press Enter:
     pip3 --version
    
  • You should see the version of pip installed with Python. For example:

     pip 21.x.x from /Library/Frameworks/Python.framework/Versions/3.x/lib/python3.x/site-packages/pip (python 3.x)
    

Step 4: Set Up Environment Variables (Optional)

  1. Add Python to PATH:

    • Open Terminal and enter the following command to open the .bash_profile or .zshrc file in a text editor:
     nano ~/.zshrc
    

    or

     nano ~/.bash_profile
    
  2. Edit the File:

    • Add the following line to the file:
     export PATH="/Library/Frameworks/Python.framework/Versions/3.x/bin:$PATH"
    
  • Save the file by pressing Ctrl O, then press Enter. Exit by pressing Ctrl X.
  1. Apply Changes:

    • In Terminal, run the following command to apply the changes:
     source ~/.zshrc
    

    or

     source ~/.bash_profile
    

Step 5: Install Virtualenv (Optional)

  1. Install virtualenv:

    • To create isolated Python environments, you can use virtualenv. Install it using pip:
     pip3 install virtualenv
    
  2. Create a Virtual Environment:

    • Navigate to your project directory:
     cd path/to/your/project
    
  • Create a virtual environment:

     virtualenv venv
    
  1. Activate the Virtual Environment:

    • Activate the virtual environment:
     source venv/bin/activate
    
  • You will see (venv) in your terminal prompt, indicating the virtual environment is active.
  1. Deactivate the Virtual Environment:

    • To deactivate the virtual environment, simply run:
     deactivate
    

You have now installed Python on your macOS system, set up your environment variables, and optionally installed virtualenv for managing your projects.

Linux

  1. Using APT (Debian/Ubuntu):
   sudo apt update
   sudo apt install python3 python3-pip
  1. Using DNF (Fedora):
   sudo dnf install python3 python3-pip

Step 2: Install PyCharm

  1. Download PyCharm:

    • Go to the JetBrains PyCharm website.
    • Download the Community Edition (free) or Professional Edition (paid).
    • Always remember to Check the System version and download compatible version else, you will able to install but not able open the pycharm software
  2. Run the Installer:

    • Follow the installation instructions provided by JetBrains.
    • Certainly! Here are the installation instructions for PyCharm as provided by JetBrains:

Installation Instructions for PyCharm

Windows

  1. Download PyCharm:

    • Go to the JetBrains PyCharm download page.
    • Download the Community Edition (free) or Professional Edition (paid).
  2. Run the Installer:

    • Double-click the downloaded .exe file to launch the installer.
    • Follow the setup wizard:
      • Click "Next" to continue.
      • Choose the installation location and click "Next".
      • Select the desired installation options:
      • Create a desktop shortcut.
      • Add the “bin” folder to the PATH (recommended).
      • Associate .py files with PyCharm.
      • Add an open folder as a project option.
      • Click "Install".
    • Once the installation is complete, click "Finish".
  3. Launch PyCharm:

    • After the installation, you can start PyCharm by double-clicking the PyCharm shortcut on your desktop or by searching for PyCharm in the Start menu.

macOS

  1. Download PyCharm:

    • Go to the JetBrains PyCharm download page.
    • Download the Community Edition (free) or Professional Edition (paid).
  2. Install PyCharm:

    • Open the downloaded .dmg file.
    • Drag and drop the PyCharm application into the Applications folder.
  3. Launch PyCharm:

    • Open Finder and go to the Applications folder.
    • Find PyCharm and double-click to open it.
    • If you see a warning about opening an application downloaded from the internet, click "Open".

Linux

  1. Download PyCharm:

    • Go to the JetBrains PyCharm download page.
    • Download the tar.gz package for the Community Edition (free) or Professional Edition (paid).
  2. Install PyCharm:

    • Open your terminal.
    • Navigate to the directory where the tar.gz file was downloaded.
    • Extract the tar.gz file:
     tar -xzf pycharm-*.tar.gz
    
  • Move to the extracted directory:

     cd pycharm-*/
    
  • Run PyCharm:

     ./bin/pycharm.sh
    
  1. Create a Desktop Entry (optional):
    • While running PyCharm, go to the main menu and select "Tools" > "Create Desktop Entry".

First-time Startup

  1. Activate PyCharm:

    • On the first startup, you will be prompted to activate PyCharm.
    • For the Community Edition, select "Evaluate for free" and click "Evaluate".
    • For the Professional Edition, enter your JetBrains account credentials or use a license key.
  2. Customize PyCharm:

    • Choose your UI theme (Light or Dark).
    • Configure additional settings as needed.
  3. Create or Open a Project:

    • You can now create a new project, open an existing project, or check out a project from version control.

For more detailed instructions and troubleshooting, refer to the official PyCharm installation guide.

Step 3: Install Selenium

  1. Using pip:

    • Open your command line or terminal, Run as Administrator
    • Install Selenium using the following command:
     pip install selenium
    

Step 4: Verify Installation

Check Python Installation:

   python --version

Check pip Installation:

   pip --version

Update pip Installation:

python -m pip install --upgrade pip
  1. Verify if Selenium Installed Properly or Not:
pip show selenium

You should get the selenium details

Web Drivers:
For the latest Selenium Version: 4.22.0, Web Drivers have been pre installed
You can verify in path:

C:\Users\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver

you will see the wedrivers for IE, Chrome, Edge, FireFox, Remote, Safari, Chromium.

Verify Selenium Installation:

  • Open a Python interactive shell by typing python in your command line or terminal.
  • Run the following commands:

     import selenium
     print(selenium.__version__)
    

Example: Basic Selenium Script

Here's a simple script to verify your Selenium setup. This script opens a web browser and navigates to a website.

  1. Install WebDriver:

    • Download the appropriate WebDriver for your browser (e.g., ChromeDriver for Chrome) from Selenium’s official site.
    • Make sure to place the WebDriver executable in a directory that is in your PATH.
  2. Create a Python Script:

   from selenium import webdriver

   # Initialize the WebDriver (assuming ChromeDriver is in your PATH)
   driver = webdriver.Chrome()

   # Open a website
   driver.get("https://www.python.org")

   # Print the title of the page
   print(driver.title)

   # Close the browser
   driver.quit()
  1. Run the Script:

    • Save the script as test_selenium.py.
    • Run the script in your command line or terminal:
     python test_selenium.py
    

If everything is set up correctly, you should see the browser open, navigate to the Python website, and print the page title in the console.

Additional Selenium Web Drivers Configuration:

If you are using earlier versions or not able to see webdriver, you can download them or For more details you can see visit:
https://pypi.org/project/selenium/

After downloading the files, extract the files and copy the drivers.exe and place in the path or accordingly to your system files path

C:\Users\AppData\Local\Programs\Python\Python311\

This is a pre installed path for python that is available in the environment variables, which you pretty much can use without errors

or You can create a folder in "C drive" and add that file path in environment variables.

Driver "PATH" Configuration:
Here are the instructions on how to add the path C:\Users\AppData\Local\Programs\Python\Python311\ or any "PATH" to the environment variables in Windows:

Adding Python Path to Environment Variables in Windows

Step 1: Open Environment Variables Settings

  1. Open System Properties:

    • Press Win Pause/Break to open the System window.
    • Alternatively, you can right-click on the This PC or Computer icon on your desktop or in File Explorer and select Properties.
  2. Open Advanced System Settings:

    • In the System window, click on Advanced system settings on the left-hand side.
  3. Open Environment Variables:

    • In the System Properties window, click on the Environment Variables... button near the bottom.

Step 2: Edit the PATH Variable

  1. Locate the PATH Variable:

    • In the Environment Variables window, you will see two sections: User variables and System variables.
    • Scroll down in the System variables section and find the variable named Path. Select it and click on the Edit... button.
  2. Add New Path:

    • In the Edit Environment Variable window, you will see a list of paths. Click on the New button to add a new path.
    • Enter the path C:\Users\AppData\Local\Programs\Python\Python311\ in the new entry.
  3. Save Changes:

    • After adding the path, click OK to close the Edit Environment Variable window.
    • Click OK again to close the Environment Variables window.
    • Finally, click OK to close the System Properties window.

Step 3: Verify the Path Addition

  1. Open Command Prompt:

    • Press Win R, type cmd, and press Enter to open the Command Prompt.
  2. Check Python Version:

    • Type the following command and press Enter:
     python --version
    
  • You should see the version of Python installed in C:\Users\AppData\Local\Programs\Python\Python311\

If everything is set up correctly, the command prompt should display the Python version, confirming that the path has been successfully added to the environment variables.

These steps ensure that Python can be accessed from any command prompt window without needing to specify the full path to the executable each time.


版本聲明 本文轉載於:https://dev.to/michael_chepala_7267688a0/installation-of-python-pycharm-selenium-and-web-drivers-509?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 儘管程式碼有效,為什麼 POST 請求無法擷取 PHP 中的輸入?
    儘管程式碼有效,為什麼 POST 請求無法擷取 PHP 中的輸入?
    解決PHP 中的POST 請求故障在提供的程式碼片段:action=''而非:action="<?php echo $_SERVER['PHP_SELF'];?>";?>"檢查$_POST陣列:表單提交後使用 var_dump 檢查 $_POST 陣列的內容...
    程式設計 發佈於2024-12-18
  • Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta 中的列偏移發生了什麼事?
    Bootstrap 4 Beta:列偏移的刪除和恢復Bootstrap 4 在其Beta 1 版本中引入了重大更改柱子偏移了。然而,隨著 Beta 2 的後續發布,這些變化已經逆轉。 從 offset-md-* 到 ml-auto在 Bootstrap 4 Beta 1 中, offset-md-*...
    程式設計 發佈於2024-12-18
  • 在 Go 中使用 WebSocket 進行即時通信
    在 Go 中使用 WebSocket 進行即時通信
    构建需要实时更新的应用程序(例如聊天应用程序、实时通知或协作工具)需要一种比传统 HTTP 更快、更具交互性的通信方法。这就是 WebSockets 发挥作用的地方!今天,我们将探讨如何在 Go 中使用 WebSocket,以便您可以向应用程序添加实时功能。 在这篇文章中,我们将介绍: WebSoc...
    程式設計 發佈於2024-12-18
  • 大批
    大批
    方法是可以在物件上呼叫的 fns 數組是對象,因此它們在 JS 中也有方法。 slice(begin):將陣列的一部分提取到新數組中,而不改變原始數組。 let arr = ['a','b','c','d','e']; // Usecase: Extract till index ...
    程式設計 發佈於2024-12-18
  • 如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    如何在 PHP 中組合兩個關聯數組,同時保留唯一 ID 並處理重複名稱?
    在 PHP 中組合關聯數組在 PHP 中,將兩個關聯數組組合成一個數組是常見任務。考慮以下請求:問題描述:提供的代碼定義了兩個關聯數組,$array1 和 $array2。目標是建立一個新陣列 $array3,它合併兩個陣列中的所有鍵值對。 此外,提供的陣列具有唯一的 ID,而名稱可能重疊。要求是建...
    程式設計 發佈於2024-12-18
  • 插入資料時如何修復「常規錯誤:2006 MySQL 伺服器已消失」?
    插入資料時如何修復「常規錯誤:2006 MySQL 伺服器已消失」?
    插入記錄時如何解決「一般錯誤:2006 MySQL 伺服器已消失」介紹:將資料插入MySQL 資料庫有時會導致錯誤「一般錯誤:2006 MySQL 伺服器已消失」。當與伺服器的連線遺失時會出現此錯誤,通常是由於 MySQL 配置中的兩個變數之一所致。 解決方案:解決此錯誤的關鍵是調整wait_tim...
    程式設計 發佈於2024-12-18
  • CSS3 轉場是否提供事件來偵測起點和終點?
    CSS3 轉場是否提供事件來偵測起點和終點?
    了解 CSS3 過渡事件CSS3 過渡允許在 Web 元素上實現流暢的動畫和視覺效果。為了增強使用者體驗並使操作與這些轉換同步,監控其進度非常重要。本文解決了 CSS3 是否提供事件來檢查過渡何時開始或結束的問題。 W3C CSS 過渡草案W3C CSS 過渡草案規定CSS 轉換會觸發對應的 DOM...
    程式設計 發佈於2024-12-18
  • Java 中可以手動釋放記憶體嗎?
    Java 中可以手動釋放記憶體嗎?
    Java 中的手動內存釋放與垃圾回收與C 不同,Java 採用託管內存框架來處理內存分配和釋放由垃圾收集器(GC) 自動執行。這種自動化方法可以提高記憶體利用率並防止困擾 C 程式的記憶體洩漏。 Java 中可以手動釋放記憶體嗎? 由於 Java 的記憶體管理是由GC,它沒有提供像 C 中的 fre...
    程式設計 發佈於2024-12-18
  • Java 1.6 中如何可靠地確定檔案是否為符號連結?
    Java 1.6 中如何可靠地確定檔案是否為符號連結?
    在 Java 1.6 中驗證符號連結確定符號連結的存在對於各種文件處理操作至關重要。在 Java 中,識別符號連結時需要考慮一些潛在問題,特別是在目錄遍歷的上下文中。 檢查符號連結的常見方法是比較文件的絕對路徑和規範路徑。規範路徑表示檔案的標準化路徑,而絕對路徑可能包括符號連結。傳統上,概念是如果這...
    程式設計 發佈於2024-12-17
  • 如何使背景顏色透明,同時保持文字不透明?
    如何使背景顏色透明,同時保持文字不透明?
    背景顏色的不透明度而不影響文本在Web 開發領域,實現透明度通常對於增強視覺吸引力和網站元素的功能。常見的要求是對 div 背景套用透明度,同時保留所包含文字的不透明度。這可能會帶來挑戰,特別是在確保跨瀏覽器相容性方面。 rgba 解決方案最有效且廣泛支持的解決方案是利用「RGBA」(紅、綠、藍、A...
    程式設計 發佈於2024-12-17
  • PHP 字串比較:`==`、`===` 或 `strcmp()` – 您應該使用哪個運算子?
    PHP 字串比較:`==`、`===` 或 `strcmp()` – 您應該使用哪個運算子?
    PHP 中的字串比較:'=='、'===' 或 'strcmp()'? PHP 中的字串比較PHP 可以使用不同的運算子來完成,例如「==」、「===」或「strcmp()」函數。此比較涉及檢查兩個字串是否相等。 '==' 與'...
    程式設計 發佈於2024-12-17
  • 如何自訂操作列的按鈕和外觀?
    如何自訂操作列的按鈕和外觀?
    自訂操作欄的按鈕和外觀要實現所需的自訂操作欄外觀,請考慮以下步驟: 1.建立自訂操作按鈕若要將圖片包含為按鈕,請透過擴充Button類別來定義自訂視圖。然後可以將此自訂視圖顯示在 ActionBar 上,如下所示:<Button android:id="@ id/my_cus...
    程式設計 發佈於2024-12-17
  • 介紹 Laravel 的履歷解析器/CV 解析器
    介紹 Laravel 的履歷解析器/CV 解析器
    照片由 Mohammad Rahmani 在 Unsplash 上拍攝 基於我們的 Resume/CV Parsing AI API 端點的流行,我們專門為您製作了一個專門的輕量級 Laravel 庫。 招募的未來:敏銳、精確且對 Laravel 友好 這個新套件可在 github...
    程式設計 發佈於2024-12-17
  • 如何在 PHP 中重新格式化日期以方便使用者顯示?
    如何在 PHP 中重新格式化日期以方便使用者顯示?
    在PHP 中重新格式化日期使用資料庫中儲存的日期時,通常需要重新格式化它們以便於使用者友好的顯示。對於以「2009-08-12」等格式儲存的日期尤其如此,人類本質上無法讀取這種格式。 為了解決這個問題,PHP 提供了各種工具,使您能夠輕鬆重新格式化日期。一種有效的方法是使用 DateTime 類,它...
    程式設計 發佈於2024-12-17
  • 為什麼我無法將元素新增到具有通配符泛型類型(`?extends Parent`)的 Java 集合中?
    為什麼我無法將元素新增到具有通配符泛型類型(`?extends Parent`)的 Java 集合中?
    型安與通配符泛型:了解禁止修飾符在Java 使用泛型集合時,通配符泛型的概念可以引入某些最初看起來可能違反直覺的限制。一個典型的例子是無法在具有通配符泛型類型的 Java 集合中新增值。 考慮以下程式碼片段:List<? extends Parent> list = ...; Paren...
    程式設計 發佈於2024-12-17

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3