Installing numpy Lion with Python 2.7? - python

I am working on a OS X 10.7 with Python 2.7 from python.org and XCode 4.2.
Following these instructions, I tried changing the CC, CXX,
and FFLAGS variables and install with sudo pip install numpy.
However, the installation still looks for gcc-4.2.
I tried
installing gcc-4.2 through MacPorts but get that Error: gcc42
does not build on Snow Leopard or later.
When I install numpy from the precompiled binary on sourceforge, I get the following error:
import numpy
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 137, in
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 4, in
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 5, in
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper
Any help?

If I recall correctly the precompiled binary on source forge is 32-bit. It took me ages to get Numpy, Scipy, and Matplotlib set up on my macbook, it's definitely much harder than it should be.
I believe that your best option is the Scipy superpack. Before using the superpack you need to update to Xcode 4.3.2
So I just installed python 2.7.2 from python.org, grabbed the superpack, and now have numpy working on my machine. After installing python 2.7.2, I did sudo pip uninstall numpy, which didn't remove enough. So I cd'd into /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ and moved both the numpy directory and the numpy egg to "old" versions of themselves. Then I ran sh install_superpack.sh and answered no to the "are you installing from a repository cloned to this machine(pretty important lol, hit yes without thinking the first time).
However, now I'm able to do this:
$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> import matplotlib
With no problems :)

