Python3.6 error when we are passing csv file - python-3.x

While reading csv file in python3.6 this error throws:
KeyError: 'result'
Error in sys.excepthook:
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "main.py", line 117, in <module>
extractPreservationDataAndSet(l.getPreservationData(), test_response);
File "main.py", line 21, in extractPreservationDataAndSet
result = temp_http_response[i];
KeyError: 'result'
How can we solve it ?

ModuleNotFoundError: No module named 'apt_pkg'
indicates you don't have the apt_pkg module installed. Have a look at the home page of that package. There is a link on how to install it using the package manager.
The easiest way to install the module is probably:
pip3 install python-apt

This solved mine issue:
python3 -c "import nltk; nltk.download('all')"
it downloaded and unzipped all the packages.

Related

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

AttributeError: module 'importlib.machinery' has no attribute 'BuiltinImporter' when creating venv

When I try to create a virtual env with python3 (python3 -m venv <ENV_NAME>), I get the following error:
python3.7 -m venv watcher hossein#hostMHY12
Could not import runpy module
Traceback (most recent call last):
File "/Users/<USER_NAME>/miniconda3/lib/python3.7/runpy.py", line 15, in <module>
import importlib.util
File "/Users/<USER_NAME>/miniconda3/lib/python3.7/importlib/util.py", line 9, in <module>
from . import abc
File "/Users/<USER_NAME>/miniconda3/lib/python3.7/importlib/abc.py", line 83, in <module>
_register(MetaPathFinder, machinery.BuiltinImporter, machinery.FrozenImporter,
AttributeError: module 'importlib.machinery' has no attribute 'BuiltinImporter'
This is a strange error, and I couldn't find any answers online. Any help is appreciated.
This issue in my case was some sort of conflict with my miniconda. Once I removed it as explained in this link, everything was fine.

unable to run a python file because of Module not found error despite sourcing the pythonpath

I have been trying to run a python file using rosrun command but unfortunately I am having this module not found error because of a package named rospkg. Until a day before yesterday, it was all working fine but yesterday, ubuntu18.04 has got some updates out of which an update for ubuntu base was also present, since that update I am having this error.
I have tried to check whether I have installed the respective python-rospkg and its says I already have the latest version. I have also using
echo $PYTHONPATH
to check the sourced paths and they are sourced correct, I am not sure whats causing this error.
the error is as follows
Traceback (most recent call last
File
"/home/microbot/catkin_ws/src/spider/spider_control/control.py",
line 5, in <module>
import roslib
File "/opt/ros/melodic/lib/python2.7/dist-
packages/roslib/__init__.py", line 50, in <module>
from roslib.launcher import load_manifest
File "/opt/ros/melodic/lib/python2.7/dist-
packages/roslib/launcher.py", line 42, in <module>
import rospkg
ModuleNotFoundError: No module named 'rospkg'
The shebang for my is as follows,
#!/usr/bin/python3
When i try to run the file by changing the shebang to
#!/usr/bin/python2.7
I get the following error
Traceback (most recent call last):
File
"/home/microbot/catkin_ws/src/spider/spider_control/control.py",
line 3, in <module>
import tensorflow as tf
ImportError: No module named tensorflow
I have installed tensorflow version 1.14 using pip installation. Can anyone please help me solving this error. Thanks in advance
edit:
I have manually tried to set the python path to /usr/lib/python2.7/dist-packages as when I tried to install python-rospkg, it says the its already instaled in that location. Doing that I am having error importing tensorflow and the error is
`Traceback (most recent call last):
File
"/home/microbot/catkin_ws/src/spider/spider_control/control.py", line
3, in <module>
import tensorflow as tf
File "/home/microbot/.local/lib/python3.6/site-
packages/tensorflow/__init__.py", line 22, in <module>
import inspect as _inspect
File "/usr/lib/python3.6/inspect.py", line 41, in <module>
import linecache
File "/usr/lib/python3.6/linecache.py", line 11, in <module>
import tokenize
File "/usr/lib/python3.6/tokenize.py", line 33, in <module>
import re
File "/usr/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Error in sys.excepthook:`

python3 path only running google-appengine modules

When running django projects with python3 or installing modules with pip, I am getting google-appengine errors, even if my project is not using google appengine.
When running pip3 freeze I get the following results:
andrew#andrew:~/dev/quickistock$ pip3 freeze
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/home/andrew/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/andrew/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/andrew/.local/lib/python3.5/site-packages/pip/locations.py", line 10, in <module>
from distutils.command.install import install, SCHEME_KEYS # noqa
File "/usr/local/google-cloud-sdk/platform/google_appengine/lib/distutils/distutils/command/install.py", line 258
raise DistutilsOptionError, \
^
SyntaxError: invalid syntax
The file usr/local/google-cloud-sdk/platform/google_appengine/lib/distutils/distutils/command/install.py has lines like this and is compatible with python 2.1. Note. this is not the official google repository but it's accurate:
print "config vars:"
This means that install.py is a python 2 file and you are running pip from python 3. There probably is some incompatibility between them.

Jython ImportError: No module named urllib

Just installed Jython 2.7beta3 and pip under Jython in mac os x
try to run /usr/local/Cellar/jython/2.7-b3/libexec/bin/pip install requests
Get error:
Traceback (most recent call last):
File "./pip", line 8, in <module>
sys.exit(
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 519, in load_entry_point
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 2630, in load_entry_point
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 2310, in load
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/setuptools-11.3.1-py2.7.egg/pkg_resources/__init__.py", line 2316, in resolve
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/pip-6.0.6-py2.7.egg/pip/__init__.py", line 15, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/Cellar/jython/2.7-b3/libexec/Lib/site-packages/pip-6.0.6-py2.7.egg/pip/vcs/__init__.py", line 8, in <module>
from pip._vendor.six.moves.urllib import parse as urllib_parse
ImportError: No module named urllib
I found I can't install anything by pip under jython.
Please help me fix it, thanks.
I had the same problem trying to use pip for Jython2.7b3.
I downloaded this:
https://github.com/jythontools/pip/tree/master
And ran the command:
Jython setup.py install
And pip is now up and running like a charm.

Resources