ModuleNotFoundError: No module named 'cassandra' - python-3.x

After installing cassandra driver by running the command:
sudo pip3 install cassandra-driver, I am getting the error ModuleNotFoundError: No module named 'cassandra' when I try to import the module by running the line cassandra.
I then tried to see what all modules are installed in pip3 by running the command pip3 freeze:
astroid==2.1.0
cassandra-driver==3.16.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pylint==2.2.2
six==1.12.0
wrapt==1.10.11
Seeing no cassandra, I tried to import the visible module: cassandra-driver and then I ended up with the error:
File "<stdin>", line 1
import cassandra-driver
^
SyntaxError: invalid syntax
Also, when I do correct the hyphen issue with this:
__import__("cassandra-driver"), I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cassandra-driver'
My which python3 is: /usr/local/bin/python3 and my which pip3 is: /usr/local/bin/pip3
My OS is MacOS
How to install cassandra?
Note: I am following this documentation.

Did you try to run these demos (from those docs)?
"If successful, you should be able to build and install the extension (just using setup.py build or setup.py install) and then use the libev event loop by doing the following:"
>>> from cassandra.io.libevreactor import LibevConnection
>>> from cassandra.cluster import Cluster
>>> cluster = Cluster()
>>> cluster.connection_class = LibevConnection
>>> session = cluster.connect()
There is a probability that actual module is named differently, e.g. there is another external package called Pillow, but you import it with name "PIL".
In docs they are importing from cassandra.cluster
Docs I'm referring to

$ echo 'import cassandra.cluster' > cassandra.py && python3 cassandra.py
Traceback (most recent call last):
File "./cassandra.py", line 3, in <module>
import cassandra
File "/home/xxx/cassandra.py", line 4, in <module>
import cassandra.cluster
ModuleNotFoundError: No module named 'cassandra.cluster'; 'cassandra' is not a package
Using a different filename, the error disappears:
echo 'import cassandra.cluster' > tmp.py && python3 cassandra.py
So, for me, the error was that my own program overrode the package. O.o

Related

Why NO ModuleNotFoundError with conda?

Normally when I've done pip uninstall <module> if I then try to import the module I get a ModuleNotFoundError, for example:
dino#DINO:~$ python -c 'import mplfinance as mpf;print(mpf.__file__)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'mplfinance'
However, after activating a conda environment, the import works fine even when the package is unstalled both with pip uninstall and with conda remove, either way, I get:
dino#DINO:~$ python -c 'import mplfinance as mpf;print(mpf.__file__)'
None
Can anyone tell me why the import is NOT raising an exception, even though there is no module there to import??
This behavior (lack of import exception) appears to be related somehow to having activated a conda environment.

How to deal with "ModuleNotFoundError: No module named 'setup' "

I installed the module "pyunicorn" in Ubuntu 16.04 LTS and all the dependencies but when I import the module in python 3.7.3 i get this error :
>>> import pyunicorn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/anaconda3/lib/python3.7/site-packages/pyunicorn/__init__.py", line 43, in <module>
from setup import __version__
ModuleNotFoundError: No module named 'setup'
What should i do to make it run properly???
I had this problem. I wanted to install it on Google Colab. I tried installing pyunicorn directly from Github and it worked for me. Try using following instruction:
pip install git+https://github.com/pik-copan/pyunicorn.git#egg=pyunicorn

ImportError: cannot import name 'Coroutine'

