Python、Pycharm、Selenium、および Web ドライバーのインストール

WBOY
リリース: 2024-07-18 12:34:48
オリジナル
924 人が閲覧しました

Installation of Python, Pycharm, Selenium and Web Drivers

インストール ガイド: Python、PyCharm、Selenium、および Web ドライバー

このガイドは、Python、PyCharm、および Selenium のインストール プロセスを簡素化することを目的としています。私は、包括的なインストール手順を検索するときに多くの人が直面する困難を軽減するためにこのドラフトを作成しました。練習でも仕事でも、次の手順に従うことでスムーズなセットアップが可能になります。

ステップ 1: Python をインストールする

  1. Python をダウンロード:

    • Python の公式 Web サイトにアクセスします。
    • Python の最新バージョンをダウンロードします。
  2. インストーラーを実行します:

    • ダウンロードしたインストーラーを実行します。
    • 「Python を PATH に追加」チェックボックスをオンにします。
    • 「今すぐインストール」をクリックします。
    • 「最大パス制限を無効にする(255)」をクリックします。

macOS

  1. Python をダウンロード:

    • Python の公式 Web サイトにアクセスします。
    • Python の最新バージョンをダウンロードします。
  2. インストーラーを実行します:

    • ダウンロードした .pkg ファイルを開きます。
    • インストール手順に従ってください。 もちろん! macOS での Python のインストール手順は次のとおりです:

macOS での Python のインストール手順

ステップ 1: Python をダウンロードする

  1. Python の公式 Web サイトに移動します:

    • Web ブラウザを開いて、Python の公式 Web サイトに移動します。
  2. 最新バージョンをダウンロード:

    • Web サイトはオペレーティング システムを自動的に検出し、macOS の最新バージョンを提案します。
    • 「Python [バージョン] をダウンロード」ボタンをクリックしてインストーラーをダウンロードします。

ステップ 2: Python をインストールする

  1. インストーラーを実行します:

    • ダウンロードが完了したら、ダウンロードしたファイル (通常はダウンロード フォルダー) を見つけます。
    • .pkg ファイルをダブルクリックして、Python インストーラーを開きます。
  2. インストール手順に従います:

    • インストーラーによって新しいウィンドウが開きます。 「続行」をクリックしてインストールプロセスを開始します。
    • 使用許諾契約を確認して同意します。
    • 設置場所を選択してください。通常はデフォルトの場所で問題ありません。
    • 「インストール」をクリックしてインストールを開始します。
    • インストールを承認するために、macOS パスワードの入力を求められる場合があります。パスワードを入力し、「ソフトウェアをインストール」をクリックします。
  3. インストールを完了します:

    • インストールが完了したら、「閉じる」をクリックしてインストーラーを終了します。

ステップ 3: インストールを確認する

  1. ターミナルを開きます:

    • ターミナルはアプリケーション > にあります。ユーティリティを使用するか、Spotlight 検索 (Cmd + スペースを押して「ターミナル」と入力) を使用します。
  2. Python バージョンの確認:

    • ターミナルで次のコマンドを入力し、Enter キーを押します。
     python3 --version
    
    ログイン後にコピー
  • インストールした Python のバージョンが表示されるはずです。例:

     Python 3.x.x
    
    ログイン後にコピー
  1. pip バージョンの確認:

    • ターミナルで次のコマンドを入力し、Enter キーを押します。
     pip3 --version
    
    ログイン後にコピー
  • Python とともにインストールされた pip のバージョンが表示されるはずです。例:

     pip 21.x.x from /Library/Frameworks/Python.framework/Versions/3.x/lib/python3.x/site-packages/pip (python 3.x)
    
    ログイン後にコピー

ステップ 4: 環境変数を設定する (オプション)

  1. Python を PATH に追加します:

    • ターミナルを開き、次のコマンドを入力して、テキスト エディターで .bash_profile または .zshrc ファイルを開きます。
     nano ~/.zshrc
    
    ログイン後にコピー

    または

     nano ~/.bash_profile
    
    ログイン後にコピー
  2. ファイルを編集します:

    • 次の行をファイルに追加します。
     export PATH="/Library/Frameworks/Python.framework/Versions/3.x/bin:$PATH"
    
    ログイン後にコピー
  • Ctrl + O を押してファイルを保存し、Enter を押します。 Ctrl + X を押して終了します。
  1. 変更を適用:

    • ターミナルで次のコマンドを実行して変更を適用します。
     source ~/.zshrc
    
    ログイン後にコピー

    または

     source ~/.bash_profile
    
    ログイン後にコピー

ステップ 5: Virtualenv をインストールする (オプション)

  1. virtualenv をインストールします:

    • 分離された Python 環境を作成するには、virtualenv を使用できます。 pip を使用してインストールします。
     pip3 install virtualenv
    
    ログイン後にコピー
  2. 仮想環境の作成:

    • プロジェクト ディレクトリに移動します。
     cd path/to/your/project
    
    ログイン後にコピー
  • 仮想環境を作成します:

     virtualenv venv
    
    ログイン後にコピー
  1. 仮想環境をアクティブ化します:

    • 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.


以上がPython、Pycharm、Selenium、および Web ドライバーのインストールの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:dev.to
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!