SeleniumBase/help_docs/virtualenv_instructions.md

95 lines
2.7 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-10-02 15:43:41 +08:00
### Step 0: Install VirtualEnvWrapper (<i>optional</i>):
* ``virtualenvwrapper`` can make it easier to work with [Python virtual environments](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) by giving you the ``mkvirtualenv`` command.
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
2020-08-18 04:28:28 +08:00
python3 -m pip install virtualenvwrapper --force-reinstall
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
2020-10-02 15:43:41 +08:00
(*Shortcut*: Run "``win_virtualenv.bat``" from the top-level SeleniumBase folder to perform the following steps.)
2018-12-27 15:14:24 +08:00
2017-10-28 03:19:11 +08:00
```bash
2020-08-18 04:28:28 +08:00
py -m pip install virtualenvwrapper-win --force-reinstall --user
2017-10-28 03:19:11 +08:00
```
2020-10-02 15:43:41 +08:00
### Step 1: Create a virtual environment:
2016-02-13 15:58:27 +08:00
2020-08-18 04:28:28 +08:00
### macOS / Linux:
2020-10-02 15:43:41 +08:00
* (Python 3) ``python3 -m venv ENV``:
2020-08-18 04:28:28 +08:00
```bash
python3 -m venv sbase_env
source sbase_env/bin/activate
```
2016-02-13 15:58:27 +08:00
2020-10-02 15:43:41 +08:00
* (Python 2, 3) ``mkvirtualenv ENV``:
2020-08-18 04:28:28 +08:00
```bash
2020-08-18 04:28:28 +08:00
mkvirtualenv sbase_env
```
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.)
2020-10-02 15:43:41 +08:00
### Windows:
* (Python 3) ``py -m venv ENV``:
```bash
2020-08-18 04:28:28 +08:00
py -m venv sbase_env
call sbase_env\\Scripts\\activate
```
2020-10-02 15:43:41 +08:00
* (Python 2, 3) ``mkvirtualenv ENV``:
```bash
mkvirtualenv sbase_env
```
(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.)
2018-12-12 07:02:24 +08:00
---
2016-02-13 15:58:27 +08:00
2020-08-18 04:28:28 +08:00
### mkvirtualenv Commands
Creating a virtual environment:
```bash
mkvirtualenv sbase_env
```
Leaving your virtual environment:
2016-02-13 15:58:27 +08:00
```bash
deactivate
```
2020-08-18 04:28:28 +08:00
Returning to a virtual environment:
2016-02-13 15:58:27 +08:00
```bash
2020-08-18 04:28:28 +08:00
workon sbase_env
2016-02-13 15:58:27 +08:00
```
2018-03-14 03:31:43 +08:00
2020-08-18 04:28:28 +08:00
Listing all virtual environments:
2018-03-14 03:31:43 +08:00
```bash
lsvirtualenv
```
2020-08-18 04:28:28 +08:00
Deleting a virtual environment:
2018-03-14 03:31:43 +08:00
```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>