Install Python modules on OSX using easy_install or setup.py

I am running Snow Leapord 10.6 and trying to install the following python modules:

  • Numpy
  • Scipy
  • Matplotlib

I'm having problems because OSX contains two versions of Python:

  • / Library / Python /
  • /System/Library/Frameworks/Python.framework/

It seems like when I execute the following command:

sudo easy_install -U {module} , the modules are installed in the package sites directory here:

 bash-3.2$ ls -al /Library/Python/2.6/site-packages/ total 688 drwxrwxr-x 12 root admin 408 Aug 24 23:26 . drwxrwxr-x 3 root admin 102 Feb 11 2010 .. -rw-rw-r-- 1 root admin 119 Feb 11 2010 README -rw-r--r-- 1 root admin 267 Aug 24 19:03 easy-install.pth drwxr-xr-x 5 root admin 170 Aug 24 10:42 nose-0.11.4-py2.6.egg drwxr-xr-x 38 root admin 1292 Aug 24 15:35 numpy -rw-r--r-- 1 root admin 1618 Aug 24 15:35 numpy-2.0.0.dev8661-py2.6.egg-info drwxr-xr-x 16 root admin 544 Aug 24 19:07 numscons drwxr-xr-x 4 root admin 136 Aug 24 19:03 numscons-0.10.1-py2.6.egg -rw-r--r-- 1 root admin 265 Aug 24 19:07 numscons-0.12.0dev-py2.6.egg-info -rw-r--r-- 1 root admin 333959 Aug 23 11:51 setuptools-0.6c11-py2.6.egg -rw-r--r-- 1 root admin 30 Aug 23 11:51 setuptools.pth 

But, when I try to install scipy, I see the following error:

  config = setup_module.configuration(*args) File "scipy/setup.py", line 20, in configuration config.add_subpackage('special') File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 851, in add_subpackage caller_level = 2) File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 834, in get_subpackage caller_level = caller_level + 1) File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/distutils/misc_util.py", line 766, in _get_configuration_from_setup_py ('.py', 'U', 1)) File "scipy/special/setup.py", line 14, in <module> (numpy.__version__, numpy.__file__)) ValueError: numpy >= 1.4 is required (detected 1.2.1 from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/numpy/__init__.pyc) 

So it looks like it is looking for an older version of numpy in my frameworks directory. I used import to find out which version of numpy python was:

  python -c 'import numpy;print numpy.__version__' 1.2.1 

And, of course, he is looking in the frameworks directory, although I have a new version sitting in:

/Library/Python/2.6/site-packages/

I know that import first looks for your local directory and then goes into PYTHONPATH and then finally looks at sys.path. So I checked them, and I don't have PYTHONPATH right now, and here is my sys.path:

 /Library/Python/2.6/site-packages/setuptools-0.6c11-py2.6.egg /Library/Python/2.6/site-packages/nose-0.11.4-py2.6.egg /Library/Python/2.6/site-packages/numscons-0.10.1-py2.6.egg /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6 /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload /Library/Python/2.6/site-packages /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode 

If I change PYTHONPATH to /Library/Python/2.6/site-packages and then check the numpy version, I get the correct version:

 bash-3.2$ python -c 'import numpy; print numpy.__version__' 2.0.0.dev8661 

But when I run sudo python setup.py build/install , scipy cannot find the number I need, even if PYTHONPATH is installed.

Can anyone help me here?

Found this link, which looks like it fixes my problem, but I can't get it to work:

http://andreasjacobsen.com/2008/10/10/using-python-setuptools-on-the-mac/

+2
source share
6 answers

The solution I came up with is the following.

1) Do not use the version of Python that comes with OSX preinstalled. Apple apparently made some changes to this, and not everything is building. So, you need to install the Python version for development. Right now - I would suggest installing Python 2.7. Here is a blog post on how to do this:

https://medium.com/cs-math/a3eb146ebfb5

2) After installing Python, you need to install the fortran libraries to install Scipy / Numpy. Use homegrown to do this (do people still use MacPorts ???)

http://brew.sh/

3) After you have installed your home brew, install fortran

brew install gfortran

4) Now you can successfully install scipy / numpy with pip (Warning - it takes some time)

pip install -U numpy pip install -U scipy

DONE

0
source

I think the easiest way is to use MacPorts to install scipy. Here's an intro , although you probably want py26-scipy.

+2
source

Have you tried installing using pip ? Also, try installing scitools , which should pull the ones you need.

+2
source

Can you not just temporarily move the old numpy, much less?

 cd /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python sudo mv numpy numpy-1.2.1 # mv back if need be 
0
source

The problem is that the easy_install you invoke is the one that Apple installs with the frameworks in / System, and python with / usr / bin / python

To find out how python is installed, check out the easy_install script and see what #! the line says which python to use.

To get the correct easy_install, you will need to install distibute or setuptools for python in / Library (I would assume that it is python.org with / usr / local / bin / python). Then use this easy_install

I would notice, however, that I use the @boocs solution to use Macports althogh, if only after scipy, etc., and there are no other C libraries, then other solutions will be shown here, also see Enthought

0
source

I had the same problem just at the same time for people with the same problem if you have two pythons on your system (say python2 and python3) and you want to install say numpy for the new version (python3) actions:

1- loading numpy

2-unzip it

3- in the terminal, go to the unpacked folder

4-python3 setup.py install

0
source

Source: https://habr.com/ru/post/1397499/


All Articles