SeleniumBase/help_docs/virtualenv_instructions.md

76 lines
2.2 KiB
Markdown
Raw Normal View History

2019-07-22 02:14:40 +08:00
## <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> Virtual Environment Tutorial
2016-02-13 15:58:27 +08:00
2018-08-10 15:22:16 +08:00
### **Step 1**: First install [VirtualEnv](http://virtualenv.readthedocs.org/en/latest/) and [VirtualEnvWrapper](http://virtualenvwrapper.readthedocs.org/en/latest/) (<i>if not installed</i>):
2019-04-11 03:44:30 +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
source `which virtualenvwrapper.sh`
2018-08-10 15:22:16 +08:00
export WORKON_HOME=$HOME/.virtualenvs
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-04-11 03:44:30 +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 virtualenv
python -m pip install --upgrade virtualenvwrapper-win
2017-10-28 03:19:11 +08:00
```
### **Step 2**: Now create a virtual environment:
2016-02-13 15:58:27 +08:00
2019-04-11 03:44:30 +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
2018-03-20 04:54:41 +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.</i>