I'm trying to run a script of mine using Python 2.7. When I run
python2.7
I get
Python 2.7.10 (default, May 25 2015, 13:06:17)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
When I try to run my script, I get:
Traceback (most recent call last):
File "bcp.py", line 1, in <module>
import numpy as np
ImportError: No module named numpy
So Python 2.7 doesn't seem to know about numpy. When I run
pip2.7 install numpy
I get:
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Cleaning up...
Any idea what's going on here?
Thanks!
This might be because you're using the wrong python distro on your computer. If you are using an OSX machine, there might be a python distribution in /usr/local/ and one in /System/Library/Frameworks. It seems like python2.7 might be linked to the one in /usr/.
Try
which python2.7
should locate which python distro "python2.7" is symlinked to. If you're symlinked to /usr/, just change it to the one in /System/Library and your numpy should work.
Related
To confirm results of a colleague who has coded an interpolation with Cubicspline from scipy with python2 , I have to import CubicSpline function. I know python2 is deprecated but this is just for a validation.
But when i do a :
from scipy.interpolate import CubicSpline
I have systematically the error message :
ImportError: cannot import name CubicSpline
So, I tried to install it with pip-2.7 by doing :
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
python2.7 get-pip.py
and after from the directory ~/Library/Python/2.7/bin :
./pip2.7 install scipy
but same error, CubicSpline is not found
I have the version :
$ which python2.7
/usr/bin/python2.7
So python2.7 is the default python2 of the system.
How to install CubicSpline library on the default installation of python2.7 in the OS ?
Have I got to reinstall all the python2.7 framework ? and if yes, how to perform it ?
Update 1
The situation has become worse :
After doing $ python2.7 -m pip install scipy numpy I get now :
$ python2.7
Python 2.7.16 (v2.7.16:413a49145e, Mar 2 2019, 14:32:10)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
Traceback (most recent call last):
File "/Users/fab/.startup.py", line 3, in <module>
import numpy as np
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 71, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_multiarray_umath.so, 2): Symbol not found: ___addtf3
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib
Finally, I decided to use Macport, but there is yet a problem when I do :
$ /opt/local/bin/python2.7
Original error was: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_multiarray_umath.so, 2): Symbol not found: ___addtf3
Referenced from: /opt/local/lib/libgcc/libquadmath.0.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /opt/local/lib/libgcc/libquadmath.0.dylib
On Big Sur, I saw that file libSystem.B.dylib didn't exist anymore.
How to circumvent all these issues ?
Update 2
Things are better but not all is done.
I removed python2.7 from MacPorts and useless binaries of kind python2* located into /usr/local/bin/.
Now, I have only the binary python2.7 coming from /usr/bin/python2.7 :
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Feb 28 2021, 12:34:25)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> from scipy.interpolate import CubicSpline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name CubicSpline
>>>
As you can see, numpy and scipy are well loaded but there is still this problem with this line : from scipy.interpolate import CubicSpline
I would like to know where is located this library CubicSpline. Indeed, Recently, I could make run a "python2.7" code version and there were no problems for the loading and using of this function CubicSpline.
Where are stored numpy and scipy for the OS System version of python2.7
Update 3
I have finally found where the issue comes from. CubicSpline seems to be only available for scipy > 0.18. But on my MacBook, if I do :
$ import scipy
scipy.version.version
I get :
>>> scipy.version.version
'0.13.0b1'
Is there a way to upgrade the scipy of MacOS Big Sur Python 2.7 default system (I mean without using Brew/Macports) ?
Update 4
I don't understand anything, on a similar MacBook Pro with Big Sur 11.3, if I do :
/usr/bin/python2.7
I get :
Python 2.7.16 (default, Feb 28 2021, 12:34:25)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported os)
(imported sys)
(imported glob)
and if look at the version of scipy in the python2.7 shell, I get :
>>> import scipy
>>> scipy.version.version
'1.2.2'
Where are installed the numpy and scipy libraries for the default python 2.7 on Big Sur 11.3 ? : I tried to look for (with sudo grep -riIHn cubicspline) in /System/Library, and ~/Library/, and in /Library/, but found nothing.
wonder if anyone has tried IntelPython with anaconda. i created an environment as in url link
Intel Python
however, when i try to import pytables, i get: -
(intelpython) dc#dcpctw:/opt/anaconda3/bin$ python
Python 3.5.3 |Intel Corporation| (default, Apr 27 2017, 18:08:47)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import tables
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'tables'
Which is strange because i have it running under the non-intel python environment, so i tried checking if pytables was installed under the intelpython environment
(intelpython) dc#dcpctw:/opt/anaconda3/bin$ sudo ./conda upgrade pytables
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /opt/anaconda3:
#
pytables 3.3.0 np112py35_intel_2 [intel] intel
(intelpython) dc#dcpctw:/opt/anaconda3/bin$
So its installed in the environment and should work, any help? thanks
You are running the python executable from /opt/anaconda/bin but you have an activated environment of (intelpython). Change to a different directory, e.g., ~, make sure the first python on your PATH is /opt/anaconda3/envs/intelpython/bin/python, and try the import again.
I use OSX 10.9 + Kivy 1.9.1, but I have two versions of Python, Mac OSX self-contained 2.7.5 and another standalone 2.7.9 installed. Here are the details:
MacBook-Air:wzy$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
MacBook-Air:wzy$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
After having installed twisted with pip install twisted, I get the following error message in kivy with python 2.7.5, which does not happen in python 2.7.9
MacBook-Air:wzy$ kivy
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 53, in <module>
_checkRequirements()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/twisted/__init__.py", line 37, in _checkRequirements
raise ImportError(required + ": no module named zope.interface.")
ImportError: Twisted requires zope.interface 3.6.0 or later: no module named zope.interface.
MacBook-Air:wzy$ python
>>> import twisted
>>> exit()
I have even installed zope.interface several times and dedicate install target directory as one of the sys.path of kivy environment.
I do believe this is two version co-exist related, but how can I fix this?
When you do pip install twisted, you are installing Twisted into some Python environment, depending on which python executable you are invoking pip with. If you have a 2.7.5 environment and a 2.7.9 environment, pip install might be putting Twisted in a different place for each, depending on what other options you passed to pip. (You probably passed some other options to pip install because without privileges, by default, pip install will just fail. Did you do sudo pip install perhaps? Did you do pip install as an admin user into a homebrewed Python?)
The right way to do this is to only ever install Twisted into virtual environments. You can create a virtual environment with the -p option to virtualenv, which tells it which Python to use for that environment. Then, with the correct virtual environment active, you can pip install twisted and everything should work as you expect.
I had the same import error problem, providing another possible solution here:
I have zope.interface 4.4.2 installed, it turned out that my twisted version is too old. By upgrade twisted solved my problem.
pip install --upgrade twisted
Thanks Glyph,
Finally I find following simple command could directly fix this problem, because Kivy use his own virtualenv environment, but I do appreciated your kindly help.
kivy -m pip install twisted
Best Wish to you,
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
I'll admit I'm completely dumbed by python install. Can someone help me on how to install module
I want to play with PyGame, PyOpenGL etc. So I install them, but I everytime I type "import pygame" error message shows up.
here's my environment so far.
In .bash_profile
PATH=${PATH}:/System/Library/Frameworks/Python.framework/Versions/Current/bin
Using easy_install PyOpenGL placed this
/Library/Python/2.5/site-packages/PyOpenGL-3.0.0b8-py2.5.egg
Locating pygame module
dchong:~ danielchong$ locate pygame
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pygame.py
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pygame.pyc
dchong:~ danielchong$ locate pyopengl
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pyopengl.py
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/py2app/recipes/pyopengl.pyc
when I run python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
I'm not a huge fan of the default python install on OS X in the first place, mostly because it's usually a pretty old version. I find everything works better if I use the macports package.
easy_install seems to work better with the macports package, but maybe that's just because I'm too lazy to figure out all the nuances of the default install.
From what I can see there, it looks like the path to the packages isn't set correctly. Are you sure you're using the right site-packages directory?
See http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-2-6-2-5-etc-/