Monday, 28 November 2011

Fix the arrow problem in OS X with the python interpreter

Install the readline package from PyPI to enable arrow and history support in python. Download the egg and install using:

easy_install readline-*.egg

For custom python installations, move the .egg to your site-packages path and add it to your python path by adding the following to your .bash_profile:

PYTHONPATH="/path/to/python/site-packages/readline-6.2.1-py2.7-macosx-10.7-intel.egg:$PYTHONPATH"
export PYTHONPATH

Thursday, 24 November 2011

how to fix "error trying to exec 'f951': execvp: No such file or directory"

error trying to exec 'f951': execvp: No such file or directory
error trying to exec 'cc1': execvp: No such file or directory

I was trying to compile a program today on OS X Lion using gfortran, but to my disappointment I got these errors every time. I am not really familiar with this kind of stuff, so I wasn't sure where to look at first. Even when trying to compile a simple hello_world program.

The internet wasn't very useful either. Google gave me barely anything :(


The solution


First I removed xcode, with the idea to reinstall it later:

sudo /Developer/Library/uninstall-devtools -mode=all

After that I dug into my /usr/local/lib and /usr/bin folders and removed any reference to gcc, gcov, g++, cpp and gfortran, which are all part of the gcc package.

I also removed all references to llvm-* (where * can be gcc, g++, etc). This comes with xcode, not really sure what this is used for. And finally I removed the libgcc/ folder and all libgfortran-related files in /usr/local/lib.

I rebooted for good measure.

Next I got Xcode 4 from the Appstore (for OS X 10.6 and lower, it's available on the Mac Dev Center and installed it. Again I went into my /usr/bin/ and removed the symlink xcode made to their (incomplete, it misses gfortran) gcc.

I downloaded and installed gcc-lion.tar.gz from HPC and installed using:
gunzip gcc-lion.tar.gz sudo tar -xvf gcc-bin.tar -C /

After that, everything seemed to work! There is without doubt a faster way to fix it, but after trying to fix it for a few hours, I'm glad it now works! :)


What else?


If gcc gives an error that looks something like this:

ld: symbol(s) not found for architecture x86_64 collect2:
ld returned 1 exit status,

an explanation can be found here. Basically, the lstdc++ parameter has to be given, so it uses the correct library. Alternativey, g++ or clang++ can be used directly.


Useful links:


http://www.webmo.net/support/fortran_osx.html
http://hpc.sourceforge.net/

Tuesday, 15 November 2011

Print terminal output to file (python)

I found this awesome code snippet for python that will automatically print any print anything that is posted to the terminal to a file.

class Writer:
    def __init__(self, stdout, filename): 
        self.stdout = stdout 
        self.logfile = open(filename, 'w') 

    def write(self, text): 
        self.stdout.write(text) 
        self.logfile.write(text) 

    def close(self): 
        self.stdout.close() 
        self.logfile.close() 

This class will then inherit and modify the standard sys.stdout:
writer = Writer(sys.stdout, output_filename) 
sys.stdout = writer