When importing pandas I would get the following error:
Numpy.dtype has the wrong size, try recompiling
I am running Python 2.7.5, with Pandas 0.14.1, and Numpy 1.9.0. I have tried installing older versions of both using pip, with major errors every time. I am a beginner when it comes to Python so any help here would be much appreciated. :)
EDIT: running OS X 10.9.4
EDIT 2: here is a link to a video of me uninstalling and reinstalling Numpy + Pandas, and then running a .py file: https://www.dropbox.com/s/sx9l288jijokrar/numpy%20issue.mov?dl=0
I've seen this error before and it typically does have to do with pandas referencing an old version of numpy. But reinstalling may not help if your python path is still pointing to an old version of numpy.
When you install numpy via pip, pip will tell you where it was installed. Something like
pip install numpy==1.9.2
Requirement already satisfied (use --upgrade to upgrade): numpy==1.9.2 in /Library/Python/2.7/site-packages
Cleaning up...
So you have the correct version of numpy installed. But when you go into python
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.pyc'
>>> numpy.version.version
'1.8.0rc1'
Your path might be pointing at a different numpy.
Easiest solution I've found for this is simply to remove the unwanted version of numpy (moving it to a _bak folder for safety)
mv /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy_bak
And now when I start python
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/Library/Python/2.7/site-packages/numpy/__init__.pyc'
>>> numpy.version.version
'1.9.2'
I've got the version I want.
For more complex workflows where different applications might need different versions of various packages, virtualenvs are a great way to go http://docs.python-guide.org/en/latest/dev/virtualenvs/. But I think for your case where you just want pandas and numpy to play nice, this approach should work fine.
I got same error. I solved by deleting existing numpy and reinstall again.
pip uninstall numpy #it will remove older version of numpy on your computer
pip install numpy #it will install recent version of numpy
Actually I don't have any idea why it works. I just changed numpy version.
you should try to upgrade your numpy to latest. it worked for me.
pip install --upgrade numpy
Related
I am using anaconda 3. When I try to import pandas I receive the following message:
ImportError: this version of pandas is incompatible with numpy < 1.15.4
your numpy version is 1.15.3.
Please upgrade numpy to >= 1.15.4 to use this pandas version
Printing numpy.__path__ gives me the following
['C:\Users\andrei\AppData\Roaming\Python\Python37\site-packages\numpy']
In conda list, my numpy version is 1.19.1. I checked the above directory to find that it has only numpy 1.15.3 inside and nothing else. Spyder is using this path instead of the anaconda's path to numpy for some arcane reason.
Looks like you have somehow installed several versions of NumPy. Try to remove them all by running several times conda remove numpy and pip uninstall numpy. If you have two versions, the corresponding uninstall command needs to be run twice. After these, install a fresh version of NumPy conda install numpy
You can verify if you still have a version of NumPy installed
conda list | grep numpy
pip list | grep numpy
Note that these commands show only one version number even if you have several copies installed.
You can use conda to upgrade to upgrade your numpy. Run this command in the terminal:
conda update numpy
You need to remove this directory
C:\Users\andrei\AppData\Roaming\Python\
to fix this problem. It seems at some point you used pip to install numpy and that's interfering with the packages installed by conda (which is reporting the right version, as you said).
Furthermore, please be aware that pip and conda packages are binary incompatible, so you should avoid as much as possible to mix them.
I am testing out Quantopian's zipline in a python 3.5.6 environment that I created with Anaconda. Per their documentation, pandas 0.22 is the recommended version, and for my own sanity, I'd like to stay with that version.
In conda, if I do
conda list | grep pandas
I get the following, as expected.
pandas 0.22.0 py35h0a44026_0
pandas-datareader 0.8.1 py_0
However, when I am in python, I get
Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 16:30:03)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> print (pd.__version__)
0.25.3
Why is it doing that? And how do I make sure that only pandas 0.22 is loaded into my python session?
Thank you for your help.
I installed mxnet in linux mint. I use anaconda for python 3.5. I followed the instruction and it was successfully installed. Both mxnet and the anaconda are latest version. However, when I tried the code:
import mxnet as mx
res = mx.nd.array([1,2,3])
I got the error:
AttributeError: module 'mxnet' has no attribute 'nd'
if I typed mx, I got: <module 'mxnet' (namespace)>
after repeating the installation and checking the scripts, I saw mxnet was installed under python 2.7, and graphviz is also under python 2.7. How can change them to python 3.5?
Working for MXNet python 3 is still in progress. Some functions are not fully tested yet.
At this time I suggest using python 2.7.
It should work in Python 3 environments.
I've installed MXNet in one easy set with pip3 in a python environment.
Everything works well.
Missing are some MXNet python API's advertised in the documentation, which are absent in the distribution and look absent in the current head of the repository as well.
So, I would not currently depend on the tutorial or example documentation -- they seem to be outdated or ahead of the repository. They cannot always guide you properly although in order to rescue yourself from particular situations reading the actual API documentation might help.
Anaconda Python 3.5 works fine for MXNet. See evidence below.
$ which python
/Users/username/anaconda3/bin/python
$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mxnet as mx
>>> res = mx.nd.array([1,2,3])
>>> print(res)
<NDArray 3 #cpu(0)>
>>> print(res.asnumpy())
[ 1. 2. 3.]
>>> mx
<module 'mxnet' from '/Users/username/anaconda3/lib/python3.5/site-packages/mxnet-0.9.5-py3.5.egg/mxnet/__init__.py'>
The Python API documentation has been updated in newer releases. See: https://github.com/dmlc/mxnet/releases
When you use Anaconda3 with Python3 and MXNet, the installation process might get a bit cumbersome.
In my case, after following the installation steps and executing python setup.py install - I had to manually copy python/mxnet files into the ~/Anaconda3/Lib/site-packages/mxnet*../
Before I copied the files, I've seen the same error module 'mxnet' has no attribute 'nd'
QTConsole is running the latest version of pandas (i.e. 0.18). However, when I import pandas in Jupyter notebook, it can only import 0.15. How can I resolve this?
**QT Console:**
Jupyter QtConsole 4.2.0
Python 2.7.11 |Anaconda 4.0.0 (x86_64)| (default, Dec 6 2015, 18:57:58)
Type "copyright", "credits" or "license" for more information.
IPython 4.1.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
import pandas
print pandas.__version__
0.18.0
**Jupyter**
import pandas
print pandas.__version__
0.15.0
You probably have different versions of Python installed via different distributions. If you are using Windows, I recommend uninstalling all Python versions/distributions, rebooting and then only installing one.
If you are using Mac, ensure that you have only one version of Anaconda installed and that it is the version first in your PATH if you are using a terminal. It may be that a different version has been installed by for instance homebrew. To check your path do !echo $PATH from both of the environments. You should see your anaconda directory early in the path (before /usr/local/bin and /usr/bin). You can also do !which python from both of the environments to see which Python binary is being used.
I just installed theano, but
import numpy
print numpy.version
here is the output
Theano version 0.7.0.dev-30cc6380863b08a3a90ecbe083ddfb629a56161d
theano is installed in /home/sizhexi/theano/Theano/theano
NumPy version 1.8.2
NumPy is installed in /usr/lib/python2.7/dist-packages/numpy
Python version 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]
nose version 1.3.1
RuntimeError: module compiled against API version a but this version of numpy is 9
terminate called after throwing an instance of 'std::runtime_error'
what(): numpy failed to initialize
Aborted (core dumped)
how to solve it?
Package management in python is sometimes tricky. To avoid these issues, I recommend using Anaconda which is a good python package and environment manager (download here, and 30 minutes guide).
Follow the official instructions to install Anaconda and chose the default values that will add Anaconda to your $PATH and make Anaconda your default python interpreter. Then open your terminal and use the following commands :
conda install pip six nose numpy scipy
pip install theano
Then try running your script using anaconda.