SuperPack worked for me (thanks, #Nolen) on OS X 10.8 (Mountain Lion) w/ XCode 4.5.1 installed.
Numpy worked for me using pip install numpy after step #1 below. But scipy would not install using pip. SuperPack fixed this.
The only thing I did differently was to use HomeBrew to install Python as step #1, rather than download it manually.
Install Python (separate from version that comes with OS X 10.8)
brew install python --framework --universal
pushd /System/Library/Frameworks/Python.framework/Versions
sudo rm Current
sudo ln -s /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current
popd
Install SuperPack:
curl -o install_superpack.sh https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh
sh install_superpack.sh
(type your admin password several times during the installation...)

Related

matplotlib works with default python but not python3.5 on debian

I have this issue. I think it's best described when I show you my bash commands that I used to produce the problem. See here:
josch#oogway:~$ python
Python 2.7.9 (default, Jun 29 2016, 13:08:31)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> #works
josch#oogway:~$ python3.5
Python 3.5.0 (default, Apr 26 2017, 21:03:53)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'matplotlib'
>>> #what??
Matplotlib was installed by:
sudo apt-get install python-matplotlib
The "default" python came with my OS installation, python3.5 was downloaded and then compiled/installed from source.
Can anyone help? Tried to solve it myselve for 2 hours now but google can't find answer
Edit: I'm trying to install a "second pip" that works with my second installation of Python, which is Python3.5. My default-Python that is managed by the OS is Python 2.7.9. Now, as suggested I did:
joschua#oogway:~/Downloads$ wget https://bootstrap.pypa.io/get-pip.py
and then:
python3.5 get-pip.py
which gave me:
joschua#oogway:~/Downloads$ python3.5 get-pip.py
Traceback (most recent call last):
File "get-pip.py", line 20061, in <module>
main()
File "get-pip.py", line 194, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
import pip
zipimport.ZipImportError: can't decompress data; zlib not available
Try installing pip3 with:
sudo apt-get install python3-pip
and then try installing matplotlib with:
sudo pip3 install matplotlib
I actually could solve the problem now.
See this link for a reasonable description on how to run two different versions of python on the same system (and as #Pierre de Buyl suggested) use two different pip versions on the same system
https://www.linkedin.com/pulse/20140815081557-89781742-how-to-install-and-use-python-with-different-versions-on-same-linux-machine
So, you installed python3.5 from source. What version of Debian are you using? (I suppose Jessie).
If you want to install packages for this Python interpreter, you must have a pip that actually uses it. Two solutions:
It is installed. If so,
python3.5 -m pip
will work and you can install packages with
python3.5 -m pip install matplotlib
or
python3.5 -m pip install --user matplotlib
It is not installed. You must install it following the instructions at https://packaging.python.org/installing/#requirements-for-installing-packages
apt-get will not install the appropriate pip for your needs. It will only install a pip that is related to the python3 (3.4 for jessie I believe) that is also in the apt-get system.
EDIT: in light of the update, you need also to re-compile python3.5 with zip enabled.

Brew not installing pygtk properly

First let me start by giving an example of what happens when I install numpy using HomeBrew
brew install numpy
This successfully dowloads and pours. And now when I try to import in python it works properly.
>>>import numpy
>>>
Now I try to install pygtk through HomeBrew using
brew install pygtk
It successfully Downloads and pours. But when I import it in python I get
>>>import pygtk
Import Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygtk
>>>
Now I went and checked my /usr/local/lib/python2.7/site-packages/
numpy exists but pygtk does not. But pygtk exists in /usr/local/lib/
Why is brew doing this? Also am I getting something fundamentally wrong here?
Now I really don't know what to do exactly but I don't think copying pygtk from /usr/local/lib/ to /usr/local/lib/python2.7/site-packages/
Note: I am using MAC OS and I mainly work through the terminal and would prefer a solution through terminal itself.
Edit1: I have found a solution or rather a workaround.
Basically I am downloading the latest PyGTK.pkg and then installing it. And then copying all the files in the system default python to my python2.7
wget -P /Users/mac_test/Downloads/ https://sourceforge.net/projects/macpkg/files/PyGTK/2.24.0/PyGTK.pkg
installer -pkg /Users/mac_test/Downloads/PyGTK.pkg -target /
cp -r /opt/gtk/lib/python2.7/site-packages/ /usr/local/lib/python2.7/site-packages/
Not sure this is the best way though.
How it worked for me:
First of all I have python installed via brew:
which python && python --version
/usr/local/bin/python
Python 2.7.13
Then I installed pygtk through brew install pygtk and it was successful
After that:
python
Python 2.7.13 (default, Dec 18 2016, 07:03:39)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygtk
>>> help(pygtk)
It responds with this:
Help on module pygtk:
NAME
pygtk
FILE
/usr/local/lib/python2.7/site-packages/pygtk.py
So probably copy pygtk to site-packages might solve your issue.
I don't know specific reason you prefer brew over pip + virtualenv but I gently recommend you to try it instead of brew and global library installation.

I can't find python package fftw3

I'm trying to use fftw3 on python to compute ffts really fast (using all my cores!)
The problem is... I can't find the fftw3 package for python...
I know it exists because the function I need uses it if and only if it's installed.
This is the module that I use: https://github.com/keflavich/image_tools/blob/master/fft_psd_tools/convolve_nd.py
And as expected this is what I get if I try to import it:
>>> import fftw3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fftw3
>>>
And I've tried this:
sudo pip install fftw3
sudo apt-get install python-fftw3
sudo easy_install fftw3
And I have also tried googling for its location, or installation instructions, with nothing to be found!
I am also aware that fftw is a C library and that pyfftw exists as python wrappers for that package, but the function I use utilizes fftw3.
I am hoping someone could point me to where this module is located!
P.S. I am running Ubuntu 14.04 and I'm using python 2.7. I also tried importing it in python 3 but it's not there either.
Looks like the problem was with the package you were trying to pip. I had no errors with sudo pip install pyfftw3 then import fftw3
will#will-mint2 ~ $ sudo pip install pyfftw3
[sudo] password for will:
Downloading/unpacking pyfftw3
Downloading PyFFTW3-0.2.1.tar.gz
...
Successfully installed pyfftw3
Cleaning up...
will#will-mint2 ~ $ python
Python 2.7.9 (default, Mar 1 2015, 12:57:24)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fftw3
>>> exit()
For windows
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyfftw
install it by:
pip install [filename].whl
import in your code by
import pyfftw as fftw

'pip3 --version' failing with a SyntaxError

This all began when I set out to install the Requests library for Python 3 (I'm running on OSX Mavericks with Python 2.7.5 (installed by brew install python) and 3.4.2 (installed by brew install python3). When I run pip3 --version (or anything related to the pip3 command) I see this:
$ pip3 --version
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
File "/usr/local/lib/python3.4/site-packages/pip/__init__.py", line 11, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "/usr/local/lib/python3.4/site-packages/pip/vcs/mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "/usr/local/lib/python3.4/site-packages/pip/download.py", line 22, in <module>
from pip._vendor import requests, six
File "/usr/local/lib/python3.4/site-packages/pip/_vendor/requests/__init__.py", line 53, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/usr/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 49, in <module>
from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/ndg/httpsclient/ssl_peer_verification.py", line 17
except ImportError, e:
^
SyntaxError: invalid syntax
When I run the Python 2.7.5 version I see this:
$ pip --version
pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
Just for sanity purposes Here is what when I see when I enter the interactive interpreters:
$ python3
Python 3.4.2 (default, Oct 19 2014, 17:52:17)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ 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.
>>> exit()
A lot of the other answers related to updating pip3 suggest that I update pip3 with this commend pip3 install --upgrade pip which gives the same error, or I use easy_install -U pip but because of how brew sets up the Pythons, it only updates the Python 2.7.5 version (there is no easy_install3). Any ideas?
The root problem is that you somehow got a Python 2.x-only package installed into your 3.x site-packages.
Underlying that, you've actually got two different Python 2.7 installations (Apple's and Homebrew's) crossed with each other, which may have something to do with how you got a 2.7 package into 3.x as well…
Anyway, the reason this is breaking pip is that pip has various optional dependencies that it tries to import if present, and some of them do the same, and so on, and ultimately, starting up pip is importing the ndg-httpsclient package.
I'm not sure how you got that package. A standard Homebrew 3.x looks in two extra site-packages directories (fire up python3 then import sys; print(sys.path) to see all of the places it looks, both stdlib and site) beyond the one that pip3 installs into.
In this case, you've somehow installed the 2.x version of ndg-httpsclient into /usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/‌​python3.4/site-packages.
Since you didn't install it with pip—and, more to the point, since you can't run pip in the first place—you can't just pip uninstall it. So:
rm -rf /usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/‌​python3.4/site-packages/ndg*
This could break some other packages that depend on it. Once you get things working, you can use pip3 list to see all the site packages you've installed and test them out. If you want to be paranoid, do something like this:
$ pip3 list > mypackages
$ rm -rf <each site-package directory>
$ brew uninstall python3
$ brew install python3
$ pip3 install -r mypackages
You might want to similarly clean up your Homebrew 2.7 (or just scrap it and only use Apple's—especially since I'm pretty sure you're running Apple's anyway), and the site-packages for the Apple 2.7 (but not Apple's Python itself, of course, because you can't uninstall that).

How to Fix the Broken BSDDB Install in the Default Python Package on Mac OS X 10.5 Leopard?

Do the following on the default Python install on Mac OS X 10.5 (Leopard) w/ Developer Tools:
noel ~ : python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/bsddb/__init__.py", line 51, in <module>
import _bsddb
ImportError: No module named _bsddb
nice, huh? How do I fix this without giving up and installing/configuring/maintaining my own Python package as per TMNC's suggestion or using MacPorts etc?
Edit
I've gone around the problem by installing Python2.4 and BSDDB via MacPorts.
My question still stands: why is the default install broken and is it possible to fix it.
Follow the instructions at http://marc-abramowitz.com/archives/2007/11/28/hacking-os-xs-python-dbhash-and-bsddb-modules-to-work/ .
The patch did not work for me and I had to replace the bsddb folder in
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
with the bsddb3 in:
/usr/local/lib/python2.7/site-packages/bsddb3
Make sure you backup the bsddb folder just in case.
This pain persists on OSX 10.8. I could not install bsddb3 using macports py-bsddb3 into a virtualenv. What was very simple and did work is:
install db53 from macports
download and unpack bsddb3 source (https://pypi.python.org/pypi/bsddb3/6.1.0)
sudo python setup.py –berkeley-db-incdir=/opt/local/include/db53 –berkeley-db-libdir=/opt/local/lib/db53 install
A solution I found was to install ActivePython, dig into its library (located in /Library/Frameworks/Python.framework/Versions/....your version here..../lib) and copy and paste the _bsddb.so file into my OS X 10.6 native python 2.6 install directory (/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/).
That fixed the missing _bsddb issue leaving me with a working version of bsddb in my native python install. Then, I just uninstalled ActivePython (instructions here)
The error I had was "No module named _bsddb". It turn out I didn't need to upgrade my bsddb. I wasusing the .pkl file created in windows. After renaming the pkl file to get it out the way Mac OSX Python recreated a new .pkl.db file and now it works perfectly.

Categories