gpt4 book ai didi

Python 找不到 elasticsearch 包

转载 作者:太空狗 更新时间:2023-10-29 21:22:16 24 4
gpt4 key购买 nike

我刚刚使用 pip install elasticsearch 安装了正确的包,但我的 .py 脚本没有找到它。

我现在有这个:

ls/Library/Python/2.7/site-packages

README                       pip-1.5.6-py2.7.egg          urllib3-1.8.3-py2.7.egg-info virtualenv.py                virtualenv_support
easy-install.pth urllib3 virtualenv-1.11.6.dist-info virtualenv.pyc

ls/usr/local/lib/python2.7/site-packages/

easy-install.pth              elasticsearch-1.0.0.dist-info setuptools-4.0.1-py2.7.egg    sitecustomize.py
elasticsearch pip-1.5.6-py2.7.egg setuptools.pth sitecustomize.pyc

现在,当我运行我的脚本 myelastic.py 时:

import sys
print sys.path

from elasticsearch import Elasticsearch
es = Elasticsearch()

我有这个:

['/Users/tati/Desktop/python', '/Applications/MAMP/Library/lib/python27.zip', '/Applications/MAMP/Library/lib/python2.7', '/Applications/MAMP/Library/lib/python2.7/plat-darwin', '/Applications/MAMP/Library/lib/python2.7/plat-mac', '/Applications/MAMP/Library/lib/python2.7/plat-mac/lib-scriptpackages', '/Applications/MAMP/Library/lib/python2.7/lib-tk', '/Applications/MAMP/Library/lib/python2.7/lib-old', '/Applications/MAMP/Library/lib/python2.7/lib-dynload', '/Applications/MAMP/Library/lib/python2.7/site-packages']
Traceback (most recent call last):
File "myelastic.py", line 5, in <module>
from elasticsearch import Elasticsearch
ImportError: No module named elasticsearch

这是我第一次使用 virtualenv,但我不确定如何解决这个问题,谢谢!

最佳答案

您已将您的文件命名为与模块相同的名称:

文件“/Users/tati/Desktop/python/elasticsearch.py​​”

它隐藏了模块名称,因此您是从文件而不是 elasticsearch 模块导入的。只需将您的 .py 重命名为 elasticsearch.py​​ 以外的名称即可。

关于Python 找不到 elasticsearch 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24478604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com