Trying to install numpy 1.7 - python

I am currently using Python 2.7 and Numpy 1.6.2. I want to use the numpy.polyfit() function with the weights parameter. However, it seems that the weights parameter is not available in numpy 1.6.2. The Sourceforge download link shows 1.6.2 as being the latest version. I have found the updated polynomial.py file which includes the weights parameter for the polyfit() function. I simply replaced my current polynomial.py with the updated one on the website. However, when I try to run my Python program, I get the error:
Traceback (most recent call last):
File "C:\Python27\first.py", line 13, in <module>
import matplotlib
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 133, in <module>
from matplotlib.rcsetup import (defaultParams,
File "C:\Python27\lib\site-packages\matplotlib\rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "C:\Python27\lib\site-packages\matplotlib\colors.py", line 52, in <module>
import numpy as np
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 153, in <module>
import polynomial
File "C:\Python27\lib\site-packages\numpy\polynomial\__init__.py", line 18, in <module>
from polynomial import Polynomial
ImportError: cannot import name Polynomial
first.py is simply the file with all my code I'm trying to run
What am I doing wrong? Is there another way to simply get the newest version of Numpy (1.7?) ?
Thank you for your help!

There are two files called polynomial.py in NumPy; lib/polynomial.py and polynomial/polynomial.py. You've replaced the wrong one.
I'm not aware of any development builds of 1.7.x for Windows; if you're comfortable with building packages yourself then you can download the source using git and build it per instructions from https://github.com/numpy/numpy/blob/master/doc/HOWTO_RELEASE.rst.txt and linked resources.

Related

C++ - Python Embedding with numpy

I would like to call a python function from C++ and get the return value. I've been able to do that with an easy multiply python function using this website's example code in section 5.3. To compile my program, I would run g++ test.cpp -I/usr/include/python2.7 -lpython2.7. However, the python function I want to run imports numpy. When I try to run my program that is similar to the one on the code example mentioned above, I get an "ImportError: cannot import name _remove_dead_weakref". The full error is here:
Traceback (most recent call last):
File "/home/osboxes/Desktop/test.py", line 1, in <module>
import numpy as np
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/core/__init__.py", line 74, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/home/osboxes/miniconda2/lib/python2.7/unittest/__init__.py", line 64, in <module>
from .main import TestProgram, main
File "/home/osboxes/miniconda2/lib/python2.7/unittest/main.py", line 7, in <module>
from . import loader, runner
File "/home/osboxes/miniconda2/lib/python2.7/unittest/runner.py", line 7, in <module>
from .signals import registerResult
File "/home/osboxes/miniconda2/lib/python2.7/unittest/signals.py", line 2, in <module>
import weakref
File "/home/osboxes/miniconda2/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref
Some information: Python version is Python 2.7.14 :: Anaconda, Inc. (Is there a difference between python 2.7.14 and my version which has anaconda, inc. at the end?) The python program also runs just fine by itself. Any help would be appreciated. Thanks!
Edit: The path was being all weird with some parts going to my local python and numpy going to miniconda's python. Uninstalling miniconda as it wasn't needed for me fixed it.
This is happening because your environment is mixing two different Python installations. You can see it jump between them here:
File "/home/osboxes/.local/lib/python2.7/site-packages/numpy/testing/__init__.py"
File "/home/osboxes/miniconda2/lib/python2.7/unittest/__init__.py"
So you start out in /home/osboxes/.local/lib/python2.7/site-packages which is the Python installed by some system package manager (or perhaps even explicitly installed from source). But then it jumps to /home/osboxes/miniconda2/lib/python2.7 which is from Conda.
Since it appears you are intending to use Python from Conda, you need to install NumPy using Conda (so it is loaded from miniconda2 and not .local, and build your code using something like -I/home/osboxes/miniconda2/include/python2.7 instead of -I/usr/include/python2.7.

Numpy - ImportError: cannot import name shares_memory

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

sklearn "numpy.dtype has the wrong size, try recompiling" in both pycharm and terminal

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

Running python script with dependencies on libraries from a virtualenv

I'm trying to run a naive bayes script that needs NumPy, SciPy and Pandas to run. To avoid the confusion with the multiple copies of python on Macs 10.7 --and because I couldn't figure out how to, really - I made a virtualenv and installed NumPy and SciPy there, checking that after running
$ python
>>> import numpy
>>> import scipy
everything works. Now, I'm in my file's directory, and running python nb_predict.py gives me a bunch of errors.
Originally, the path to my python compiler at the top of my file was
#!/usr/local/bin/python
but since I didn't know if it had changed after installing everything in the virtual env, I've tried it with:
#!/Users/myusername/.virtualenvs/scipy/bin/python
and it still doesn't work. I've made the script executable, also.
Please, any help would be greatly appreciated!
This is what I get as the error:
Traceback (most recent call last):
File "nb_predict.py", line 3, in <module>
from sklearn.naive_bayes import MultinomialNB
File "/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scikit_learn-0.15_git-py2.7-macosx-10.9-intel.egg/sklearn/naive_bayes.py", line 25, in <module>
from .preprocessing import binarize
File "/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scikit_learn-0.15_git-py2.7-macosx-10.9-intel.egg/sklearn/preprocessing/__init__.py", line 22, in <module>
from .imputation import Imputer
File "/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scikit_learn-0.15_git-py2.7-macosx-10.9-intel.egg/sklearn/preprocessing/imputation.py", line 10, in <module>
from scipy import stats
File "/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scipy-0.14.0.dev_572aaf0-py2.7-macosx-10.9-intel.egg/scipy/stats/__init__.py", line 332, in <module> from .stats import *
File "/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scipy-0.14.0.dev_572aaf0-py2.7-macosx-10.9-intel.egg/scipy/stats/stats.py", line 181, in <module>
import scipy.special as special
File "/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scipy-0.14.0.dev_572aaf0-py2.7-macosx-10.9-intel.egg/scipy/special/__init__.py", line 532, in <module>
from ._ufuncs import *
ImportError: dlopen(/Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scipy-0.14.0.dev_572aaf0-py2.7-macosx-10.9-intel.egg/scipy/special/_ufuncs.so, 2): Symbol not found: ___sincos_stret
Referenced from: /Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scipy-0.14.0.dev_572aaf0-py2.7-macosx-10.9-intel.egg/scipy/special/_ufuncs.so
Expected in: /usr/lib/libSystem.B.dylib
in /Users/myusername/.virtualenvs/scipy/lib/python2.7/site-packages/scipy-0.14.0.dev_572aaf0-py2.7-macosx-10.9-intel.egg/scipy/special/_ufuncs.so

Error when calling scikit-learn using AMD64 build of Scipy on Windows

I am getting this error on this line:
from sklearn.ensemble import RandomForestClassifier
The error log is:
Traceback (most recent call last):
File "C:\workspace\KaggleDigits\KaggleDigits.py", line 5, in <module>
from sklearn.ensemble import RandomForestClassifier
File "C:\Python27\lib\site-packages\sklearn\ensemble\__init__.py", line 7, in <module>
from .forest import RandomForestClassifier
File "C:\Python27\lib\site-packages\sklearn\ensemble\forest.py", line 47, in <module>
from ..feature_selection.selector_mixin import SelectorMixin
File "C:\Python27\lib\site-packages\sklearn\feature_selection\__init__.py", line 7, in <module>
from .univariate_selection import chi2
File "C:\Python27\lib\site-packages\sklearn\feature_selection\univariate_selection.py", line 13, in <module>
from scipy import stats
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 320, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 241, in <module>
import scipy.special as special
File "C:\Python27\lib\site-packages\scipy\special\__init__.py", line 529, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
After installing:
Python 2.7.4 for Windows x86-64
scipy-0.12.0.win-amd64-py2.7.‌exe (from here)
numpy-unoptimized-1.7.1.win-amd64-py2.7.‌exe (from here)
scikit-learn-0.13.1.win-amd64-py2.7.‌exe (from here)
Anybody know why this is happening and how to solve it ?
As Christoph Gohlke mentioned on his download page, the scikit-learn downloadable from his website requires Numpy-MKL. Therefore I made a mistake by using Numpy-Unoptimized.
The link to his Numpy-MKL is statically linked to the Intel's MKL and therefore you do not need any additional download (no need to download Intel's MKL).
This is a little late, but for those like me, download these from the official
Microsoft website.
After that restart your interpreter/console and it should work.
This problem happened to me when I use scipy 0.12. After I changed to scipy 0.11, the problem was gone.

Categories

Resources