New to Python. Trying to understand how to import the pandas module. I imported it through Pycharm, then ran a basic script seen below. I get several errors that I'm not sure how to interpret
import pandas
x = input("Enter your age")
print(x)
I receive this error message.
Traceback (most recent call last):
File "C:/Users/leeb/PycharmProjects/HelloWorld/app.py", line 1, in <module>
import pandas
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\pandas\__init__.py", line 11, in <module>
__import__(dependency)
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\numpy\__init__.py", line 150, in <module>
from . import random
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\numpy\random\__init__.py", line 181, in <module>
from . import _pickle
File "C:\Users\leeb\PycharmProjects\HelloWorld\venv\lib\site-packages\numpy\random\_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "type.pxd", line 9, in init numpy.random.mtrand
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 440 from C header, got 432 from PyObject
This error tends to happen when you have an older version of Numpy installed.
You should upgrade it, as follows:
pip install numpy --upgrade
If that doesn't work, try to use a specific version of numpy, as follows:
pip uninstall numpy
pip install numpy==1.15.1
Or, if you're using anaconda, try:
conda update numpy
Related
I need to install pandas on a LinuxOS. Initially, I used
sudo apt-get install python3-pandas
It looked like the installation was complete but then I switch to Thonny and import pandas and get this
Traceback (most recent call last):
File "<pyshell>", line 1, in <module>
File "/usr/local/lib/python3.7/dist-packages/pandas/_init_.py", line 22, in <module>
from pandas.compat import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/_init_.py", line 15, in <module>
from pandas.compat.numpy import (
File "/usr/local/lib/python3.7/dist-packages/pandas/compat/numpy/_init_.py", line 7, in <module>
from pandas.util.version import Version
File "/usr/local/lib/python3.7/dist-packages/pandas/util/_init_.py", line 1, in <module>
from pandas.util._decorators import ( # noqa
File "/usr/local/lib/python3.7/dist-packages/pandas/util/_decorators.py", line 14, in <module>
from pandas._libs.properties import cache_readonly # noqa
File "/usr/local/lib/python3.7/dist-packages/pandas/libs/init_.py", line 13, in <module>
from pandas._libs.interval import Interval
File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject
I have been looking all over the internet and tried doing everything anyone suggested but it persists. I uninstalled and reinstalled it using sudo pip3 install pandas. Pandas right now is v1.3.4. Tried upgrading it, the prompt said "Requirement already satisfied, skipping upgrade". I am facing a similar issue with installation and importation of trackpy library too but let's just focus on pandas for now. Didn't want to go for Conda as that is huge and I have limited space (this is a RPi I'm working with).
I am trying to get numpy<1.19.0 and ConfigSpace==0.4.16 to work in a python==3.7 conda environment. The installed version of numpy is 1.18.5.
I am getting the following error:
Traceback (most recent call last):
File "/home/user/.conda/envs/deephyper/bin/deephyper", line 5, in <module>
from deephyper.core.cli import main
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/core/cli/__init__.py", line 1, in <module>
from deephyper.core.cli.cli import main
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/core/cli/cli.py", line 9, in <module>
from deephyper.core.cli import hps, nas, balsam_submit
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/core/cli/hps.py", line 6, in <module>
from deephyper.search.util import load_attr_from
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/search/__init__.py", line 6, in <module>
from deephyper.search.search import Search
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/search/search.py", line 8, in <module>
from deephyper.evaluator.evaluate import Evaluator
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/evaluator/__init__.py", line 5, in <module>
from deephyper.evaluator.evaluate import Encoder
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/deephyper/evaluator/evaluate.py", line 15, in <module>
import skopt
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/__init__.py", line 45, in <module>
from . import callbacks
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/callbacks.py", line 17, in <module>
from skopt.utils import dump
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/utils.py", line 19, in <module>
from .sampler import Sobol, Lhs, Hammersly, Halton, Grid
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/sampler/__init__.py", line 4, in <module>
from .lhs import Lhs
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/sampler/lhs.py", line 9, in <module>
from ..space import Space, Categorical
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/space/__init__.py", line 5, in <module>
from .space import *
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/skopt/space/space.py", line 27, in <module>
import ConfigSpace as CS
File "/home/user/.conda/envs/deephyper/lib/python3.7/site-packages/ConfigSpace/__init__.py", line 37, in <module>
from ConfigSpace.configuration_space import Configuration, \
File "ConfigSpace/configuration_space.pyx", line 39, in init ConfigSpace.configuration_space
File "ConfigSpace/hyperparameters.pyx", line 1, in init ConfigSpace.hyperparameters
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
I tried suggested solutions suggested in other similar questions such as trying other versions of numpy or removing all numpy installations and reinstalling numpy and ConfigSpace with pip options --no-cache-dir --no-binary, but the error persists.
Are there other potential solutions that I could try?
I got some additional insight into the issue by consulting this GitHub issue page. As it turns out, if the size from the PyObject is smaller than the size from the C header, an upgrade of the package referenced by the error (here numpy) is necessary to resolve the error, and vice versa.
I was able to resolve the issue by upgrading numpy to version 1.20.0, even though the requirement was numpy<1.19.0.
Sharing this in case it helps others: I was trying to get fairseq to work and ran into the same issue of ValueError with binary incompatibility as possible reason and Jake's suggestion of updating numpy to 1.20.0 helped solve the problem even through requirements specifically asked for numpy<1.19.0.
I ran into the same problem: ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject and this solution worked for me. Specifically, using Dockerfile to create an image, I install flair==0.8.0.post1, which requires numpy<1.19.0. But after installing flair==0.8.0.post1 I install numpy==1.20.0 and this has avoided the problem. This section of the Dockerfile is:
RUN pip install flair==0.8.0.post1
RUN pip install numpy==1.20.0
While trying to import sklearn, i come across the following error message :
AttributeError: module 'numpy' has no attribute '__config__'
I did install and updated both numpy and sklearn with conda but still get the same error. Any ideas?
import sklearn
Get error message:
Traceback (most recent call last):
File "<ipython-input-35-b7c74cbf5af0>", line 1, in <module>
import sklearn
File "C:\Users\sound\Documents\Conda\lib\site-packages\sklearn\__init__.py", line 82, in <module>
from .base import clone
File "C:\Users\sound\Documents\Conda\lib\site-packages\sklearn\base.py", line 20, in <module>
from .utils import _IS_32BIT
File "C:\Users\sound\Documents\Conda\lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
from scipy.sparse import issparse
File "C:\Users\sound\Documents\Conda\lib\site-packages\scipy\sparse\__init__.py", line 229, in <module>
from .base import *
File "C:\Users\sound\Documents\Conda\lib\site-packages\scipy\sparse\base.py", line 7, in <module>
from scipy._lib._numpy_compat import broadcast_to
File "C:\Users\sound\Documents\Conda\lib\site-packages\scipy\_lib\_numpy_compat.py", line 16, in <module>
_assert_warns = np.testing.assert_warns
File "C:\Users\sound\Documents\Conda\lib\site-packages\numpy\__init__.py", line 213, in __getattr__
import numpy.testing as testing
File "C:\Users\sound\Documents\Conda\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
from ._private.utils import *
File "C:\Users\sound\Documents\Conda\lib\site-packages\numpy\testing\_private\utils.py", line 57, in <module>
HAS_LAPACK64 = hasattr(numpy.__config__, 'lapack_ilp64_opt_info')
File "C:\Users\sound\Documents\Conda\lib\site-packages\numpy\__init__.py", line 220, in __getattr__
"{!r}".format(__name__, attr))
AttributeError: module 'numpy' has no attribute '__config__'
---
I had the exact same problem using the binary numpy 1.18.1 package from piwheels on my RasperryPi 4. Do you also happen to try to use this on a Raspberry Pi?
If yes, then:
It works after uninstalling numpy and then retrieving numpy 1.18.1 from pypi instead of from piwheels (had to compile from source though - it takes roughly 15 minutes).
There seems to be something wrong with the piwheels package - I don't know what it is.
The following two commands should solve your problem:
pip3 uninstall numpy
pip3 install numpy==1.18.1 --no-binary :all:
The first command uninstalls your numpy package. The second one retrieves numpy version 1.18.1 where the switch --no-binary :all: tells pip to not get any binary packages, i.e. from piwheels, but instead compile from source.
I'm going to preface this by saying that I'm relatively new to Python and so please forgive me if I have difficulty understanding something.
I've recently been trying to install OpenCV on my computer following the "Installing OpenCV from prebuilt binaries" instructions found here:
http://docs.opencv.org/3.1.0/d5/de5/tutorial_py_setup_in_windows.html#gsc.tab=0
I initially tried to install OpenCV by itself, as I already had Python 3.5 and a working version of numpy. However, my attempts to import cv2 failed, and I eventually decided to uninstall Python and follow all the steps listed on the website. However, I now have this error when I try import numpy:
Traceback (most recent call last):
File "C:/PythonProgramming/SLIC/src/SLICAlgorithm.py", line 1, in <module>
import numpy
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 180, in <module>
from . import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 20, in <module>
import function_base
File "C:\Python27\lib\site-packages\numpy\core\function_base.py", line 6, in <module>
from .numeric import result_type, NaN, shares_memory, MAY_SHARE_BOUNDS, TooHardError
ImportError: cannot import name shares_memory
Process finished with exit code 1
Other people online seem to have no problem with these instructions, or at least not with numpy. What does this error mean, and what can I do to fix it? I have a 64-bit version of Windows 10 and am working in PyCharm. All help you can provide would be much appreciated.
same problem, the following fix worked for me
pip install -I numpy --force-reinstall
I got "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal when compiling Sci-kit learning. I've upgraded all packages(numpy, scikit to the latest), nothing works.Python version is 2.7. Please help. Appreciate!
checking for nltk
Traceback (most recent call last):
File "startup.py", line 6, in <module>
import nltk
File "/Library/Python/2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import *
File "/Library/Python/2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI
File "/Library/Python/2.7/site-packages/nltk/chunk/api.py", line 13, in <module>
from nltk.parse import ParserI
File "/Library/Python/2.7/site-packages/nltk/parse/__init__.py", line 79, in <module>
from nltk.parse.transitionparser import TransitionParser
File "/Library/Python/2.7/site-packages/nltk/parse/transitionparser.py", line 21, in <module>
from sklearn.datasets import load_svmlight_file
File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 155, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:5029)
ValueError: numpy.dtype has the wrong size, try recompiling
The error "numpy.dtype has the wrong size, try recompiling" means that sklearn was compiled against a numpy more recent than the numpy version sklearn is now trying to import. To fix this, you need to make sure that sklearn is compiled against the version of numpy that it is now importing, or an earlier version. See ValueError: numpy.dtype has the wrong size, try recompiling for a detailed explanation.
I guess from your paths that you are using the OSX system Python (the one that ships with OSX, at /usr/bin/python). Apple has modified this Python in a way that makes it pick up its own version of numpy rather than any version that you install with pip etc - see https://github.com/MacPython/wiki/wiki/Which-Python#system-python-and-extra-python-packages . I strongly recommend you switch to Python.org or homebrew Python to make it easier to work with packages depending on numpy.
The problem occurs when you are using incompatible versions. Check the versions using:
pip freeze
or, for a specific module
pip freeze | grep Module_Name
I fix my problem by updating all packages:
pip install -U scikit-learn numpy scipy pandas matplotlib
As of Today(30/11/2016). These versions are compatible:
matplotlib==1.5.2
nltk==3.2.1
numpy==1.11.2
pandas==0.19.1
scikit-learn==0.18.1
scipy==0.18.1
textblob==0.11.1