1

I'm having trouble installing astropy for python. when I enter 'pip install astropy' in the terminal I get this message:

Collecting astropy
Using cached astropy-1.0.4.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 20, in <module>
  File "/private/var/folders/8g/ggchkyrx1xv7jk9df887m1cr0000gq/T/pip-build-63p1fldn/astropy/setup.py", line 49, in <module>
    adjust_compiler(NAME)
  File "/private/var/folders/8g/ggchkyrx1xv7jk9df887m1cr0000gq/T/pip-build-63p1fldn/astropy/.eggs/astropy_helpers-1.0.3-py3.4.egg/astropy_helpers/setup_helpers.py", line 197, in adjust_compiler
    if re.match(broken, version):
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/re.py", line 160, in match
    return _compile(pattern, flags).match(string)
TypeError: can't use a bytes pattern on a string-like object

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in 
/private/var/folders/8g/ggchkyrx1xv7jk9df887m1cr0000gq/T/pip-build-63p1fldn/astropy

Anyone has any idea why this is happening?

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
sarelg
  • 23
  • 4

1 Answers1

2

Are you on OS X? It seems the setup.py of astropy is trying to avoid using the llvm-gcc compiler on your system. There may be a bug in one of astropy's helper methods, but you can try to avoid it going down this code path by explicitly making clang your default compiler:

$ export CC=clang
$ export CXX=clang++
$ export FFLAGS=-ff2c

Then re-run pip install astropy

EDIT: Since the above isn't working for you, try a manual installation.

Install Xcode Command Line Tools so as to ensure clang is installed on your system: http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/

xcode-select --install

Set the environment variable CC configuring clang as your default compiler

export CC=clang

Download the astropy tarball

curl -O https://pypi.python.org/packages/source/a/astropy/astropy-1.0.4.tar.gz

Unzip the astropy tarball

tar zxvf astropy-1.0.4.tar.gz

Change directory to theastropy-1.0.4 folder

cd astropy-1.0.4

Try to manually patch the bug that's causing the install to fail. First open up setup_helpers.py in a text editor

vim astropy_helpers/astropy_helpers/setup_helpers.py

Modify line 110. Remove the "b".

i.e. Change:

(b'i686-apple-darwin[0-9]*-llvm-gcc-4.2', 'clang')

To:

('i686-apple-darwin[0-9]*-llvm-gcc-4.2', 'clang')

Execute the manual installation from the astropy-1.0.4/ folder:

sudo python setup.py install
Joe Young
  • 5,749
  • 3
  • 28
  • 27
  • 1
    This looks like the right idea. It is indeed a bug, which seems to only occur if you're using an unknown or otherwise broken compiler. In this case the [`get_compiler_version`](https://github.com/astropy/astropy-helpers/blob/master/astropy_helpers/setup_helpers.py#L202) function returns the string `'unknown'`, when it should be returning a bytes object (or vice versa). Joe's solution should work here, unless you don't have `clang` either. I've opened an issue here: https://github.com/astropy/astropy-helpers/issues/182 – Iguananaut Sep 02 '15 at 21:46
  • By the way, if you don't have a C compiler at all you could work around this bug by setting `export CC=/bin/echo` or something like that, though the package will still fail to install in that case--it needs a C compiler to build (consider also using a scientific python distribution with pre-built binaries for Astropy) – Iguananaut Sep 02 '15 at 23:30
  • So any more thoughts on what I can do right now? I kinda need it for work. By the way, I had a different error before, and I saw someone here with a similar error suggest doing this: 'sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2'. After that I got this error. – sarelg Sep 03 '15 at 07:40
  • Try installing Xcode Command Line tools, then run the pip install again: http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/ If it doesn't work immediately after installing Xcode Command Line tools, try setting the CC environment variable as shown in my answer. – Joe Young Sep 03 '15 at 07:55
  • Tried it, no difference. – sarelg Sep 03 '15 at 08:57
  • Updated the answer with an alternate manual installation method. – Joe Young Sep 03 '15 at 10:41
  • Thanks for all the help, still doesn't work, now I get a long error where the bottom line is: 'RuntimeError: Broken toolchain: cannot link a simple C program'. – sarelg Sep 03 '15 at 11:33