ImportError while running python program - python

I have tried all the import methods and upgrading the libraries but still I'm unable to get over this error. I have downloaded and installed all the nltk and corpus data programmatically and it is working in the python shell but i'm getting error.
Traceback (most recent call last):
File "spark.py", line 7, in <module>
from textblob_aptagger import PerceptronTagger
File "/usr/local/lib/python2.7/dist-packages/textblob_aptagger/__init__.py", line 8, in <module>
from textblob_aptagger.taggers import PerceptronTagger
File "/usr/local/lib/python2.7/dist-packages/textblob_aptagger/taggers.py", line 10, in <module>
from textblob.packages import nltk
ImportError: No module named packages
Here's a pastebin to my code and imports..

Same error has been posted on github here. Use this instead to install textblob:
$ pip install -U git+https://github.com/sloria/textblob-aptagger.git#dev
Also, you should change from text.blob import TextBlob as tbto from textblob...
Works for me..

Related

I am trying to use module requests in python and it is simply not working

My issue
i have downloaded chardet, requests, typing, binary io, and django modules in an effort to fix whatever issue i am having while importing python module requests.
I also reainstalled python with the standard group of python modules option. I dont know what the issue is please help. Thank you.
Further information
Python 3.9
Installed using pip
The code:
import requests
Below is the error log:
Traceback (most recent call last):
File "C:\PROGRA~1\IBM\SPSS\STATIS~1\26\Python3\Lib\site-packages\requests\compat.py", line 12, in <module>
import chardet
ImportError: No module named 'chardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import requests
File "C:\PROGRA~1\IBM\SPSS\STATIS~1\26\Python3\Lib\site-packages\requests\__init__.py", line 45, in <module>
from .exceptions import RequestsDependencyWarning
File "C:\PROGRA~1\IBM\SPSS\STATIS~1\26\Python3\Lib\site-packages\requests\exceptions.py", line 11, in <module>
from .compat import JSONDecodeError as CompatJSONDecodeError
File "C:\PROGRA~1\IBM\SPSS\STATIS~1\26\Python3\Lib\site-packages\requests\compat.py", line 14, in <module>
import charset_normalizer as chardet
File "C:\PROGRA~1\IBM\SPSS\STATIS~1\26\Python3\Lib\site-packages\charset_normalizer\__init__.py", line 24, in <module>
from .api import from_bytes, from_fp, from_path, normalize
File "C:\PROGRA~1\IBM\SPSS\STATIS~1\26\Python3\Lib\site-packages\charset_normalizer\api.py", line 3, in <module>
from typing import BinaryIO, List, Optional, Set
ImportError: No module named 'typing'
I have found the issue after checking everything using pip. All modules up to date python up to date pip up to date. However despite completely uninstalling and reinstalling setuptools was out of date. so i updated setuptools with pip.
to find out whats out of date with pip:
pip list --outdated

Finding NLTK module in python

I'm trying to use the NLTK module in IDLE but it can't find the moduleā€”I noticed NLTK had downloaded to my system's default python directory for the 2.7 version, so I found the file path to the "site-packages" folder in 3.8 and copied NLTK there, but now when I try to "import NLTK" in python I get this error message:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/__init__.py", line 99, in <module>
from nltk.internals import config_java
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/nltk/internals.py", line 28, in <module>
from six import string_types
ModuleNotFoundError: No module named 'six'
As I understand your intention is to use the NLTK package that you have installed for Python 2.7 , in Python 3.8, correct ?
In such case you shouldn't copy the library yourself, but rather use pip3 to install it once again into P3.8.

Python import error no module named bz2

I have libbz2-dev installed however I am still getting the following import error while importing gensim :
>>> import gensim
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/krishna/gensimenv/lib/python2.7/site-packages/gensim/__init__.py", line 6, in <module>
from gensim import parsing, matutils, interfaces, corpora, models, similarities, summarization
File "/home/krishna/gensimenv/lib/python2.7/site-packages/gensim/corpora/__init__.py", line 14, in <module>
from .wikicorpus import WikiCorpus
File "/home/krishna/gensimenv/lib/python2.7/site-packages/gensim/corpora/wikicorpus.py", line 21, in <module>
import bz2
ImportError: No module named bz2
you can try to do
pip install bz2file
I'm having the same issue and the tip above didn't resolve it.
Perhaps before creating the virtual env you need to:
sudo apt-get install libbz2-dev
related:
missing python bz2 module

Python ImportError: cannot import name utils

