aburrell / apexpy

A Python wrapper for Apex coordinates
MIT License
34 stars 25 forks source link

[BUG]: pip install on windows failing #65

Closed asreimer closed 3 years ago

asreimer commented 3 years ago

Describe the bug

pip install . doesn't work out of the box with Windows 10 and the mingw32 compiler.

To Reproduce Steps to reproduce the behavior:

  1. Grab this commit: git clone git+https://github.com/aburrell/apexpy.git@4a5b2d696b1c905b77e4115cbe9438f41c0c6740 (This is the latest, about to be merged in for 1.1.0 release)
  2. Try to pip install . and then try importing import apexpy in a python shell and get this result:

    Python 3.7.9 (default, Aug 31 2020, 17:10:11) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import apexpy C:\tools\miniconda3\envs\py37\lib\site-packages\apexpy\apex.py:19: UserWarning: fortranapex module could not be imported, so apexpy probably won't work. Make sure you have a gfortran compiler. Wheels installation assumes your compiler lives in /opt/local/bin" assumes your compiler lives in /opt/local/bin"])) Traceback (most recent call last): File "", line 1, in File "C:\tools\miniconda3\envs\py37\lib\site-packages\apexpy__init__.py", line 3, in from .apex import Apex, ApexHeightError File "C:\tools\miniconda3\envs\py37\lib\site-packages\apexpy\apex.py", line 20, in raise err File "C:\tools\miniconda3\envs\py37\lib\site-packages\apexpy\apex.py", line 14, in from . import fortranapex as fa ImportError: DLL load failed: The specified module could not be found.

Expected behavior The pip install command should work fine.

Computer (please complete the following information): Windows 10, miniconda python3.7 with mingw32 compiler installed.

asreimer commented 3 years ago

edit: redacted

asreimer commented 3 years ago

The original issue was on my end. It seems that I can get everything working now and am getting the same results identically in both windows and linux now.

edit: I updated this issue for what I found along the way.

This testing was useful though because I found that I cannot install apexpy without adding:

[build_ext]
mingw32 

to setup.cfg. This directly impacts #59. I haven't figured out an algorithmic fix yet. At the very least, maybe we need to add instructions in the docs?

What do you think @aburrell?

aburrell commented 3 years ago

Hmmm... and I am guessing from this command that there's no 32/64 agnostic command? My first instinct is to say, "let's create a branch and I'll upload a testable pip release candidate for you". But we need to make sure the setup config won't break appveyor or people with 64-bit systems, or are not on Windows!

I think adding instructions may be the way to go. I saw this example for using/abusing pip. Does it work for you?

# Specifying mingw32
pip install --global-option build_ext --global-option --compiler=mingw32 apexpy

# Specifying Visual C++
pip install --global-option build_ext --global-option --compiler=msvc apexpy

Above solution from: https://stackoverflow.com/questions/3297254/how-to-use-mingws-gcc-compiler-when-installing-python-package-using-pip

Also, did you try the pip install from TestPyPi? That will get you the current release candidate. From your statement above it looks like you didn't, but am also not sure if it will matter in this instance.

asreimer commented 3 years ago

After some sleep, I tried again. I had already tried the suggested command, specifically this:

pip install --global-option build_ext --global-option --compiler=mingw32 .

but it doesn't work. Looking at the logs, it seems to try to build all the dependencies in pyproject.toml first and that's what's causing the problem:

Processing c:\users\xxxx\desktop\git\apexpy
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:

So if I tell pip to ignore PEP 517, that fixes things:

pip install --no-use-pep517 --global-option build_ext --global-option --compiler=mingw32 .

So adding pyproject.toml fixed some things, but it does weird things when specifying custom build args? This should also work for installing from pypi later. Installing from TestPyPi, this works:

pip install --no-use-pep517 --global-option build_ext --global-option --compiler=mingw32 --index-url https://test.pypi.org/simple/ apexpy==1.1.0

So probably the best solution to all of this is just to document this idiosyncrasy for windows users?

aburrell commented 3 years ago

So probably the best solution to all of this is just to document this idiosyncrasy for windows users?

Yes, I think that's the best way forward.

asreimer commented 3 years ago

Sounds good. I'll make a commit to the documentation later today. Thanks!

asreimer commented 3 years ago

Looks like the best solution for Windows users might be to do this: https://wiki.python.org/moin/WindowsCompilers#GCC_-_MinGW-w64_.28x86.2C_x64.29

I've tested this and I can now simply run pip install . from within the git repo. Also, pip install --no-use-pep517 --global-option build_ext --index-url https://test.pypi.org/simple/ apexpy==1.1.0 works, but only if I include the --no-use-pep517 flag.

gregstarr commented 2 years ago

I am on Windows 11 and was having trouble installing apexpy as part of a conda environment.yml file. There were no errors during installation but I got the ImportError: DLL load failed: The specified module could not be found..

Everything appears to work if I take the following steps:

  1. conda create -n env
  2. conda activate env
  3. conda install numpy
  4. pip install apexpy
  5. conda env update -f environment.yml