在同一环境中使用不同版本的python包

bqf10yzr  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(2)|浏览(487)

我需要不同版本的 elasticseach-dsl 安装在同一个virtualenv中。我希望能够使用某种别名导入它们:

import elasticsearch_dsl1
import elasticsearch_dsl2
import elasticsearch_dsl5

我在考虑创建一个名为 elasricsearch_dsl* 在他们的 setup.py 添加正确版本的安装要求 elasticsearch_dsl 但是当我安装软件包时,会导致冲突,因为我的所有软件包都需要同一个库的不同版本。我不知道如何进行,如果这是可能的。
谢谢大家

ndh0cuux

ndh0cuux1#

简短回答:
这是不可能的。

h6my8fg2

h6my8fg22#

我找到了解决问题的办法。
我下载了 elasticsearch-dsl 不同版本的库
然后将import语句更改为 elasticsearch1 , elasticsearch2 等库而不是 elasticsearch v1.x和v2.x


# example `elasticsearch-dsl` v5.4.0

from elasticsearch import Elasticsearch #  --> from elasticsearch5 import Elasticsearch

修改了 setup.py 更改依赖项的步骤 elasticsearchelasticsearch1 , elasticsearch2 对于每个版本的 elasticsearch-dsl 我一直很幸运,因为有 elasticsearch1 , elasticsearch2 ... 否则我就得对他们重复同样的程序。更幸运的是,不同版本的库之间的依赖关系是兼容的。
我不为这项技术感到骄傲,但它成功了。

设置.py

一个例子 setup.py 文件 elasticsearch-dls==7.3.0 ,那么 elasticsearch-dsl7 ```
from os.path import join, dirname
from setuptools import setup, find_packages

VERSION = (7, 3, 0)
version = VERSION
versionstr = ".".join(map(str, VERSION))

f = open(join(dirname(file), "README"))
long_description = f.read().strip()
f.close()

install_requires = [
"six",
"python-dateutil",
"elasticsearch7", # before "elasticsearch>=7.0.0,<8.0.0" <---
# ipaddress is included in stdlib since python 3.3
'ipaddress; python_version<"3.3"',
]

tests_require = [
"mock",
"pytest>=3.0.0",
"pytest-cov",
"pytest-mock<3.0.0",
"pytz",
"coverage<5.0.0",
]

setup(
name="elasticsearch-dsl7", # <---
description="Python client for Elasticsearch",
license="Apache-2.0",
url="https://github.com/elasticsearch/elasticsearch-dsl-py",
long_description=long_description,
version=versionstr,
author="Honza Král",
author_email="honza.kral@gmail.com",
maintainer="Seth Michael Larson",
maintainer_email="seth.larson@elastic.co",
packages=find_packages(where=".", exclude=("test_elasticsearch_dsl*",)),
python_requires=">=2.7, !=3.0., !=3.1., !=3.2., !=3.3.",
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: Apache Software License",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
install_requires=install_requires,
test_suite="test_elasticsearch_dsl.run_tests.run_all",
tests_require=tests_require,
extras_require={"develop": tests_require + ["sphinx", "sphinx_rtd_theme"]},
)

相关问题