2021-05-04 01:59:31 +00:00
|
|
|
# Python
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2012-09-03 01:14:32 +00:00
|
|
|
Enables local Python and local Python package installation.
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Settings
|
2017-11-13 00:20:52 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
This module supports virtual environments from conda and
|
|
|
|
[*virtualenvwrapper*][2]. By default, only *virtualenvwrapper* is enabled. To
|
|
|
|
disable *virtualenvwrapper*, add the following to *~/.zpreztorc*.
|
2017-11-13 00:20:52 +00:00
|
|
|
|
2017-12-11 19:01:40 +00:00
|
|
|
```sh
|
|
|
|
zstyle ':prezto:module:python' skip-virtualenvwrapper-init 'on'
|
|
|
|
```
|
2017-11-13 00:20:52 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
Conda support is enabled by adding the following to *~/.zpreztorc*.
|
2017-11-13 00:20:52 +00:00
|
|
|
|
2017-12-11 19:01:40 +00:00
|
|
|
```sh
|
|
|
|
zstyle ':prezto:module:python' conda-init 'on'
|
|
|
|
```
|
2017-11-13 00:20:52 +00:00
|
|
|
|
|
|
|
Caution: using conda and virtualenvwrapper at the same time may cause conflicts.
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Local Python Installation
|
2012-09-03 01:14:32 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
[*pyenv*][4] builds and installs multiple Python versions locally in the home
|
2012-09-03 01:14:32 +00:00
|
|
|
directory.
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
This module prepends the *pyenv* directory to the path variable to enable the
|
2013-08-20 12:21:17 +00:00
|
|
|
execution of `pyenv`.
|
2012-09-03 01:14:32 +00:00
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
Install Python versions with `pyenv install` into *~/.pyenv/versions*.
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2019-09-10 16:10:31 +00:00
|
|
|
This will be loaded automatically if pyenv is installed to `$PYENV_ROOT`,
|
2021-05-04 01:59:31 +00:00
|
|
|
*~/.pyenv*, or if the `pyenv` command is on the path.
|
2019-09-10 16:10:31 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Local Package Installation
|
2012-05-05 17:15:44 +00:00
|
|
|
|
|
|
|
Since version 2.6, Python supports per user package installation, as defined in
|
|
|
|
[PEP 370][1].
|
|
|
|
|
2012-06-02 21:17:12 +00:00
|
|
|
This module prepends per user site directories to the relevant path variables
|
|
|
|
to enable the execution of user installed scripts and the reading of
|
|
|
|
documentation.
|
2012-05-05 17:15:44 +00:00
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
2017-08-29 23:04:44 +00:00
|
|
|
Install packages into the per user site directory with `pip install --user`.
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## virtualenvwrapper
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
[*virtualenvwrapper*][2] is a frontend to the popular [*virtualenv*][3] utility.
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2018-10-12 15:52:24 +00:00
|
|
|
`virtualenv` creates isolated Python environments and `virtualenvwrapper`
|
|
|
|
provides convenient shell functions to create, switch, and manage them.
|
2012-05-05 17:15:44 +00:00
|
|
|
|
|
|
|
### Usage
|
|
|
|
|
2017-08-29 23:47:06 +00:00
|
|
|
Install `virtualenvwrapper`.
|
2012-09-03 14:53:19 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
Virtual environments are stored in *~/.virtualenvs*.
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2012-09-03 15:27:58 +00:00
|
|
|
There are configuration variables that have to be set to enable certain features.
|
2017-08-29 23:47:06 +00:00
|
|
|
If you wish to use these features, export the variables in [`zshenv`][6].
|
2012-09-03 15:27:58 +00:00
|
|
|
|
2017-08-29 23:47:06 +00:00
|
|
|
The variable `$PROJECT_HOME` tells `virtualenvwrapper` where to place project
|
2012-09-03 15:27:58 +00:00
|
|
|
working directories. It must be set and the directory created before `mkproject`
|
|
|
|
is used. Replace *Developer* with your projects directory.
|
|
|
|
|
2017-07-21 01:07:29 +00:00
|
|
|
```sh
|
|
|
|
export PROJECT_HOME="$HOME/Developer"
|
|
|
|
```
|
2012-09-03 15:27:58 +00:00
|
|
|
|
2017-08-29 23:47:06 +00:00
|
|
|
The variable `VIRTUALENVWRAPPER_PYTHON` tells `virtualenvwrapper` to use the
|
|
|
|
specified full path of the `python` interpreter overriding the `$PATH` search.
|
2017-07-25 00:34:11 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
|
|
|
|
```
|
|
|
|
|
2017-08-29 23:47:06 +00:00
|
|
|
The variable `VIRTUALENVWRAPPER_VIRTUALENV` tells `virtualenvwrapper` to use the
|
2017-07-25 00:34:11 +00:00
|
|
|
specified full path of `virtualenv` binary overriding the `$PATH` search.
|
|
|
|
|
|
|
|
```sh
|
|
|
|
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
|
|
|
|
```
|
|
|
|
|
2017-08-29 23:47:06 +00:00
|
|
|
The variable `$VIRTUALENVWRAPPER_VIRTUALENV_ARGS` tells `virtualenvwrapper` what
|
2012-09-03 15:27:58 +00:00
|
|
|
arguments to pass to `virtualenv`. For example, set the value to
|
2017-08-29 23:47:06 +00:00
|
|
|
`--system-site-packages` to ensure that all new environments have access to the
|
2012-09-03 15:27:58 +00:00
|
|
|
system site-packages directory.
|
|
|
|
|
2017-07-21 01:07:29 +00:00
|
|
|
```sh
|
|
|
|
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--system-site-packages'
|
|
|
|
```
|
2012-09-03 15:27:58 +00:00
|
|
|
|
2017-05-31 00:29:32 +00:00
|
|
|
### Additional Options
|
|
|
|
|
|
|
|
There is a hook to enable auto-switching to virtualenvs when switching into a
|
|
|
|
directory where the root of the project matches a virtualenv name.
|
|
|
|
|
|
|
|
This can be enabled with:
|
|
|
|
|
2017-07-21 01:07:29 +00:00
|
|
|
```sh
|
|
|
|
zstyle ':prezto:module:python:virtualenv' auto-switch 'yes'
|
|
|
|
```
|
2017-05-31 00:29:32 +00:00
|
|
|
|
2017-08-29 23:47:06 +00:00
|
|
|
`virtualenvwrapper` is automatically initialized if pre-requisites are met
|
2017-07-25 00:34:11 +00:00
|
|
|
(`$VIRTUALENVWRAPPER_VIRTUALENV` is explicitly set or `virtualenv` is in
|
|
|
|
`$PATH`). This can be disabled with:
|
|
|
|
|
2017-12-11 19:01:40 +00:00
|
|
|
```sh
|
2017-07-25 00:34:11 +00:00
|
|
|
zstyle ':prezto:module:python:virtualenv' initialize 'no'
|
|
|
|
```
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Aliases
|
2012-08-15 12:00:08 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
- `py` is short for `python`.
|
|
|
|
- `py2` is short for `python2`.
|
|
|
|
- `py3` is short for `python3`.
|
2012-08-15 12:00:08 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Functions
|
2012-09-03 14:34:41 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
- `python-info` exposes information about the Python environment via the
|
|
|
|
`$python_info` associative array.
|
2012-09-03 14:34:41 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Theming
|
2012-09-07 02:39:11 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
To display the name of the current virtual environment in a prompt, define the
|
2012-10-02 16:53:59 +00:00
|
|
|
following style in the `prompt_name_setup` function.
|
2012-09-07 02:39:11 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
```sh
|
|
|
|
# %v - virtualenv name.
|
|
|
|
zstyle ':prezto:module:python:info:virtualenv' format 'virtualenv:%v'
|
|
|
|
```
|
2012-09-07 02:39:11 +00:00
|
|
|
|
|
|
|
Then add `$python_info[virtualenv]` to `$PROMPT` or `$RPROMPT` and call
|
2012-10-02 16:53:59 +00:00
|
|
|
`python-info` in the `prompt_name_preexec` hook function.
|
2012-09-07 02:39:11 +00:00
|
|
|
|
2017-12-04 20:01:07 +00:00
|
|
|
Similarly, you can use `:prezto:module:python:info:version:format` with `%v` for
|
|
|
|
the version and add `$python_info[version]` to your prompt for the current
|
|
|
|
python version/
|
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
## Authors
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2012-05-22 00:18:30 +00:00
|
|
|
*The authors of this module should be contacted via the [issue tracker][5].*
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
- [Sorin Ionescu](https://github.com/sorin-ionescu)
|
|
|
|
- [Sebastian Wiesner](https://github.com/lunaryorn)
|
2012-05-05 17:15:44 +00:00
|
|
|
|
2021-05-04 01:59:31 +00:00
|
|
|
[1]: https://www.python.org/dev/peps/pep-0370/
|
|
|
|
[2]: https://www.doughellmann.com/projects/virtualenvwrapper/
|
|
|
|
[3]: https://pypi.org/project/virtualenv/
|
2013-08-20 12:21:17 +00:00
|
|
|
[4]: https://github.com/yyuu/pyenv
|
2012-09-03 20:08:39 +00:00
|
|
|
[5]: https://github.com/sorin-ionescu/prezto/issues
|
2017-08-29 23:47:06 +00:00
|
|
|
[6]: https://github.com/sorin-ionescu/prezto/blob/master/runcoms/zshenv
|