简体   繁体   English

Python没有找到elasticsearch包

[英]Python not finding elasticsearch package

I just installed with pip install elasticsearch the right package, but is not being found by my .py script. 我刚刚使用pip install elasticsearch安装了正确的软件包,但我的.py脚本找不到它。

I have this right now: 我现在有这个:

ls /Library/Python/2.7/site-packages 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/ 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

Now when I run my script myelastic.py: 现在当我运行我的脚本myelastic.py时:

import sys
print sys.path

from elasticsearch import Elasticsearch
es = Elasticsearch()

I have this: 我有这个:

['/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

It's the first time I work with virtualenv, but I'm not sure how to work around this issue, thanks! 这是我第一次使用virtualenv,但我不知道如何解决这个问题,谢谢!

You have called your file the same name as the module: 您已将文件调用与模块相同的名称:

File "/Users/tati/Desktop/python/elasticsearch.py" . File "/Users/tati/Desktop/python/elasticsearch.py"

It is shadowing the module name so you are importing from your file not the elasticsearch module. 它隐藏了模块名称,因此您要从文件导入而不是弹性搜索模块。 Just rename your .py to something other than elasticsearch.py . 只需将重命名.py比其他东西elasticsearch.py

I had the same issue. 我遇到过同样的问题。 I fixed it by adding to my .bash_profile : 我通过添加到我的.bash_profile来修复它:

export PYTHONPATH=/Library/Python/2.7/site-packages

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 python 的 Elasticsearch package 连接到远程 Elasticsearch 服务器 - Connecting to remote Elasticsearch server with python's Elasticsearch package Python导入/查找名称中带有句点的软件包 - Python importing/finding a package with a period in the name 查找 package 的最低支持 Python 版本 - Finding the minimum supported Python version for a package Python:查找包中的所有包 - Python: Finding all packages inside a package Python package 用于高效加权最短路径查找 - Python package for efficient weighted shortest path finding 尝试使用 elasticsearch-dsl Python package 访问 Elasticsearch 云时“无法建立新连接” - “Failed to establish a new connection” when trying to access Elasticsearch Cloud with elasticsearch-dsl Python package 如何将Elasticsearch Ingest附件处理器插件与Python软件包elasticsearch-dsl结合使用 - How do you use the Elasticsearch Ingest Attachment Processor Plugin with the Python package elasticsearch-dsl Python 未从 PyPi 包中找到库(因此,dll) - Python not finding a library (so, dll) from a PyPi package Python查找包中的所有包,即使在鸡蛋中也是如此 - Python Finding all packages inside a package, even when in an egg R 网状 package 未找到 Python win32com 模块 - R reticulate package not finding Python win32com module
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM