esheldon / fitsio

A python package for FITS input/output wrapping cfitsio
GNU General Public License v2.0
131 stars 57 forks source link

Compiling under Windows 10 - "MSVCCompiler has no attribute compiler" #103

Open joseortiz3 opened 7 years ago

joseortiz3 commented 7 years ago

Hello, I'm interested in getting fitsio compiled under windows 10. The setup.py indicates to use the same compiler that compiled python. I used msvc to compile python.

So in like 64 of the setup.py

    def build_extensions(self):
        if not self.use_system_fitsio:

            # Use the compiler for building python to build cfitsio
            # for maximized compatibility.

            # there is some issue with non-aligned data with optimizations
            # set to '-O3' on some versions of gcc.  It appears to be
            # a disagreement between gcc 4 and gcc 5

            CCold=self.compiler.compiler

my self.compiler (MSVCCompiler) does not have an attribute called compiler, so this line fails. I'm not sure where self.compiler is defined. If I did, I would tell you what attributes my self.compiler does have.

When pip runs, I get the error message

Installing collected packages: fitsio
  Running setup.py install for fitsio: started
    Running setup.py install for fitsio: finished with status 'error'
    Complete output from command C:\Users\Joey\Anaconda2\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\joey\\appdata\\local\\temp\\pip-build-hmsdmw\\fitsio\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\joey\appdata\local\temp\pip-negmnl-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-2.7
    creating build\lib.win-amd64-2.7\fitsio
    copying fitsio\fitslib.py -> build\lib.win-amd64-2.7\fitsio
    copying fitsio\test.py -> build\lib.win-amd64-2.7\fitsio
    copying fitsio\util.py -> build\lib.win-amd64-2.7\fitsio
    copying fitsio\__init__.py -> build\lib.win-amd64-2.7\fitsio
    running build_ext
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\joey\appdata\local\temp\pip-build-hmsdmw\fitsio\setup.py", line 203, in <module>
        "build_ext": build_ext_subclass,
      File "C:\Users\Joey\Anaconda2\lib\distutils\core.py", line 151, in setup
        dist.run_commands()
      File "C:\Users\Joey\Anaconda2\lib\distutils\dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "C:\Users\Joey\Anaconda2\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "C:\Users\Joey\Anaconda2\lib\site-packages\setuptools-20.7.0-py2.7.egg\setuptools\command\install.py", line 61, in run
      File "C:\Users\Joey\Anaconda2\lib\distutils\command\install.py", line 563, in run
        self.run_command('build')
      File "C:\Users\Joey\Anaconda2\lib\distutils\cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "C:\Users\Joey\Anaconda2\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "C:\Users\Joey\Anaconda2\lib\distutils\command\build.py", line 127, in run
        self.run_command(cmd_name)
      File "C:\Users\Joey\Anaconda2\lib\distutils\cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "C:\Users\Joey\Anaconda2\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "C:\Users\Joey\Anaconda2\lib\distutils\command\build_ext.py", line 339, in run
        self.build_extensions()
      File "c:\users\joey\appdata\local\temp\pip-build-hmsdmw\fitsio\setup.py", line 64, in build_extensions
        CCold=self.compiler.compiler
    AttributeError: MSVCCompiler instance has no attribute 'compiler'

Maybe someone knows a modification to get this to work? Maybe either making setup.py compatible with msvccompiler, or by specifying that another compiler be used?

esheldon commented 7 years ago

Can you please try setting CC=None ? This will I think use the default compiler settings.

esheldon commented 7 years ago

actually since the compiler attribute is missing entirely, this might mean the other attributes are missing as well, and you might need to sett all those keyword args to None, e.g. something like below. Maybe someone with a windows box knows better how to do these things correctly

            if not hasattr(self.compiler,'compiler'):
                CC=None
                ARCHIVE=None
                RANLIB=None
            else:
                CCold=self.compiler.compiler
                ARCHIVE=self.compiler.archiver
                RANLIB=self.compiler.ranlib

                CC=[]
                for val in CCold:
                    if val=='-O3':
                        print("replacing '-O3' with '-O2' to address "
                              "gcc bug")
                        val='-O2'
                    CC.append(val) 

            self.configure_cfitsio(
                CC=CC, 
                ARCHIVE=ARCHIVE,
                RANLIB=RANLIB,
            )

also in configure_cfitsio you will need a check

        args = ''
        if CC is not None:
            args += ' CC="%s"' % ' '.join(CC[:1])
            args += ' CFLAGS="%s"' % ' '.join(CC[1:])
MrBudgens commented 5 years ago

I am also unable to install on Windows. I get the same error as above.

Further progress can be made by:

However this is as far as I got. The installation fails with:

LINK : fatal error LNK1181: cannot open input file 'm.lib'

raphael-attie commented 4 years ago

