Repository: biopython/biopython

Issue:
gcc Error raised during installation
I am following the instructions on installing biopython [here](http://biopython.org/wiki/Download). After unzipping, cding into the folder and typing `python setup.py build` the following error is raised:

```
gcc: error: unrecognized command line option ‘-Qunused-arguments’; did you mean ‘-Wunused-argument’?
gcc: error: unrecognized command line option ‘-Qunused-arguments’; did you mean ‘-Wunused-argument’?
error: command 'gcc' failed with exit status 1
```

I have also tried installing with pip, but the following error was raised:

`failed building wheel for biopython`

and

`Command "/Users/josephsolvason/miniconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/98/hln2y055423b7bktpx2m_nb40000gn/T/pip-build-dbc_20t2/biopython/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/98/hln2y055423b7bktpx2m_nb40000gn/T/pip-qvap070g-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/98/hln2y055423b7bktpx2m_nb40000gn/T/pip-build-dbc_20t2/biopython/`

Thoughts?


Discussion:
Which version of Biopython did you download?

Which version of Python are you using? It looks like some version of Python 3 via conda?

Which OS are you using? It looks like it could be Mac OS X?

Which version of ``gcc`` is installed? Try ``gcc - v`` for this.

What is the default compiler, i.e. What does ``cc -v`` give?


Also given you appear to be using conda, did you try ``conda install biopython``?

*Update:* https://github.com/biopython/biopython.github.io/issues/118
Ok, based on your response I tried using Python 2.7.13 to build in the biopython directory and it worked. However, it still did not work with python 3.6.0 

I was able to use biopython with python 3.6.0 after installing with  `conda install python`. Thanks for your suggestion!
It seems the conda Python environment is subtly different in some way that our ``setup.py`` does not handle. But I'm glad that ``conda install biopython`` worked as that would be my recommendation for adding packages within the conda Python environment.

Shall we close this issue?
Sure thing! Thanks.

Joe


Joseph Solvason
Chimera Bioengineering

On Tue, Jun 20, 2017 at 2:13 PM, Peter Cock <notifications@github.com>
wrote:

> It seems the conda Python environment is subtly different in some way that
> our setup.py does not handle. But I'm glad that conda install biopython
> worked as that would be my recommendation for adding packages within the
> conda Python environment.
>
> Shall we close this issue?
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/biopython/biopython/issues/1287#issuecomment-309893498>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AbxuJjvRYvuZXiv3cfLxdr8GXWBOd4zWks5sGDYMgaJpZM4N-6EN>
> .
>

I got this error installing on MacOS 10.13.6 and was able to track it to the [compiler version check](https://github.com/biopython/biopython/blob/b1e33b9d7c619dd122bd7e1d6337455273194602/setup.py#L85) in `setup.py`.

That check, which reads the output of `cc -v`, ignores environment flags like `$CC`, which will later be used to decide the compiler. In my mac `cc` is the OS-distributed clang, whereas `$CC` is `gcc-7` via Homebrew.

I opened a [PR in MDAnalysis](https://github.com/MDAnalysis/mdanalysis/pull/2163), which gave me similar problems, where `setup.py` now uses a combination of `distutils`' `new_compiler()` and `customize_compiler()` to get the compiler that'll be used for building. If biopython can use `distutils` at setup-time this might be a good thing to implement. Otherwise, perhaps directly check environment vars?
You are likely right about the source of this problem, not looking at ``$CC``. Good detective work, let's reopen this issue 👍 

I'd be comfortable with explicitly checking ``os.environ["CC"]`` or similar (has to work cross platform including Windows, so something like ``${CC:-cc} -v`` would probably not work), but if not - is there a ``setuptools`` equivalent of the ``distutils`` approach you linked to?
I couldn't find anything specific to `setuptools`. Are there even platforms where biopython is deployed that have `setuptools` but not `distutils`? Seems a bit odd given the former's dependence on the latter.

If the matter is avoiding direct `distutils` import, would it be acceptable to use it via `setuptools.distutils`?

Finally, the `distutils.sysconfig.customize_compiler` routine is the core bit, as it does a nice job at finding flags and whatnot. It wouldn't be terrible to [copy over](https://github.com/python/cpython/blob/1c3de541e64f75046b20cdd27bada1557e550bcd/Lib/distutils/sysconfig.py#L148) if no alternatives are available.
No, just that only relatively recently we accepted ``setuptools`` as a Biopython installation requirement, and it seems in some ways further along that ``distutils`` which as part of the standard library is effectively in maintenance mode.

We can assume ``distutils`` is present and use that if it is appropriate.

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -82,7 +82,12 @@ def osx_clang_fix():
         from subprocess import getoutput
     else:
         from commands import getoutput
-    cc = getoutput("cc -v")
+    from distutils.ccompiler import new_compiler
+    from distutils.sysconfig import customize_compiler
+    # The compiler test should be made on the actual compiler that'll be used
+    compiler = new_compiler()
+    customize_compiler(compiler)
+    cc = getoutput("{} -v".format(compiler.compiler[0]))
     if "gcc" in cc or "clang" not in cc:
         return
     for flag in ["CFLAGS", "CPPFLAGS"]:


Test patch: