I have been experiencing the following problem with pandas for days: I can import pandas when I use spyder but it does not work when I use ipython or jupyter. I have been looking in several directions to solve the problem:
I have updated pandas,
I have checked that ipython and spyder have the same pythonpath,
I have uninstalled and reinstalled spyder
It still does not work and I get the following error message:
ImportError Traceback (most recent call last)
<ipython-input-8-d6ac987968b6> in <module>()
----> 1 import pandas
/Users/ME/anaconda/lib/python2.7/site-packages/pandas/__init__.py in <module>()
29 "pandas from the source directory, you may need to run "
30 "'python setup.py build_ext --inplace' to build the C "
---> 31 "extensions first.".format(module))
32
33 from datetime import datetime
ImportError: C extension: hashtable not built.
If you want to import pandas from the source directory, you may need to run
'python setup.py build_ext --inplace' to build the C extensions first.
I see that other people had the same problem but there is no clear answer. Does anyone know the procedure to solve it ?
I found the solution: the error comes from a value error due to an encoding problem.
It happens quite a lot in python and various questions have been asked about it. Among them, the following link explains it carefully:
Pelican 3.3 pelican-quickstart error "ValueError: unknown locale: UTF-8"
To be short, one only needs to run the following bash code to solve the problem:
echo -e "export LC_ALL=en_US.UTF-8\nexport LANG=en_US.UTF-8" >> ~/.bashrc && source ~/.bashrc
Related
I apologies for the trivial question but when I tried to run a few scripts this morning that had been working for months I came across the following error message:
import scipy.stats
Traceback (most recent call last):
File "<ipython-input-5-b66176eb2d0a>", line 1, in <module>
import scipy.stats
ImportError: No module named stats
So I get the problem that Python doesn't seem to find the stats package in the scipy folder, yet I double checked that I indeed had a scipy folder in the Python install directory as well as a stats folder within the scipy folder.
I do have the following: C:\Python27\Lib\site-packages\scipy\stats\
I use Spyder, I tried reloading the kernel, closing and reopening Spyder but nothing seems to work.
Further info;
I do have an __init__.py in the scipy folder.
The import scipy command works
attempts to load other packages within scipy also throw the error
Any help would be very welcome if you encountered the same problem before !
EDIT:
Okay so I restarted the kernel from the python console once more and did the following, which works:
import os
os.getcwd()
Out[2]: 'C:\\Python27\\lib\\site-packages'
from scipy import stats
The bug has now moved on to another package...
I suspect that when I am running my script which is located on another drive Python struggles to find the packages. My puzzles me is that it didn't use to.
I'm running Python 2.7.11 under Anaconda 2.0.0 (x86_64) on a MacBook.
Some weeks ago, as part of a process of getting OpenCV working, I downgraded numpy from wherever it was (unfortunately/stupidly I have no record) to 1.7.1. I seem to remember this was necessary, and I do not want OpenCV to stop working, so I'm pretty sure I should now leave numpy where it is.
However, today I discovered that this has broken my matplotlib/pylab. When I do import pylab I get the following:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 9 but this version of numpy is 7
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
...
...
ImportError: numpy.core.multiarray failed to import
My question, therefore, is: how do I install (or roll back to) a version of matplotlib that's compatible with my existing numpy, without disturbing my existing numpy?
Here's where I've got so far: based on related conda questions on SO, I looked at the output of conda list --revisions matplotlib which includes:
...
2016-03-28 17:16:36 (rev 6)
conda {3.8.3 -> 4.0.5}
conda-env {2.0.1 -> 2.4.5}
numpy {1.8.1 -> 1.7.1}
...
Now I'm not sure how to interpret this but given the numpy version number looks like it's actually falling in contrast to all the other entries here, this sounds to me like a promising, "in March 2016 matplotlib realized it could fall back to an earlier version of its numpy dependency". However, when I ask for this revision:
conda install --revision=6 matplotlib
I'm told I already have it, and that its dependency is numpy 1.8:
Fetching package metadata: ....
# All requested packages already installed.
# packages in environment at /Users/jez/anaconda:
#
matplotlib 1.3.1 np18py27_1 <unknown>
So from here I'm not sure how to proceed. I've tentatively played with some variations on conda install matplotlib, but it clearly wants to mess with my numpy at the same time, so I have never pressed y. Equally clearly, I'm out of my depth in conda, so would really appreciate your help.
You can specify the exact versions of any libraries you want in the conda install command. For example:
$ conda install numpy=1.7.1 matplotlib=1.3
If the versions are incompatible, the command will give you an error specifying exactly what the incompatibility is.
I am current getting the error
ImportError: cannot import name gof
when importing theano.
>>> import theano
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import theano
File "C:\Python27\lib\site-packages\theano\__init__.py", line 63, in <module>
from theano.compile import (
File "C:\Python27\lib\site-packages\theano\compile\__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "C:\Python27\lib\site-packages\theano\compile\function_module.py", line 16, in <module>
from theano import gof
ImportError: cannot import name gof
I am using python 2.7.10 (). Theano is installed using pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git.
Hope to get you suggestion to solve this problem
Most of the time, when I see this error, it is caused by those 2 errors:
1) A syntax error in Theano. Update Theano and make sure to have no local modifcation. I nerver saw this error in the master of Theano, but just in case.
2) When there is multiple version of Theano that are installed.
In both case, remove all version of Theano. Do it multiple time to be sure there is none left. Then install again.
From memory, this always solved the problem when it wasn't a syntax error during development (but not in the master version of Theano that you use)
This ImportError can be caused because Theano is unable to compile the gof module itself. If this is the case, you will see an error message that looks like "Exception: Compilation Failed (return status=1): C:\Long\Path\...\mod.cpp:1: sorry, unimplemented: 64-bit mode not compiled in".
Fixing With Conda
If you are installing theano into a conda environment, make sure that you have a C compiler available to that environment.
The command
conda install m2w64-toolchain
will provide a C compiler to your environment that's isolated from the rest of the machine.
After the m2w64-toolchain package is installed, import theano should work
Fixing Manually
If you are installing Theano yourself, two points from these threads may help:
Install the bleeding edge version of Theano
Install libpython from http://www.lfd.uci.edu/%7Egohlke/pythonlibs/
I assume you're using Windows 7 or later.
If you have installed Python Anaconda, then open Windows Powershell or Command Prompt and type conda install mingw libpython before typing pip install theano
Alternatively, if you don't have Anaconda, download those packages from
anaconda.org/anaconda/mingw/files
anaconda.org/anaconda/libpython/files
github.com/Theano/Theano
Then open Command Prompt, navigate to each folder and type python setup.py install
Now run Python and import theano
Possible errors:
If you get the RuntimeError: "To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement" then
Go to Control Panel > System > Advanced system settings and select "Environment Variables".
In the "System variables" section, make a new variable name MKL_THREADING_LAYER and set its value to GPU
If you get other kinds of errors, then try the following:
Make an empty file called .theanorc (a file extension without a file name) in your home folder C:\Users\<username>. If you get the error "You must type a file name" then see stackoverflow.com/q/5004633
Open .theanorc and write this:
[global]
cxx=C:\<path to Anaconda>\Anaconda3\MinGW\bin\g++.exe
Run Python again and import theano. If it works, then you can probably delete .theanorc
In my case, the fix was to install a python build that's callable as a shared library:
PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.15
I tried installing pandas using easy_install and it claimed that it successfully installed the pandas package in my Python Directory.
I switch to IDLE and try import pandas and it throws me the following error -
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pandas
File "C:\Python27\lib\site-packages\pandas-0.12.0-py2.7-win32.egg\pandas\__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:20282)
ValueError: numpy.dtype has the wrong size, try recompiling
Please help me diagnose the error.
FYI: I have already installed the numpy package
Maybe you interrupted pandas install , retry using pip :
First install pip (if you haven't done it already) :
easy_install pip
then reinstall pandas:
pip install pandas --upgrade
Hope it helps
You know that output error you got when you tried running #nipun-batra's script?
Well, you got it because you have to first:
import platform
before you can run:
platform.platform()
I know this because I--about 10 minutes ago--got the same error when trying to run the same script. The difference is that I--an absolute beginner--figured out our problem after a quick trip over to google. (Man, they let you search for anything over there!)
This, when coupled with your follow-up appeal exactly two months after your initial posting, suggests to me that you would prefer to minimize--as much as possible--the usual hardship associated with owning and operating your own computer-machine-thingy.
As a result, with respect to your initial IDLE/pandas issue, your best best bet is to forget about messing around with easy_install, etc. Instead, go head on down to Continuum Analytics and pick up your very own (free) copy of Anaconda, which has got more packages than you can shake a stick at! (Including, I might add, pandas, numpy, scipy, statsmodels, matplotlib, IPython, and many more). And the best part is that it all comes bundled together as a single easy-to-download file. Trust me, it will save you a lot of headaches if you just download everything all at once.
Hope this helps!
Panda does not work with python 2.7 , do you will need python 3.6 or higer
I tried looking for an answer to this around the forum/google, but I can't find anything. My issue is this (from python console):
>>> import pandas
cannot import name hashtable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pandas\__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
ImportError: cannot import name hashtable //also can't import name NaT somtimes
I ran the windows 1-click installer prior to attempting the import. I'm running everything 32-bit. The pandas installer is for python 2.7.
Here's a list of modules that I have correctly imported into Python.
setuptools
pip
mox
dateutil
six
numpy
SQLAlchemy
I'm on windows 7.
I also have anaconda installed, but that was really just a "hail mary" after I tried everything else. My end goal is to install the ultra-finance module. However, it seems to require pandas, hence me being stuck.
I'm a python noob, so please don't assume I know anything. Thanks.
EDIT: please let me know if I can provide any extra information.
The recommended way to install pandas is via pip:
pip install pandas
This hashtables error arises from the cython files not being built. This error message will be more informative from 0.11.1.
Try running your code in Spyder (Anaconda -> Spyder). It worked for me.
Check that you have python scripts included in your system path variable. In my case I had to add "C:\Python27\Scripts"
I was having a similar problem when downloading Pandas to my Windows 8 system. The first error I had was an egg error, but after installing some packages I think I have the solution.
First look at the previous pip errors with Pandas, make sure you have the most updated pip.
The second part is downloading wheel using
pip install wheel
After installing wheel and having the dependencies for panda and using pip it worked correctly.