My python 2.7 code is as follows:
import pandas as pd
from pandas import DataFrame
DF_rando = DataFrame([1,2,3])
...and then when I execute, I get a strange error regarding dateutil.tz.
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/mattobrien/pandas_test.py
No module named dateutil.tz
Traceback (most recent call last):
File "/Users/mattobrien/pandas_test.py", line 2, in <module>
import pandas as pd
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas/tslib.pyx", line 37, in init pandas.tslib (pandas/tslib.c:76999)
ImportError: No module named dateutil.tz
Process finished with exit code 1
Very strange. I checked an indeed dateutil.tz is indeed installed. I uninstalled Pandas and reinstalled it to be sure. No issues there.
Why am I getting this error?
Needed these 2 lines.
sudo pip install python-dateutil --upgrade
sudo pip install pytz --upgrade
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 reproducing a simple example from here to run Python into Power BI desktop :
https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts
import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print (df)
I do not know where to begin to solve this error:
Details: "ADO.NET: Python script error.
<pi>Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
_check_versions()
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 159, in _check_versions
from . import ft2font
ImportError: DLL load failed while importing ft2font: The specified module could not be found.
</pi>"
This works :
pip uninstall matplotlib
pip install --upgrade matplotlib
pip uninstall pandas
pip install --upgrade pandas
pip uninstall pillow
pip install --upgrade pillow
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
The full error:
import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
File "R:\Python34\lib\site-packages\matplotlib\__init__.py", line 180, in <module>
from matplotlib.cbook import is_string_like
File "R:\Python34\lib\site-packages\matplotlib\cbook.py", line 34, in <module>
import numpy.ma as ma
ImportError: No module named 'numpy.ma'
numpy is imported normally.
How do I install numpy.ma?
I also faced the same situation today. I found that I had saved a file as numpy.py, so check the filenames in your folder.
Re-install the correct version of numpy.
download correct .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
pip install C:\Path\To\Wheel\Filename.whl # for example: numpy-1.9.2+mkl-cp34-none-win_amd64.whl
Use Your (via terminal) package manager and search.
Example on Ubuntu:
aptitude search numpy
and install package.
In my case:
apt-get install python-numpy
Submodules aren't implicitly imported, and must be explicitly declared, but I'm making an explicit call to the pd.Series submodule, aren't I?
Regardless, shouldn't import pandas as pd allow for pd.Series to be called? The following code works flawlessly in iPython, but fails when executed from a script.
#!/usr/bin/env/python2.7
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
Results in:
tyler#machine ~/src/stats $ python pandas.py
Traceback (most recent call last):
File "pandas.py", line 3, in <module>
import pandas as pd
File "/home/tyler/src/stats/pandas.py", line 6, in <module>
counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
AttributeError: 'module' object has no attribute 'Series'
Where have I gone wrong?
The issue is that you've called your module pandas. Call it something else. And don't forget to delete the pandas.pyc generated on import pandas or else it will keep failing.
series in ipython not python
try
$ ipython
import pandas as pd
import numpy as np
counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
I had the same issue with the error message 'module' object has no attribute '_tseries', I have missed to install python-dateutil package.
The solution:
With python2.6, to install pandas 0.6.1, you have to install numpy 1.6.1 and python-dateutil like 2.6.1:
pip install numpy==1.6.1
pip install python-dateutil==2.6.1
pip install --force-reinstall pandas==0.6.1