I'm having this issue running a script and it looks like it missed some dependencies, but as you can see below. After installing the missing libraries, it doesn't make any sense.
[ericfoss#maverick-fossum-ddns-net packages]$ python -c "import utils"
[ericfoss#maverick-fossum-ddns-net packages]$ python -c "import requests"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 64, in <module>
from . import utils
ImportError: cannot import name utils
[ericfoss#maverick-fossum-ddns-net packages]$
Any idea why utils can be imported, but requests can't?
Check if Requests requirements are satisfied:
$ pip show requests
...
Requires: certifi, idna, chardet, urllib3
I hit the same error but I was missing idna. After installing it the issue resolved.
Well, after pip uninstall requests and reinstalling, it no longer would work at all. Luckily, dnf install python-requests fixed the whole thing...
We may see the unable to import utils error in multiple contexts.
I got this error message when I was migrating scripts from python 2 to 3.
I used the inbuilt python migration automated tool to change the file that is causing the import error using the command 2to3 -w filename
This has resolved the error because the import utils is not back supported by python 3 and we have to convert that code to python 3.
I ran into a similar problem when running Jupyter Lab:
$ jupyter-lab --ip 0.0.0.0
Traceback (most recent call last):
File "/Users/gtholpadi/opt/anaconda3/bin/jupyter-lab", line 6, in <module>
from jupyterlab.labapp import main
File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab/labapp.py", line 14, in <module>
from jupyterlab_server import slugify, WORKSPACE_EXTENSION
File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/__init__.py", line 4, in <module>
from .app import LabServerApp
File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/app.py", line 10, in <module>
from .handlers import add_handlers, LabConfig
File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/handlers.py", line 18, in <module>
from .listings_handler import ListingsHandler, fetch_listings
File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/jupyterlab_server/listings_handler.py", line 17, in <module>
import requests
File "/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/requests/__init__.py", line 120, in <module>
from . import utils
ImportError: cannot import name 'utils' from partially initialized module 'requests' (most likely due to a circular import) (/Users/gtholpadi/opt/anaconda3/lib/python3.8/site-packages/requests/__init__.py)
requests was already installed when I got this error. I tried pip install -U requests and that solved the problem.
utils package is not installed
You can install package using
sudo pip install utils

msession not defined

I am trying to run this example program - http://pysnmp.sourceforge.net/examples/1.x/snmpbulk.html
I am on Mac OS X, and I installed pysnmp by -
$ sudo /usr/local/bin/pip install pysnmp
Now when I run the program I get -
Traceback (most recent call last):
File "pysnmptest.py", line 2, in <module>
from pysnmp import msession
ImportError: cannot import name msession
UPDATE:
seems like pysnmp 4.x doesn't have msession, so I tried http://pysnmp.sourceforge.net/examples/4.x/v3arch/index.html
and now I get -
Traceback (most recent call last):
File "pysnmptest.py", line 2, in <module>
from pysnmp.entity.rfc3413.oneliner import cmdgen
File "/Library/Python/2.6/site-packages/pysnmp/entity/rfc3413/oneliner/cmdgen.py", line 2, in <module>
from pysnmp.entity import engine, config
File "/Library/Python/2.6/site-packages/pysnmp/entity/engine.py", line 2, in <module>
from pysnmp.proto.rfc3412 import MsgAndPduDispatcher
File "/Library/Python/2.6/site-packages/pysnmp/proto/rfc3412.py", line 3, in <module>
from pysnmp.smi import builder, instrum
File "/Library/Python/2.6/site-packages/pysnmp/smi/builder.py", line 4, in <module>
from pysnmp.smi import error
File "/Library/Python/2.6/site-packages/pysnmp/smi/error.py", line 1, in <module>
from pyasn1.error import PyAsn1Error
ImportError: No module named pyasn1.error
The webpage also says they have dependencies on third-party libraries -
Latest PySNMP releases (4.x and later)
depend on the following:
ASN.1 library for Python used for
handling ASN.1 objects Python
Cryptography Toolkit used for SNMP
message authentication and encryption
How do I install them? and would it better to install from the tarball from webpage directly?
which version of pysmnp did you install? The example you're trying to run seems to be suited for the 1.x version of pysnmp.
Here I've found examples for the newest 4.x version. Note they don't use msession so I guess it was removed.
EDIT: Looks like now you have to install pyasn1 from here...
I don't use OSX so I don't know what's the better method for installing software on it. On ubuntu I just did apt-get install python-pysnmp and the whole thing was installed.
pyasn1 has been depended by pysnmp. So you could just type:
from pyasn1.error import PyAsn1Error

Categories