SeleniumBase/help_docs/virtualenv_instructions.md

75 lines
2.3 KiB
Markdown
Raw Normal View History

2020-05-22 11:39:59 +08:00
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Virtual Environment Tutorial</h2>
2016-02-13 15:58:27 +08:00
2020-05-16 01:15:37 +08:00
### Step 1: Install VirtualEnv and VirtualEnvWrapper:
2018-08-10 15:22:16 +08:00
2019-09-16 17:17:33 +08:00
### macOS / Linux:
2017-10-28 03:19:11 +08:00
2018-12-27 15:14:24 +08:00
(*Shortcut*: Run "``source virtualenv_install.sh``" from the top-level SeleniumBase folder to perform the following steps.)
2017-10-28 03:19:11 +08:00
```bash
python -m pip install --upgrade virtualenv
python -m pip install --upgrade virtualenvwrapper
2018-08-10 15:22:16 +08:00
export WORKON_HOME=$HOME/.virtualenvs
2019-09-16 17:17:33 +08:00
source `which virtualenvwrapper.sh`
2017-10-28 03:19:11 +08:00
```
If you add ``source `which virtualenvwrapper.sh` `` to your local bash file (``~/.bash_profile`` on macOS, or ``~/.bashrc`` on Linux), virtualenvwrapper commands such as ``mkvirtualenv`` will be available whenever you open a new command prompt.
2018-08-10 15:22:16 +08:00
2019-09-16 17:17:33 +08:00
### Windows:
2018-08-10 15:22:16 +08:00
2018-12-27 15:14:24 +08:00
(*Shortcut*: Run "``virtualenv_install.bat``" from the top-level SeleniumBase folder to perform the following steps.)
2017-10-28 03:19:11 +08:00
```bash
python -m pip install --upgrade virtualenvwrapper-win
2017-10-28 03:19:11 +08:00
```
2020-05-16 01:15:37 +08:00
### Step 2: Create a virtual environment:
2016-02-13 15:58:27 +08:00
2019-09-16 17:17:33 +08:00
### macOS / Linux / Windows:
2016-02-13 15:58:27 +08:00
* Using ``mkvirtualenv``:
```bash
mkvirtualenv seleniumbase_venv
```
2018-12-12 07:02:24 +08:00
(If you have multiple versions of Python installed on your machine, and you want your virtual environment to use a specific Python version, add ``--python=PATH_TO_PYTHON_EXE`` with the Python executable to use.)
* Using ``virtualenv``:
```bash
virtualenv seleniumbase_venv
source seleniumbase_venv/bin/activate
```
* (Python 3) Using ``mvenv``:
```bash
python3 -mvenv seleniumbase_venv
source seleniumbase_venv/bin/activate
```
2018-12-12 07:02:24 +08:00
---
2016-02-13 15:58:27 +08:00
If you ever need to leave your virtual environment, use the following command:
```bash
deactivate
```
2017-04-07 05:46:54 +08:00
You can always jump back into your virtual environment later:
2016-02-13 15:58:27 +08:00
```bash
workon seleniumbase_venv
2016-02-13 15:58:27 +08:00
```
2018-03-14 03:31:43 +08:00
To list all existing virtual environments:
```bash
lsvirtualenv
```
To delete a virtual environment:
```bash
rmvirtualenv VIRTUAL_ENV_NAME
```
2018-03-20 03:13:09 +08:00
2019-09-16 17:17:33 +08:00
<br><i>[python-guide.org/en/latest/dev/virtualenvs](http://docs.python-guide.org/en/latest/dev/virtualenvs/) has more information about Python virtual environments. For specific details about VirtualEnv and VirtualEnvWrapper, see [http://virtualenv.readthedocs.org/en/latest/](http://virtualenv.readthedocs.org/en/latest/) and [http://virtualenvwrapper.readthedocs.org/en/latest/](http://virtualenvwrapper.readthedocs.org/en/latest/).</i>