> For the complete documentation index, see [llms.txt](https://tester-bszelag.gitbook.io/software-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tester-bszelag.gitbook.io/software-testing/python-3.x.md).

# Python 3.X

## Python 3

### install python

{% embed url="<https://www.python.org/>" %}
Just download and install from main website of python.
{% endembed %}

### Set environment Variables

1. open "environment Variables"
2. set at System Variables New variable "PYTHONPATH"
3. Add paths like on first screen
4. Create on Variable Path (System variables) a new variable named %PYTHONPATH%
5. The Paths of PYTHONPATH will be use in Path by %PYTHONPATH%

![Add paths to python](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MFAfOYU4v2f4pgtC1qY%2F-MFAgCsLsqnF6cI88lxA%2Fimage.png?alt=media\&token=691b6efd-4434-4c6e-9f55-0209266d7784)

![%PYTHONPATH%](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MFAfOYU4v2f4pgtC1qY%2F-MFAglH-juvFyWk6XTZ7%2Fimage.png?alt=media\&token=5c678f10-1601-4f95-8032-85cbc2f58e91)

At command prompt / powershell just try command to check if python is correctly installed

`python -V`\
`>Python 3.8.5`

## Pycharm (IDE)

### Install Pycharm

{% embed url="<https://www.jetbrains.com/pycharm/>" %}

Download and install Pycharm Community version - it is for free.

### Create first project

File > New Project\
1\. set a location and new folder name\
2\. set a New environment (it's better option, because sometimes we forgot to tell someone what to install in his environment to this project could be work)

![Create a new project with new environment on Python 3.8](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MFAiCtr82afg73JBDNB%2F-MFAjjNaDgzEQ8NFMmN5%2Fimage.png?alt=media\&token=8dec994b-05ad-4534-9be8-840772377f0e)

### Install pip to Python Interpreter

1. File > Settings&#x20;
2. Project: "gitbookProject" > Python Interpreter&#x20;
3. Click "+" icon > to install

![to install package](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MFAnQ3sW7OyGd8Eq9Yd%2F-MFAoWcM30hYzfe4d3Ky%2Fimage.png?alt=media\&token=0698859c-2d98-417f-8670-b4cff58a2106)

4\. search and install package

![Install selenium package](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MFAnQ3sW7OyGd8Eq9Yd%2F-MFAor5b27jbCO1CDIoD%2Fimage.png?alt=media\&token=1dd5c932-4b75-4381-a78f-e8ec9ed76881)

5\. Package 'selenium' installed successfully

## Pip and Venv by console

{% embed url="<https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/>" %}

### Package manager

pip is the reference Python package manager. It’s used to install and update packages. You’ll need to make sure you have the latest version of pip installed.

```
py -m pip install --upgrade pip
```

### Virtual environment

Virtual environment is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

#### Creating a venv

```
py -m venv env
```

(we could do it by pycharm by option New environment)

#### Activating a virtual environment

```
.\venv\Scripts\activate
```

#### Leaving a virtual environment

```
deactivate
```

#### Pip install

e.g. selenium

```
pip install selenium
```

### How to use venv and pip

![](https://4075407169-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MCCXrRYTXdf78GMukgv%2F-MFAkIO7KeJSOxic9Qi0%2F-MFAn1Fx2vpQVpgdHnOq%2Fimage.png?alt=media\&token=6a755c0e-14b0-4375-8355-63201c2cfc44)

## requirements.txt

Save all the packages in the file

```python
pip freeze > requirements.txt
```

Install packages from file requirements.txt

```python
pip install -r requirements.txt

>
Requirement already satisfied: selenium==3.141.0 in c:\users\nn\appdata\local\programs\python\python38-32\lib\site-packages (from -r requirements.txt (line 1)) (3.141.0)
Requirement already satisfied: urllib3==1.25.10 in c:\users\nn\appdata\local\programs\python\python38-32\lib\site-packages (from -r requirements.txt (line 2)) (1.25.10)

```
