Python: Attribute Error When Importing Pandas From a Script - python

Pandas imports fail when I invoke a script from the command line. I can't identify what is causing this. Can anyone help me out? Thanks in advance!
Code
import pandas as pd
Error
root#vultr:~/Repos/solomon# python3 lib/scripts/dummy.py
Traceback (most recent call last):
File "lib/scripts/dummy.py", line 1, in <module>
import pandas as pd
File "/usr/local/lib/python3.5/dist-packages/pandas/__init__.py", line 42, in <module>
from pandas.core.api import *
File "/usr/local/lib/python3.5/dist-packages/pandas/core/api.py", line 10, in <module>
from pandas.core.groupby import Grouper
File "/usr/local/lib/python3.5/dist-packages/pandas/core/groupby.py", line 50, in <module>
from pandas.core.frame import DataFrame
File "/usr/local/lib/python3.5/dist-packages/pandas/core/frame.py", line 69, in <module>
from pandas.core.generic import NDFrame, _shared_docs
File "/usr/local/lib/python3.5/dist-packages/pandas/core/generic.py", line 48, in <module>
from pandas.io.formats.format import format_percentiles, DataFrameFormatter
File "/usr/local/lib/python3.5/dist-packages/pandas/io/formats/format.py", line 36, in <module>
from pandas.io.common import (_get_handle, UnicodeWriter, _expand_user,
File "/usr/local/lib/python3.5/dist-packages/pandas/io/common.py", line 484, in <module>
def UnicodeReader(f, dialect=csv.excel, encoding="utf-8", **kwds):
AttributeError: module 'csv' has no attribute 'excel'

Did you interrupted pandas installation?
Try to upgrade
(first install pip if you don't have it)
https://pip.pypa.io/en/stable/installing/
then
pip install pandas --upgrade

Solved:
It was because I had a directory named "csv" in the same directory as the run script. Stupid mistake. Sorry guys and gals.

Related

ImportError: DLL load failed: The specified procedure could not be found. (thinkdsp and thinkplot)

I am an amateur programmer. I am trying to use:
import thinkdsp as dsp
import thinkplot as plt
I have installed the pip install thinkx module but I keep getting that error and I don't understand why. I will leave what the console shows down below:
Traceback (most recent call last):
File "Karaokemaker1.py", line 1, in <module>
import thinkdsp as dsp
File "C:\Users\keigo\anaconda3\lib\site-packages\thinkdsp.py", line 17, in <module>
import scipy.stats
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\__init__.py", line 384, in <module>
from .stats import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\stats.py", line 185, in <module>
from . import distributions
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 25, in <module>
from scipy import optimize
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\__init__.py", line 390, in <module>
from ._minimize import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\_minimize.py", line 30, in <module>
from ._trustregion_constr import _minimize_trustregion_constr
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\_trustregion_constr\__init__.py", line 4, in <module>
from .minimize_trustregion_constr import _minimize_trustregion_constr
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\optimize\_trustregion_constr\minimize_trustregion_constr.py", line 4, in <module>
from scipy.sparse.linalg import LinearOperator
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\__init__.py", line 116, in <module>
from .eigen import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py", line 11, in <module>
from .arpack import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py", line 22, in <module>
from .arpack import *
File "C:\Users\keigo\anaconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py", line 45, in <module>
from . import _arpack
ImportError: DLL load failed: The specified procedure could not be found.
I assumed the issue was with the scipy because all the following errors come from that module. I checked and I have everything installed properly for the scipy module.
Please help! Thank you!
Run any command prompt you are using as administrator and then run pip install lib_name --force-reinstall
Try using these two commands they will help you:
conda remove --force scipy
And:
pip install scipy
Hello I had the same issue than you. Depend on wich version of python you use you should choose a version thinkx. I recommend you to go on the website of thinkx and check out for past udapte. In my case that was with matplotlib 3.3.1 for python 3.7. I went in git bash and used
pip install matplotlib==3.0.1
and everything worked. I had the same issue with seaborn and it worked.

Import Error: cannot import pivot_simple

I am using Ubuntu system with python 2.7 and pandas version of 0.19.I have been trying to run a python file and this error keeps on showing up-
>>> import file.py as x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "file.py", line 4, in <module>
import pandas as pd
File "/home/user/.local/lib/python2.7/site-packages/pandas/__init__.py", line 39, in <module>
from pandas.core.api import *
File "/home/user/.local/lib/python2.7/site-packages/pandas/core/api.py", line 20, in <module>
from pandas.core.reshape import (pivot_simple as pivot, get_dummies,
ImportError: cannot import name pivot_simple
Please help me in resolving the issue by telling the possible issues for this error and the way it can be removed.
Thanks!
instead of using 'files.py'
please try 'import files as x'

Could not Import Pandas: TypeError

I wanted to use the following pandas, but could not import it at all.
https://github.com/pydata/pandas/releases/download/v0.15.0/pandas-0.15.0.win-amd64-py2.7.exe
However I could not import it:
import pandas as pd
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandas as pd
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 45, in <module>
from pandas.io.api import *
File "C:\Python27\lib\site-packages\pandas\io\api.py", line 15, in <module>
from pandas.io.gbq import read_gbq
File "C:\Python27\lib\site-packages\pandas\io\gbq.py", line 39, in <module>
if LooseVersion(_GOOGLE_API_CLIENT_VERSION >= '1.2.0'):
File "C:\Python27\lib\distutils\version.py", line 265, in __init__
self.parse(vstring)
File "C:\Python27\lib\distutils\version.py", line 274, in parse
self.component_re.split(vstring))
TypeError: expected string or buffer
What's wrong guys?
This happened to me when upgrading google-api-python-client to a version higher than 1.2.0.
The problem is in Pandas, but it has been fixed: https://github.com/pydata/pandas/commit/403f38da35ab04d3997f61db3c98134fe02910d3
The solutions is to either downgrade google-api-python-client, fix the lines in pandas yourself or wait for pandas 0.15.1
Maybe you should try: pip install pandas (btw, you should install pip first).

Openpyxl missing 'jdcal'

I tried to install the openpyxl module, but during the installation it showed some errors with JDcall. When I then try to import it, I get this error:
Traceback (most recent call last):
File "C:\Andrzej\workspace\sandbox\sandbox.py", line 7, in <module>
import openpyxl
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\__init__.py", line 29, in <module>
from openpyxl.workbook import Workbook
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\workbook\__init__.py", line 25, in <module>
from .workbook import *
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\workbook\workbook.py", line 35, in <module>
from openpyxl.worksheet import Worksheet
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\worksheet\__init__.py", line 25, in <module>
from .worksheet import *
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\worksheet\worksheet.py", line 35, in <module>
import openpyxl.cell
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\cell\__init__.py", line 25, in <module>
from .cell import *
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\cell\cell.py", line 47, in <module>
from openpyxl.date_time import (
File "C:\Python34\lib\site-packages\openpyxl-2.0.5-py3.4.egg\openpyxl\date_time.py", line 34, in <module>
from jdcal import (
ImportError: No module named 'jdcal'
I get this same problem for Python 3.4 and 3.3, how can I solve it?
You should install jdcal separately. After this, install Openpyxl. I faced the same issue - after doing this, it got resolved
After I downloaded the jdcal-x.x.x.tar.gz from https://pypi.org/project/jdcal/#files and extracted it in \path\to\pythonxx\Lib\site-packages\ I had to copy the jdcal.py file from \path\to\pythonxx\Lib\site-packages\jdcal-1.4.1\ to \path\to\pythonxx\Lib\site-packages\ in order to work.
jdcal is a library required by openpyxl but should be installed automatically. How are you installing openpyxl?
I managed to get openpyxl to work by uninstalling openpyxl, jdcall and et-xmlfile, then reinstalling all three, then upgrading all three.
Not sure why it works, and the error messages are still there, but I was able to successfully import openpyxl and create a workbook.

Python error importing module pandas "name 'GET' is not defined"

I have the most updated numpy, httplib2, pytz, Cython, python-dateutil & numexpr
And newest pandas build
But I'm flummoxed! The following code gives the following rather cryptic error. What is it trying to tell me?
import pandas
print "ok pandas"
error:
Traceback (most recent call last):
File "sank.py", line 1, in <module>
import pandas
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.14.1-py2.7-macosx-10.6-intel.egg/pandas/__init__.py", line 45, in <module>
from pandas.io.api import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.14.1-py2.7-macosx-10.6-intel.egg/pandas/io/api.py", line 15, in <module>
from pandas.io.gbq import read_gbq
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas-0.14.1-py2.7-macosx-10.6-intel.egg/pandas/io/gbq.py", line 59, in <module>
import httplib2
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2-0.9-py2.7.egg/httplib2/__init__.py", line 1070, in <module>
from google.appengine.api import apiproxy_stub_map
File "/Users/maggielee/Documents/pythons/google.py", line 32, in <module>
GET / HTTP/1.0
NameError: name 'GET' is not defined
Solution by furas and OP.
I had an old file called google.py. Just renamed/deleted it and problem was solved.
Probably python uses this file when it imports from google.appengine.api.

Categories