ModuleNotFoundError: No module named 'elasticsearch' - elasticsearch

I am new to Python. MAC user, I have Python 3.7 and I have installed Elasticsearch via pip3 install elasticsearch. I do not have any other file named Elasticsearch and I tried to fix the PYTHONPATH as suggested on other posts. I also tried to uninstall and re-install Elasticsearch again. Same error. When I run...
import logging
import elasticsearch
def gotoelk():
_es = None
_es = Elasticsearch([{'host':'Internal IP of my Elasticsearch', 'port': 9200}])
if _es.ping():
print('Connected')
else:
print('NOT connected')
return _es
if __name__ == '__main__':
logging.basicConfig(level=logging.ERROR)
gotoelk()
I get the following:
Traceback (most recent call last):
File "/Users/username/Desktop/MBAPI/ELK_connect_test.py", line 3, in <module>
import elasticsearch
ModuleNotFoundError: No module named 'elasticsearch'
Any ideas or suggestions?

Related

Django Rest Framework AttributeError: module 'coreapi' has no attribute 'Client'

I am trying to run tests for api that worked before. Test.py looks like following:
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase
class ApiUserTest(APITestCase):
"""
python manage.py test .\apps\api\api_user
API urls:
api_user/login/
api_user/logout/
api_user/register/
api_user/change_password/
"""
def setUp(self):
...
def test_user_register(self):
...
But I'm getting the following error
PS F:\ComputerShop> python manage.py test .\apps\api\api_user
System check identified no issues (0 silenced).
E
======================================================================
ERROR: api.api_user.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: api.api_user.tests
Traceback (most recent call last):
File "C:\Users\Emil\AppData\Local\Programs\Python\Python38\lib\unittest\loader.py", line 436, in _find_test_path
module = self._get_module_from_name(name)
File "C:\Users\Emil\AppData\Local\Programs\Python\Python38\lib\unittest\loader.py", line 377, in _get_module_from_name
__import__(name)
File "F:\ComputerShop\apps\api\api_user\tests.py", line 3, in <module>
from rest_framework.test import APITestCase
File "F:\ComputerShop\env\lib\site-packages\rest_framework\test.py", line 123, in <module>
class CoreAPIClient(coreapi.Client):
AttributeError: module 'coreapi' has no attribute 'Client'
I also tried to run tests on a known working project, but they did not start there either.
I've tried to reinstalling the rest framework but it doesn't help. I use virtual environment in the project
To solve this problem you should install next packages:
pip install coreapi pyyaml

How to install pyspark without hadoop?

I want to install pyspark but I don't want to use hadoop because I just want to test out some functions. I followed instructions from a bunch of websites: I used pip to install pyspark, installed jdk 8 and set JAVA_PATH, SPARK_HOME, PATH variables but it's not working.
My program is:
from pyspark import *
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
I am getting this exception:
\Java\jdk1.8.0_291\bin\java was unexpected at this time.
Traceback (most recent call last):
File "c:\Users\ankit\Untitled-1.py", line 4, in <module>
spark = SparkSession.builder.getOrCreate()
File "C:\Users\ankit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyspark\sql\session.py", line 228, in getOrCreate
sc = SparkContext.getOrCreate(sparkConf)
File "C:\Users\ankit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyspark\context.py", line 384, in getOrCreate
SparkContext(conf=conf or SparkConf())
File "C:\Users\ankit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyspark\context.py", line 144, in __init__
SparkContext._ensure_initialized(self, gateway=gateway, conf=conf)
File "C:\Users\ankit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyspark\context.py", line 331, in _ensure_initialized
SparkContext._gateway = gateway or launch_gateway(conf)
File "C:\Users\ankit\AppData\Local\Programs\Python\Python39\lib\site-packages\pyspark\java_gateway.py", line 108, in launch_gateway
raise Exception("Java gateway process exited before sending its port number")
Exception: Java gateway process exited before sending its port number

ImportError: cannot import name Minio

I am using minio 5.0.1 with this command:
pip install minio
But I still get this error
Traceback (most recent call last):
File "minio.py", line 2, in <module>
from minio import Minio
File "/root/minio.py", line 2, in <module>
from minio import Minio
ImportError: cannot import name Minio
i guess it's to late for this answer but anyways:
since you call your python file minio.py he tries to import this file instead of the minio package and failes to find an object inside called Minio.
Rename your py file to miniotest.py and it should work.

trouble setting pythonpath with uwsgi

i am trying to run the uwsgi deamon. I am on amazon Linux with EPEL. For installation, I have done
sudo yum install uwsgi uwsgi-plugin-python
and this is my uwsgi ini
[uwsgi]
plugins = python
socket = /tmp/project.sock
#socket = :9050
chmod-socket = 666
uid = nginx
gid = nginx
master = true
enable-threads = true
processes = 2
home = /srv/project-live
virtualenv = /srv/project-live
chdir = /srv/project-live
pythonpath = /srv/project-live
module = project.wsgi
pidfile = /srv/project-live/uwsgi/live.pid
daemonize = /srv/project-live/logs/uwsgi.log
touch-reload = /srv/project-live/uwsgi/touch.py
vacuum = true
by doing
sudo service uwsgi restart
the service starts but the log file gives
*** Operational MODE: preforking ***
added /srv/project-live/ to pythonpath.
Traceback (most recent call last):
File "./project/__init__.py", line 1, in <module>
from __future__ import absolute_import
ImportError: No module named __future__
where i am going wrong??
it was looking for python plugin for uwsgi, which wasn't installed. after installing the plugin, everything worked just fine.

Ubuntu 10.04 - Python multiprocessing - 'module' object has no attribute 'local' error

The following code is from the python 2.6 manual.
from multiprocessing import Process
import os
def info(title):
print(title)
print('module name:', 'me')
print('parent process:', os.getppid())
print('process id:', os.getpid())
def f(name):
info('function f')
print('hello', name)
if __name__ == '__main__':
info('main line')
p = Process(target=f, args=('bob',))
p.start()
p.join()
This creates the following stack traces:
Traceback (most recent call last):
File "threading.py", line 1, in <module>
from multiprocessing import Process
File "/usr/lib/python2.6/multiprocessing/__init__.py", line 64, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib/python2.6/multiprocessing/util.py", line 287, in <module>
class ForkAwareLocal(threading.local):
AttributeError: 'module' object has no attribute 'local'
Exception AttributeError: '_shutdown' in <module 'threading' from '/home/v0idnull/tmp/pythreads/threading.pyc'> ignored
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/multiprocessing/util.py", line 258, in _exit_function
info('process shutting down')
TypeError: 'NoneType' object is not callable
Error in sys.exitfunc:
Traceback (most recent call last):
File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs
func(*targs, **kargs)
File "/usr/lib/python2.6/multiprocessing/util.py", line 258, in _exit_function
info('process shutting down')
TypeError: 'NoneType' object is not callable
I'm completely clueless as to WHY this is happening, and google has given me very little to work with.
that code runs fine on my machine:
Ubuntu 10.10, Python 2.6.6 64-bit.
but your error is actually because you have a file named 'threading.py' that you are running this code from (see the stack-trace details). this is causing a namespace mismatch, since the multiprocessing module needs the 'real' threading module. try renaming your file to something other than 'threading.py' and running it again.
also... the example you posted is not from the Python 2.6 docs... it is from the Python 3.x docs. make sure you are reading the docs for the version that matches what you are running.

Resources