我正在Google (CentOS)上运行一个虚拟环境。
我安装了es_v作为我的虚拟环境,并遵循这些指示安装弹性搜索。
(es_v)$ which java
/usr/bin/java
(es_v)$ which python
/var/www/my_project/elastic/es_v/bin/python
(es_v)$ python --version
Python 3.6.5我运行了配置命令并运行了服务:
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service当我试图摄取数据时(test.py):
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
doc = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['result'])
res = es.get(index="test-index", doc_type='tweet', id=1)
print(res['_source'])
es.indices.refresh(index="test-index")
res = es.search(index="test-index", body={"query": {"match_all": {}}})
print("Got %d Hits:" % res['hits']['total'])
for hit in res['hits']['hits']:
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])我得到:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from elasticsearch import Elasticsearch
ModuleNotFoundError: No module named 'elasticsearch'我试着安装elasticsearch:
sudo pip install elasticsearch它把我指向了目录:
Requirement already satisfied: elasticsearch in /usr/lib/python3.6/site-packages (6.2.0)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/lib/python3.6/site-packages (from elasticsearch) (1.22)我应该包括/usr/elasticsearch/和/usr/elasticsearch/bin/某处吗?它似乎找不到它,因为我指的不是完整的道路。
任何关于我做错了什么的指导都将不胜感激。
发布于 2020-11-24 08:58:55
您可能需要检查Scrapy使用的python版本是否与pip安装到的python_number文件夹共享相同的版本。在我的例子中,我的Scrapy安装在Python 3.8上,并从/usr/local/lib/Python 3.8获得依赖,但是我的Python更新后的pip指向/usr/local/lib/Python 3.9。这就是为什么Scrapy无法找到新添加的模块'elasticsearch‘。
解决方案是在命令中指定版本,如:python3.8 -m pip install elasticsearch
https://stackoverflow.com/questions/50888478
复制相似问题