I am trying to follow this instructions here:
https://github.com/hyperledger/indy-agent/blob/master/python/README.md
in order to simulate Hyperledger indy interactions, on a ubuntu 18.04 AWS instance.
I already cloned the repository and installed dependencies.(I am following dev mode instruction because the docker fails)
Then i launch the command:
python3 indy-agent.py 8094
And here the logs I have:
Traceback (most recent call last):
File "indy-agent.py", line 17, in <module>
import aiohttp_jinja2
File "/home/ubuntu/.local/lib/python3.5/site-packages/aiohttp_jinja2/__init__.py", line 6, in <module>
from aiohttp import web
File "/home/ubuntu/.local/lib/python3.5/site-packages/aiohttp/__init__.py", line 6, in <module>
from .client import (
File "/home/ubuntu/.local/lib/python3.5/site-packages/aiohttp/client.py", line 12, in <module>
from typing import ( # noqa
ImportError: cannot import name 'Coroutine'
This the aiohttp/client.py file:
"""HTTP Client for asyncio."""
import asyncio
import base64
import hashlib
import json
import os
import sys
import traceback
import warnings
from types import SimpleNamespace, TracebackType
from typing import ( # noqa
Any,
Coroutine,
Generator,
Generic,
….
)
This is the aiohttp/init.py file:
version = '3.5.4'
from typing import Tuple # noqa
from . import hdrs
from .client import (
….
And this is the aiohttp_jinja2/init.py:
import asyncio
import functools
import warnings
import jinja2
from collections import Mapping
from aiohttp import web
….
Any ideas on how to fix it?
Should I change some lines of code in one of these files?
Thanks
ADDITIONAL INFORMATION(BASED ON ANSWERS)
After the feedback from the answers, I updated to python 3.6.9.
While the asyncio problems fixed, still I get problems While setting up docker in the /python directory, I got the following:
1)make docker-build
2)sudo make docker-start PORT=8094
docker run -it -p $PORT:$PORT -e PORT=$PORT --name indy-agent_$PORT indy-agent
Traceback (most recent call last):
File "indy-agent.py", line 20, in <module>
from modules.connection import Connection, AdminConnection
File "/app/modules/__init__.py", line 1, in <module>
from python_agent_utils.messages.errors import ValidationException
ModuleNotFoundError: No module named 'python_agent_utils'
Makefile:5: recipe for target 'docker-start' failed
make: [docker-start] Error 1 (ignored)
docker rm indy-agent_$PORT
indy-agent_8094
When I try to install manually(without docker), I try to launch “pip install -r requirements.txt”, and I get the following:
ERROR: Could not find a version that satisfies the requirement aiohttp==3.5.4 …….ERROR: No matching distribution found for aiohttp==3.5.4 (from -r requirements.txt (line 2))
Then, when I try to launch the command “python3.6 indy-agent.py 8094”, I get continuously logs about missing modules. I installed them manually, which allowed me to go a little further in the process. But then I receive logs about modules that I cannot install through python.
This fact of having to install all the modules manually seems very strange to me, but I installed the agent outside the indy-sdk directory and also inside indy-sdk directory, and I get the same results.
Here’s the commands I launch and the logs I get:
1)python3.6 indy-agent.py 8094
ModuleNotFoundError: No module named 'aiohttp_jinja2'
2)python3.6 -m pip install aiohttp_jinja2
3)python3.6 indy-agent.py 8094
ModuleNotFoundError: No module named 'base58'
4)python3.6 -m pip install base58
No module named 'dateutil'
5)python3.6 -m pip install python-dateutil
6)python3.6 indy-agent.py 8094
ModuleNotFoundError: No module named 'indy'
7)sudo apt-get update
8)sudo apt-get install -y libindy
9)python3.6 -m pip install indy
10)python3.6 indy-agent.py 8094
ImportError: cannot import name 'did'
11)python -m pip install did
12)sudo python3 -m pip install did
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Could not find a version that satisfies the requirement did (from versions: )
No matching distribution found for did

ImportError: No module named 'mutiprocessing'

I am trying to import 'multiprocessing' and using python 3.5.3 but its gives error
Traceback (most recent call last):
File "ssser.py", line 7, in <module>
import mutiprocessing
ImportError: No module named 'mutiprocessing'
when i try to install multiprocessing module then i again error occure
i am using following command for installation
python3 -m pip install multiprocessing
and got error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-26ilgzih/multiprocessing/setup.py", line 94
print 'Macros:'
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-26ilgzih/multiprocessing/
however when i import "import multiprocessing" in terminal then no error occure but when i used in my file "ssscr.py" then it gives error
i am using geany,and python3 (IDEL) on raspberry pi3
Can any body help me how i can fix this error ?
For others who faces Similar error like
ModuleNotFoundError: No module named 'multiprocessing';
would also occur if you name your python file as multiprocessing.(as it makes ambiguity between your program name and actual module name)
Just rename your file and it will work (if you have dependency installed).
Seems like you are installing multiprocessing in the python 2 version. Could you use pip3 to install the package?
pip3 install multiprocessing
Also use the following command to check which pip you are using
$ ls -l `which pip`
$ ls -l `which pip3`
And to see if the package got correctly installed or not use
$ pip show pip
$ pip3 show pip
Update:
multiprocessing is built-in after python2.6
OP did a typo. It should be
import multiprocessing in place of import mutiprocessing

import rpy2.ipython meet error ModuleNotFoundError: No module named 'IPython'

My python version is 3.6. my OS is windows. After install rpy2 module, when I type import rpy2, got no issue. But when type import rpy2.ipython, got error as below:
>>> import rpy2.ipython
Warning (from warnings module):
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\rmagic.py", line 76
"either.")))
UserWarning: The Python package 'pandas' is strongly recommended when using `rpy2.ipython`. Unfortunately it could not be loaded, and we did not manage to load 'numpy' either.
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import rpy2.ipython
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\__init__.py", line 1, in <module>
from .rmagic import load_ipython_extension
File "D:\Soft_app\Python\lib\site-packages\rpy2\ipython\rmagic.py", line 81, in <module>
from IPython.core.displaypub import publish_display_data
ModuleNotFoundError: No module named 'IPython'
Can help to figure out what's issue??
It seems that you are missing Ipython and pandas. Installing them should resolve your issue.
Run "pip install ipython" to install Ipython and run "pip install pandas" to install pandas.
Hopefully, this will solve your problem.
Happy Coding ~

Resources