ImportError: cannot import name 'Coroutine' - python-3.x

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

Related

Installing tensorflow object_detection api in a repo in google drive

I have cloned the models repo from TensorFlow and installed it into my project folder in google drive.
but when I try to run the model_builder_tf2_test.py I am getting ModuleNotFoundError: No module named 'object_detection' error.
import sys
nb_path = '/content/drive/MyDrive/project/lib'
sys.path.insert(0, nb_path)
and installed it using the following command
!python -m pip install --target=$nb_path .
the files are downloaded into the project folder but can't be accessed by the files in models repo.
however, I can access the modules using the:
import sys
sys.path.append('/content/drive/MyDrive/project/lib')
The error I am getting after running:
%cd /content/drive/MyDrive/project/models/research
!python object_detection/builders/model_builder_tf2_test.py
is:
Traceback (most recent call last):
File "object_detection/builders/model_builder_tf2_test.py", line 24, in <module>
from object_detection.builders import model_builder
ModuleNotFoundError: No module named 'object_detection'
I would add this as a comment but still don't have enough reputation.
did you try using this?
pip install tensorflow-object-detection-api
if it helps,
believe the question is a duplicate?

Python Circular Import Module _gi causes apt-add-repository command to fail in linux

I was trying to add a repository today when i find a strange error that i cannot seem to solve.
I was trying to do this command
sudo apt-add-repository ppa:fish-shell/release-3
When it always returned this error message
Traceback (most recent call last):
File "/usr/bin/apt-add-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 67, in <module>
from gi.repository import Gio
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gi/__init__.py)
I've tried diagnosing it with this command
sudo update-alternatives --config python3
and it shows this
There is only one alternative in link group python3 (providing /usr/bin/python3): /usr/bin/python3.8
Nothing to configure.
I've also tried going to the /usr/lib/python3/dist-packages/gi
and adding a symbolic link there with this command
sudo ln -s _gi.cpython-{36m,37m}-x86_64-linux-gnu.so
Still it didn't work
I've tried adding the correct python version to /usr/bin/apt-add-repository
I have also tried to use
python3 -m pip install gi
Could not find a version that satisfies the requirement gi (from versions: )
No matching distribution found for gi
How do i fix this annoying error?
done:
sudo apt-get install graphviz
And the code:
import objgraph
import random
import io
from graphviz import Source
from io import StringIO
q = StringIO()
#objgraph.show_refs([SAFE_TAGS], output=s)
objgraph.show_chain(
objgraph.find_backref_chain(
random.choice(objgraph.by_type('dict')),
objgraph.is_proper_module),
output=q)
q.seek(0)
Source(q.read())
chart

ModuleNotFoundError: No module named 'cassandra'

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

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

Cannot import opencv besides in site-packages directory with python3

I am following a lynda openCV python course and its opencv installation guide but got stuck on importing the cv2.
I used pip3 install opencv-python to install cv2.
I can only import cv2 when my current directory is /usr/local/lib/python3.6/site-packages . Anywhere else would give me
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
Following are my system versions:
Python 3.6.0
macOS High Sierra 10.13.2
Opencv version '3.4.0'
Here's the __init__.py found in /usr/local/lib/python3.6/site-packages/cv2, not sure how this matters though
import importlib
import os
from .cv2 import *
from .data import *
# wildcard import above does not import "private" variables like __version__
# this makes them available
globals().update(importlib.import_module('cv2.cv2').__dict__)
UPDATE
I added this code and it seems to be working from any directory, still question is why do I have to do this? I can just import numpy from anywhere.. weird
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages')
It is because of your cv2.so compiled library file. If you look into your /usr/local/lib/python3.6/site-packages/cv2/python-3.6 folder (or for some users, its inside /usr/local/python/cv2/python-3.6), you should see the file cv2.cpython-36m-darwin.so like so:
(cv) fangran#Fangs-MacBook-Pro ~ % ls /usr/local/lib/python3.6/site-packages/cv2/python-3.6
cv2.cpython-36m-darwin.so
Now, what you'd want to do is to cd into that directory and rename it to cv2.so (so its easier)
(cv) fangran#Fangs-MacBook-Pro ~ % cd /usr/local/lib/python3.6/site-packages/cv2/python-3.6
(cv) fangran#Fangs-MacBook-Pro python-3.6 % sudo mv cv2.cpython-36m-darwin.so cv2.so
In case you're in a virtual environment (which is recommended), make sure to do into the site-packages of that environment and do a symlink:
(cv) fangran#Fangs-MacBook-Pro site-packages % cd ~/.virtualenvs/cv/lib/python3.6/site-packages/
(cv) fangran#Fangs-MacBook-Pro site-packages % ln -s /usr/local/python/cv2/python-3.6/cv2.so cv2.so
or if not, just make sure that whatever env you're in can get access to the cv2.so file.

Resources