- Hands-On Reactive Programming with Python
- Romain Picard
- 543字
- 2021-06-24 18:25:12
Installating RxPY
RxPY is available as a Python package published on PyPI (https://pypi.org/), so it can be installed with pip. Depending on your operating system, you may already have pip installed. Otherwise refer to the pip installation documentation (https://pip.pypa.io/en/stable/installing/).
By following the examples in this book, you will install several libraries and sample packages that you may not want to keep on your system. In order to avoid cluttering your environment, you should run all these examples in a virtualenv. virtualenv is a tool that allows you to create isolated Python environments. With it you can create many different Python environments, potentially using different Python interpreters that are independent from each other. This is a great tool when developing in Python because it allows you to:
- Test libraries without installing them on your system
- Test some code with different versions of Python interpreters
- Test some code with different versions of dependency packages
- Have one independent and reproducible execution environment per project
If you are not already familiar with it, I encourage you to use it when running the example code that we will use. The installation of virtualenv is very easy via PyPI, using the following command:
pip3 install virtualenv
Creating a new virtual environment is also quite easy, in a single line with three parameters, using the following line of code:
virtualenv --system-site-packages -p /usr/local/bin/python3 venv-rx
The --system-site-packages option indicates that we want to use system packages when they are already installed. If you omit this parameter you will create a complete Python environment from scratch. This would be better for isolation but requires much more space because each dependency will be reinstalled in virtualenv. In our case, we do not need a strict isolation from the system; we only want to avoid installing new packages in our system. The -p option indicates what the Python interpreter will use. You should adapt it to your environment. The /usr/local/bin value corresponds to a macOS system. On Linux, the cpython interpreter is usually located at /usr/bin. Finally the venv-rx parameter is the name of virtualenv created. After running this command you will see a new directory named venv-rx.
Once virtualenv is created, you can enter it and leave it. Once you have entered virtualenv, all actions done by the Python interpreter are done in this isolated environment. Entering into virtualenv is done by sourcing a script in its bin directory, as can be seen in the following code:
source venv-rx/bin/activate
(venv-rx)$
When you are inside virtualenv, the name of virtualenv is printed in parentheses before the shell prompt. This is how you know if you are inside an isolated environment or on your system environment. Leaving virtualenv is done by executing the deactivate function, as can be seen in the following code:
(venv-rx)$ deactivate
$
From that point, the rx package can be installed via the pip tool, as can be seen in the following code:
$ source venv-rx/bin/activate
(venv-rx)$ pip install rx
If you want to install the latest development version, you can also install it directly from the GitHub sources. First clone the repository, and then install RxPY from the local sources, as demonstrated in the following code:
(venv-rx)$ git clone https://github.com/ReactiveX/RxPY.git
(venv-rx)$ cd RxPy.git
(venv-rx)$ python3 setup.py install
- pcDuino開發實戰
- 網絡操作系統:Windows Server 2003管理與應用
- 阿里云數字新基建系列:云原生操作系統Kubernetes
- VMware Horizon View 6 Desktop Virtualization Cookbook
- SOA實踐者說
- 高性能Linux服務器構建實戰:運維監控、性能調優與集群應用
- Linux性能優化
- 循序漸進學Docker
- Java EE 8 Design Patterns and Best Practices
- Microsoft Operations Management Suite Cookbook
- RHCSARHCE 紅帽Linux認證學習指南(第7版)EX200 & EX300
- Vim 8文本處理實戰
- 鴻蒙操作系統設計原理與架構
- Windows Vista終極技巧金典
- Docker for Developers