Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 views
in Technique[技术] by (71.8m points)

python - How do I replace my HPC gfortran with Homebrew gfortran?

I currently have Xcode (along with command line tools) and gfrotran from HPC installed on my Yosemite system, and would like to replace HPC's gfortran with Homebrew's (because I'm having trouble building Python packages with the HPC gfortran).

What are the steps to accomplish this?

I want to be sure that

  1. HPC's gfortran is gone (I just want one Fortran) and
  2. Apple's tools still work (for Xcode, Swift, OS X and iOS development, etc.)

and of course

  1. that I have a working version of gfortran that reliably builds Python packages.

Can this be done? I see for example that Homebrew's gfortran is now packaged as part of gcc, so it looks like I'll end up with two versions gcc (which I'd like to avoid) or one that doesn't play well with Xcode.

What are the steps to accomplish 1-3?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I recently worked through this very same problem. This is how I got/have it working on my Yosemite system.

Some things about home-brew and the command line tools compilers:

  1. The compiler you get through home-brew will overwrite the existing one if it is in the same place. If you have a fortran compiler that you obtained from the command line tools then it will not be affected.(Home-brew will warn you about this before doing anything)

  2. The binaries for the compilers you get through the command line tools are in /usr/bin .

  3. The compilers (and anything else) you obtain using home-brew are stored in the cellar ( /usr/local/Cellar) and the executables are linked into the directory /usr/local/bin.

What to do?

  1. Modify the path: I only needed to use the compilers I got through home-brew so I moved /usr/local/bin to the top of my $path this ensures that the /usr/local/bin directory is searched before /usr/bin.

  2. Use aliases : You can create an alias for each compiler so that you can use them interchangeably as you wish. To create an alias you will have to modify your shell-rc file. On my system I use the tcsh, and to create an alias for the home-brew compiler I would add something similar to this to my ~/.cshrc file.

    alias brewgfortran '/usr/local/bin/gfortran'
    

    this now executes the home-brew gfortran-4.9 executable that is stored in my cellar and linked to /usr/local/bin/gfortran/

  3. IF you absolutely want rid of the apple compilers you can of course remove them from the /usr/bin/ directory completely. I don't think this is the best idea though. I have shown you a few ways to avoid using them and if you ever needed them for some reason you would be SOL. I cant say if those tools you need will work without them as I have never used any of those, however I know it will build python packages for you (sorry hope this still helps)

NOTE: If you are not using the same shell as me the syntax for the alias is a little different (I think) just google it or man alias


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...