Same error message as original post, under Windows 10. After I changed the setup.py according to the above instructions from esheldon, I executed and it first complained that I was missing the shell "sh" and "patch". Not familiar with using python under Windows, I installed that "patch" software and then installed the bash shell with cygwin to get the "sh" command. Updated windows Path to get all that available from the Windows Anaconda Prompt. I am now left with this error coming from "./configure":

(base) C:\Users\attie\Dev\fitsio>python setup.py install running install running bdist_egg running egg_info writing fitsio.egg-info\PKG-INFO writing dependency_links to fitsio.egg-info\dependency_links.txt writing requirements to fitsio.egg-info\requires.txt writing top-level names to fitsio.egg-info\top_level.txt reading manifest file 'fitsio.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching '*' under directory 'cfitsio3430' writing manifest file 'fitsio.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py running build_ext ./configure: line 14: $'\r': command not found ./configure: line 29: syntax error near unexpected token newline' '/configure: line 29: ;; Traceback (most recent call last): File "setup.py", line 294, in cmdclass={"build_ext": build_ext_subclass} File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools__init__.py", line 145, in setup return distutils.core.setup(**attrs) File "C:\Users\attie\Anaconda3\lib\distutils\core.py", line 148, in setup dist.run_commands() File "C:\Users\attie\Anaconda3\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "C:\Users\attie\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools\command\install.py", line 67, in run self.do_egg_install() File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install self.run_command('bdist_egg') File "C:\Users\attie\Anaconda3\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Users\attie\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools\command\bdist_egg.py", line 172, in run cmd = self.call_command('install_lib', warn_dir=0) File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools\command\bdist_egg.py", line 158, in call_command self.run_command(cmdname) File "C:\Users\attie\Anaconda3\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Users\attie\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools\command\install_lib.py", line 11, in run self.build() File "C:\Users\attie\Anaconda3\lib\distutils\command\install_lib.py", line 107, in build self.run_command('build_ext') File "C:\Users\attie\Anaconda3\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "C:\Users\attie\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "setup.py", line 72, in run build_ext.run(self) File "C:\Users\attie\Anaconda3\lib\site-packages\setuptools\command\build_ext.py", line 84, in run _build_ext.run(self) File "C:\Users\attie\Anaconda3\lib\site-packages\Cython\Distutils\old_build_ext.py", line 186, in run _build_ext.build_ext.run(self) File "C:\Users\attie\Anaconda3\lib\distutils\command\build_ext.py", line 339, in run self.build_extensions() File "setup.py", line 104, in build_extensions RANLIB=RANLIB, File "setup.py", line 232, in configure_cfitsio "could not configure cfitsio %s" % self.cfitsio_version) ValueError: could not configure cfitsio 3470

jscheidtmann commented 3 months ago

I face the same problem:

I have compiled cfitsio-4.4.0 as per instructions using Microsoft Visual Studio community edition.

Now I am trying to get python -m pip install fitsio to work on a Windows 11 machine.

I face the same issue as the posters above, but using the following environment variables in a Windows powershell, I am able to get @MrBudgens error message from the pip install:

$env:FITSIO_USE_SYSTEM_FITSIO=1     
$env:FITSIO_SYSTEM_FITSIO_INCLUDEDIR = '<cfitsio source tree>'   
$env:FITSIO_SYSTEM_FITSIO_LIBDIR= '<Release directoy of cfitsio.build>' 

I copied respective zlib files into the LIBDIR directory and renamed zlib.lib to z.lib (Ok, that was not a good move and was a wild guess, but that seems to have brought me onto the right track). This is the error message I get from pip install:

"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:\Entwicklung\imagesessionanalysis\cfitsio.build\Release "/LIBPATH:C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\libs" "/LIBPATH:C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0" "/LIBPATH:C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\PCbuild\amd64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.22621.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.22621.0\\um\x64" cfitsio.lib z.lib m.lib /EXPORT:PyInit__fitsio_wrap build\temp.win-amd64-cpython-310\Release\fitsio/fitsio_pywrap.obj /OUT:build\lib.win-amd64-cpython-310\fitsio\_fitsio_wrap.cp310-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-310\Release\fitsio\_fitsio_wrap.cp310-win_amd64.lib
      LINK : fatal error LNK1181: Eingabedatei "m.lib" kann nicht ge”ffnet werden.
      error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.37.32822\\bin\\HostX86\\x64\\link.exe' failed with exit code 1181
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for fitsio
  Running setup.py clean for fitsio
Failed to build fitsio

The Google search for this brings up this reference https://stackoverflow.com/questions/19333898/lnk1181-cannot-open-input-file-m-lib and in setup.py the culprits seem to be lines 176 and 178:

self.compiler.add_library('z')
...
self.compiler.add_library('m')

Can one of you please test, if commenting out these lines yields a working install? Thx, Jens If this works out, could you please guard these instructions to not execute on Windows, @esheldon?