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
Related
One of my script is importing Investpy library and I encoutered the following error message when I have checked the site-package the Investpy is in place.
Traceback (most recent call last):
File "/Users/LSH/WSFG_DEV/workspace/telegram_bot/roe_eps_check.py", line 9, in <module>
import investpy
File "/Users/LSH/Library/Python/3.8/lib/python/site-packages/investpy/__init__.py", line 7, in <module>
from .stocks import get_stocks, get_stocks_list, get_stocks_dict, get_stock_countries, get_stock_recent_data, \
File "/Users/LSH/Library/Python/3.8/lib/python/site-packages/investpy/stocks.py", line 16, in <module>
from lxml.html import fromstring
File "/Users/LSH/Library/Python/3.8/lib/python/site-packages/lxml/html/__init__.py", line 53, in <module>
from .. import etree
ImportError: cannot import name 'etree' from 'lxml' (/Users/LSH/Library/Python/3.8/lib/python/site-packages/lxml/__init__.py)
LSH#LSHs-Air workspace %
Does anyone know what is wrong? I have already remove and re-install Investpy but no luck.
Thank you everyone!! :)
You could try and do:
pip install lxml-4.6.3-cp38-cp38-win_amd64
OR
python -m pip install lxml==3.6.0
If this doesn't fix the issue, uninstall lxml and reinstall it using pip
Source:
ImportError: cannot import name 'etree' on Python 3.6
I am trying to run a program (obviously written in python) and it requires some python modules. One of the missed modules is aiomultiprocess. I tried installing it with pip install aiomultiprocess pip3 install aiomultiprocess python3.7 -m pip install aiomultiprocess but they all come back with the same error message:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/local/lib/python3.7/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/local/lib/python3.7/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.7/ctypes/__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
File "/usr/local/lib/python3.7/_ctypes.py", line 5, in <module>
import ffi
ModuleNotFoundError: No module named 'ffi'
No ffi module?! Let's get it!
I looked it up and figured it's a foreign library that come, in the case of python, as 2 forms: CFFI & LibFFI, but "ffi" doesn't exist for python. I installed cffi libffi and added them to this path /usr/local/lib/python3.7/site-packages/, but it changed nothing.
So my question is there another way to install python modules without the need of pip??!
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..
I tried to help('modules') and there was no nose module.
I even tried pip install nose, sudo pip install nose, and etc..
When ever I tried to install nose with command line, it will throw out
SyntaxError: invalid syntax.
Traceback (most recent call last):
File "C:\Python34\plot_cluster_iris.py", line 31, in <module>
from sklearn.cluster import KMeans
File "C:\Python34\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "C:\Python34\lib\site-packages\sklearn\cluster\spectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "C:\Python34\lib\site-packages\sklearn\utils\__init__.py", line 11, in <module>
from .validation import (as_float_array, check_arrays, safe_asarray,
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 17, in <module>
from .fixes import safe_copy
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
from .testing import ignore_warnings
File "C:\Python34\lib\site-packages\sklearn\utils\testing.py", line 36, in <module>
from nose.tools import assert_equal
What should I do?
I think your pip3 and python3 versions are mismatched, possibly due to multiple versions of Python 3 installed.
Run pip3 --version to find the exact Python version that pip3 is associated with and the location of site-packages directory.
Then, run python3 and look at the location of site-packages using:
import site
site.getsitepackages()
If you see different directory locations then that's your problem - multiple versions of Python 3. If it is indeed the problem, remove both the versions, re-install the correct one and then install your packages.
I hope this helps!
I just installed html5lib for Python with Windows Command Prompt. The package was installed here:
File "C:\Python27\lib\site-packages\html5lib
However, if I try to import html5lib:
#! /usr/bin/python
import html5lib
I get the following error:
Traceback (most recent call last):
File "C:\Users\workspace\testhtml5\src\test.py", line 2, in <module>
import html5lib
File "C:\Python27\lib\site-packages\html5lib\__init__.py", line 16, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "C:\Python27\lib\site-packages\html5lib\html5parser.py", line 2, in <module>
from six import with_metaclass
ImportError: No module named six
Any idea on what might be causing the error? Thanks
You're missing the six module. You can download it from here, or better, use pip install six .