在没有 pip 的虚拟环境中安装 redis 5.x 软件包



我在虚拟环境中使用pip安装了redis 3.5.3。但是由于我需要redis 5.x,我卸载了redis并尝试使用pip使用较新版本。但是,我得到了

$ pip install redis==5.0.5
ERROR: Could not find a version that satisfies the requirement redis==5.0.5 (from versions: 0.6.0, 0.6.1, 1.34, 1.34.1, 2.0.0, 2.2.0, 2.2.2, 2.2.4, 2.4.0, 2.4.1, 2.4.2, 2.4.3, 2.4.4, 2.4.5, 2.4.6, 2.4.7, 2.4.8, 2.4.9, 2.4.10, 2.4.11, 2.4.12, 2.4.13, 2.6.0, 2.6.1, 2.6.2, 2.7.0, 2.7.1, 2.7.2, 2.7.3, 2.7.4, 2.7.5, 2.7.6, 2.8.0, 2.9.0, 2.9.1, 2.10.0, 2.10.1, 2.10.2, 2.10.3, 2.10.5, 2.10.6, 3.0.0, 3.0.0.post1, 3.0.1, 3.1.0, 3.2.0, 3.2.1, 3.3.0, 3.3.1, 3.3.2, 3.3.3, 3.3.4, 3.3.5, 3.3.6, 3.3.7, 3.3.8, 3.3.9, 3.3.10, 3.3.11, 3.4.0, 3.4.1, 3.5.0, 3.5.1, 3.5.2, 3.5.3)
ERROR: No matching distribution found for redis==5.0.5

因此,我求助于使用make安装它。

$ cd /tmp
$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar xzf redis-5.0.5.tar.gz
$ cd redis-5.0.5
$ make

并使用$ src/redis-server运行服务器。我得到什么

...lots of verbose...
14126:M 22 Jun 2020 12:15:30.196 * DB loaded from disk: 0.000 seconds
14126:M 22 Jun 2020 12:15:30.196 * Ready to accept connections
14126:M 22 Jun 2020 12:15:41.798 * DB saved on disk

我想软件包已全局安装并且 redis 服务器正在运行(也使用sudo systemctl status redis进行验证(。但是,现在当我再次使用我的 virtualenv 和import redis时,我收到丢失的包错误。

我应该如何在我的虚拟 python 脚本中使用 redis 5.x?

http://download.redis.io/releases/redis-5.0.5.tar.gz 指向Redis(数据库(可执行文件。

这是让Redis使用Python的第一步,

第二步是获取 Python 的 Redis 包以连接到数据库。

由于 Python 的 Redis 包与实际的 Redis 数据库不是一回事,因此您不需要获取与数据库版本匹配的包版本,您只需要:

pip install redis

获取 Python 的 Redis 包的最新版本。

从那里,随着数据库在后台运行,您可以使用 Python 连接:

import redis
db = redis.Redis(host='localhost', port=6379, [...])

最新更新