”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > Python、Pycharm、Selenium 和 Web 驱动程序的安装

Python、Pycharm、Selenium 和 Web 驱动程序的安装

发布于2024-07-29
浏览:528

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]删除
最新教程 更多>
  • 如何从PHP中的Unicode字符串中有效地产生对URL友好的sl。
    如何从PHP中的Unicode字符串中有效地产生对URL友好的sl。
    为有效的slug生成首先,该函数用指定的分隔符替换所有非字母或数字字符。此步骤可确保slug遵守URL惯例。随后,它采用ICONV函数将文本简化为us-ascii兼容格式,从而允许更广泛的字符集合兼容性。接下来,该函数使用正则表达式删除了不需要的字符,例如特殊字符和空格。此步骤可确保slug仅包含...
    编程 发布于2025-03-31
  • 哪种方法更有效地用于点 - 填点检测:射线跟踪或matplotlib \的路径contains_points?
    哪种方法更有效地用于点 - 填点检测:射线跟踪或matplotlib \的路径contains_points?
    在Python Matplotlib's path.contains_points FunctionMatplotlib's path.contains_points function employs a path object to represent the polygon.它...
    编程 发布于2025-03-31
  • 如何使用Regex在PHP中有效地提取括号内的文本
    如何使用Regex在PHP中有效地提取括号内的文本
    php:在括号内提取文本在处理括号内的文本时,找到最有效的解决方案是必不可少的。一种方法是利用PHP的字符串操作函数,如下所示: 作为替代 $ text ='忽略除此之外的一切(text)'; preg_match('#((。 &&& [Regex使用模式来搜索特...
    编程 发布于2025-03-31
  • 如何使用不同数量列的联合数据库表?
    如何使用不同数量列的联合数据库表?
    合并列数不同的表 当尝试合并列数不同的数据库表时,可能会遇到挑战。一种直接的方法是在列数较少的表中,为缺失的列追加空值。 例如,考虑两个表,表 A 和表 B,其中表 A 的列数多于表 B。为了合并这些表,同时处理表 B 中缺失的列,请按照以下步骤操作: 确定表 B 中缺失的列,并将它们添加到表的末...
    编程 发布于2025-03-31
  • 为什么我的CSS背景图像出现?
    为什么我的CSS背景图像出现?
    故障排除:CSS背景图像未出现 ,您的背景图像尽管遵循教程说明,但您的背景图像仍未加载。图像和样式表位于相同的目录中,但背景仍然是空白的白色帆布。而不是不弃用的,您已经使用了CSS样式: bockent {背景:封闭图像文件名:背景图:url(nickcage.jpg); 如果您的html,css...
    编程 发布于2025-03-31
  • 您可以使用CSS在Chrome和Firefox中染色控制台输出吗?
    您可以使用CSS在Chrome和Firefox中染色控制台输出吗?
    在javascript console 中显示颜色是可以使用chrome的控制台显示彩色文本,例如红色的redors,for for for for错误消息?回答是的,可以使用CSS将颜色添加到Chrome和Firefox中的控制台显示的消息(版本31或更高版本)中。要实现这一目标,请使用以下模...
    编程 发布于2025-03-31
  • 您如何在Laravel Blade模板中定义变量?
    您如何在Laravel Blade模板中定义变量?
    在Laravel Blade模板中使用Elegance 在blade模板中如何分配变量对于存储以后使用的数据至关重要。在使用“ {{}}”分配变量的同时,它可能并不总是最优雅的解决方案。幸运的是,Blade通过@php Directive提供了更优雅的方法: $ old_section =“...
    编程 发布于2025-03-31
  • 如何从PHP中的数组中提取随机元素?
    如何从PHP中的数组中提取随机元素?
    从阵列中的随机选择,可以轻松从数组中获取随机项目。考虑以下数组:; 从此数组中检索一个随机项目,利用array_rand( array_rand()函数从数组返回一个随机键。通过将$项目数组索引使用此键,我们可以从数组中访问一个随机元素。这种方法为选择随机项目提供了一种直接且可靠的方法。
    编程 发布于2025-03-31
  • 对象拟合:IE和Edge中的封面失败,如何修复?
    对象拟合:IE和Edge中的封面失败,如何修复?
    To resolve this issue, we employ a clever CSS solution that solves the problem:position: absolute;top: 50%;left: 50%;transform: translate(-50%, -50%)...
    编程 发布于2025-03-31
  • PHP阵列键值异常:了解07和08的好奇情况
    PHP阵列键值异常:了解07和08的好奇情况
    PHP数组键值问题,使用07&08 在给定数月的数组中,键值07和08呈现令人困惑的行为时,就会出现一个不寻常的问题。运行print_r($月份)返回意外结果:键“ 07”丢失,而键“ 08”分配给了9月的值。此问题源于PHP对领先零的解释。当一个数字带有0(例如07或08)的前缀时,PHP将...
    编程 发布于2025-03-31
  • 如何在无序集合中为元组实现通用哈希功能?
    如何在无序集合中为元组实现通用哈希功能?
    在未订购的集合中的元素要纠正此问题,一种方法是手动为特定元组类型定义哈希函数,例如: template template template 。 struct std :: hash { size_t operator()(std :: tuple const&tuple)const {...
    编程 发布于2025-03-31
  • 如何在Java中执行命令提示命令,包括目录更改,包括目录更改?
    如何在Java中执行命令提示命令,包括目录更改,包括目录更改?
    在java 通过Java通过Java运行命令命令可能很具有挑战性。尽管您可能会找到打开命令提示符的代码段,但他们通常缺乏更改目录并执行其他命令的能力。 solution:使用Java使用Java,使用processBuilder。这种方法允许您:启动一个过程,然后将其标准错误重定向到其标准输出。...
    编程 发布于2025-03-31
  • 哪种在JavaScript中声明多个变量的方法更可维护?
    哪种在JavaScript中声明多个变量的方法更可维护?
    在JavaScript中声明多个变量:探索两个方法在JavaScript中,开发人员经常遇到需要声明多个变量的需要。对此的两种常见方法是:在单独的行上声明每个变量: 当涉及性能时,这两种方法本质上都是等效的。但是,可维护性可能会有所不同。 第一个方法被认为更易于维护。每个声明都是其自己的语句,使其...
    编程 发布于2025-03-31
  • 如何处理PHP文件系统功能中的UTF-8文件名?
    如何处理PHP文件系统功能中的UTF-8文件名?
    在PHP的Filesystem functions中处理UTF-8 FileNames 在使用PHP的MKDIR函数中含有UTF-8字符的文件很多flusf-8字符时,您可能会在Windows Explorer中遇到comploreer grounder grounder grounder gro...
    编程 发布于2025-03-31

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3