0

I started to use a Mac after someone and I encountered problems with Numpy/Matplotlib version. It turned out that there are several Python installations there and things from different installations are imported (which don't work together). I have:

1) /opt/local/ - installed via MacPorts

2) /Library/Frameworks/Python.framework - installed by hand

3) /System/Library/Frameworks/Python.framework/Versions/2.7/ - I have no idea where does it come from.

I checked:

pkgutil --pkgs

to find out:

org.pythonmac.matplotlib-platlib-py2.7-macosx10.6
org.pythonmac.numpy-platlib-py2.7-macosx10.5
org.pythonmac.numpy-scripts-py2.7-macosx10.5
org.pythonmac.scipy-platlib-py2.7-macosx10.5

so, I suppose this is where this not working numpy comes from. I have no idea how to remove this stuff and if it will not break OS X system / some package manager deps, etc. I could leave these files in place and just use "my" numpy, but unfortunately their location is one of the first in PYTHONPATH, so always numpy from /System/Library gets imported and doesn't work with Matplotlib from MacPorts.

To sum up, here are my questions: 1) is it safe and how to remove these packages from OS X ? 2) how is PYTHONPATH set on OS X, where can I manipulate it (in order to remove some entries and force "my" Numpy being imported, instead of old system one)?

This is Mac OS X 10.7.5

Maciek
  • 762
  • 6
  • 17

2 Answers2

0

I can't flag this as a duplicate because I don't have enough rep, but I found a possible answer here: How to uninstall Python 2.7 on a Mac OS X 10.6.4?

As myildirim suggested, try checking out virtualenv, with virtualenvwrapper to isolate all your installations in the future! Both keep your system sanitized and neatly organized.

As for the second half of your question, a quick google search shows that your path can be shown in .profile on your system's path. Inside .profile is the python path that you're looking for. [source/more information]

If you have any more questions, let me know!

Community
  • 1
  • 1
Cameron
  • 127
  • 10
0

This was stolen from my teachers website, this could be a helpful guide to setting of Python and numpy correctly on a Mac

The combination of Python, NumPy (Numerical Python), SciPy (Scientific Python), and OpenCV provides you with a free, open source programming environment that is ideal for imaging-related applications. You will have access to a huge collection of community-developed codes for linear algebra, matrix algebra, linear mathematics, computer vision, and image processing. You will also have access to an up-to-date collection of image acquisition routines for both still and video digital cameras. Rounded out by a full suite of input/output routines for a myriad of image and video file formats, this environment will provide you with a rich development and research capability.

You will need to have Apple's XCode installed on your computer.

If you are running Mac OS X 10.7 (Lion) or later (Mountain Lion), the latest version of XCode can be downloaded from the App Store. This is a large download (approximately 4GB) so you may want to connect your machine to the wired network during installation.

If you are running Mac OS X 10.6.8 (Snow Leopard), you will need to download XCode 3.2.6 from the Apple Developer site. You need to be signed up to the free Apple Developer program in order for this to work, and note, that this is an end-of-life product that will no longer receive updates. If possible, you should consider upgrading to the most recent version of Mac OS X.

Once XCode is installed, you will want to download and install the command line tools. Start XCode and go to

XCode > Preferences... > Downloads and install the "Command Line Tools".

You will now need to install MacPorts on your system. The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11, or Aqua-based open-source software on the Mac OS X operating system.

Now you are ready to install Python and the various modules mentioned above. Open up a terminal window

Applications > Utilities > Terminal and issue the following commands (be very careful what you type, executing these commands with sudo means you are operating as the root user on your machine, and as such, you could do some real damage if you issue an incorrect command):

$ sudo port selfupdate
$ sudo port install python27
$ sudo port install py27-tkinter
$ sudo port install py27-numpy
$ sudo port install py27-scipy
$ sudo port install qt4-mac
$ sudo port install opencv +python27+eigen+qt4+tbb+dc1394
$ sudo port install py27-matplotlib
$ sudo port select --set python python27

expected. The default shell on your Mac "out of the box", as in most modern Unix operating systems, is bash. Your default environment is controlled by a couple of resource files, located in your home directory, that get executed upon startup of the shell; these are .bash_profile and .bashrc. Using your favorite text editor, create or modify these files making sure that they minimally contain the following (note that these are "hidden" files and are most easily accessed from the command line):

.bash_profile

if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

.bashrc

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

if [ -x /usr/libexec/path_helper ]; then
    export PATH=""
    export MANPATH=""
    eval `/usr/libexec/path_helper -s`
fi
export PATH=/opt/local/bin:$PATH
export MANPATH=$MANPATH:/opt/local/man

export PYTHONPATH=<path-to-your-python-modules>

The indicated on the last line should indicate the location of any personally developed Python modules that you have written or will write that you would like to be available to all the codes you write on your machine, regardless of the location that you develop them in. For example, you might create a directory in your home directory by typing

cd
mkdir src/python/modules

where you intend to store all of your personal Python modules. Your PYTHONPATH envrionment variable in the .bashrc file should then be

export PYTHONPATH=$HOME/src/python/modules

Now to see if it works

$ python

>>> import numpy
>>> import scipy
>>> import cv2
>>> numpy.__version__
>>> scipy.__version__
>>> cv2.__version__
Maggick
  • 763
  • 2
  • 10
  • 26