I want to build a python package to upload to PyPI with compiled fortran code, so the user doesn't have to have any fortran compiler.
To do this, I've made an extension to my package in the setup.py file:
import io
from os import path as op
from setuptools import find_packages
from numpy.distutils.core import Extension, setup
with open('README.md') as readme_file:
readme = readme_file.read()
here = op.abspath(op.dirname(__file__))
# get the dependencies and installs
with io.open(op.join(here, "requirements.txt"), encoding="utf-8") as f:
all_reqs = f.read().split("\n")
install_requires = [x.strip() for x in all_reqs if "git+" not in x]
dependency_links = [x.strip().replace("git+", "") for x in all_reqs if "git+" not in x]
requirements = [ ]
setup_requirements = [ ]
test_requirements = [ ]
erf_extension = Extension(name='intelligen.fortran.functions',
sources=['intelligen/fortran/erf.f', 'intelligen/fortran/erf.pyf'],
extra_link_args=["-static", "-static-libgfortran", "-static-libgcc"])
setup(
author="Diego Bouchet",
author_email='diegobouchet88@gmail.com',
python_requires='>=3.5',
install_requires=install_requires,
dependency_links=dependency_links,
license="MIT license",
long_description=readme,
long_description_content_type='text/markdown',
include_package_data=True,
keywords='intelligen',
name='intelligen',
packages=find_packages(include=['intelligen', 'intelligen.*']),
setup_requires=setup_requirements,
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/Bouchet07/intelligen',
version='0.12.2',
zip_safe=False,
ext_modules=[erf_extension],
)
The requirements.txt is:
numpy
matplotlib
This works for me, when I do pip install -e . the package works fine, with the fortran code, and when I run python setup.py sdist bdist_wheel and upload to PyPI with twine upload dist/*, I can succesfully run pip install intelligen (the name of my package) and it works, but I tried in a different computer and it doesn't work. I get this:
ERROR: Command errored out with exit status 1:
command: 'c:\users\usuario\appdata\local\programs\python\python39\python.exe' 'c:\users\usuario\appdata\local\programs\python\python39\lib\site-packages\pip\_vendor\pep517\in_process\_in_process.py' build_wheel 'C:\Users\Usuario\AppData\Local\Temp\tmpe6a8v106'
cwd: C:\Users\Usuario\AppData\Local\Temp\pip-install-e_38naxi\intelligen_5ad9e25d759146c88a2da9bade5f8dcb
Complete output (36 lines):
running bdist_wheel
running build
running config_cc
INFO: unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
INFO: unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
INFO: build_src
INFO: building extension "intelligen.fortran.functions" sources
INFO: f2py options: []
INFO: adding 'build\src.win-amd64-3.9\build\src.win-amd64-3.9\intelligen\fortran\fortranobject.c' to sources.
INFO: adding 'build\src.win-amd64-3.9\build\src.win-amd64-3.9\intelligen\fortran' to include_dirs.
INFO: build_src: building npy-pkg config files
running build_py
creating build\lib.win-amd64-cpython-39
creating build\lib.win-amd64-cpython-39\intelligen
copying intelligen\AI.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\constants.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\integrate.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\intelligen.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\interpolate.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\linregress.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\numeric.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\signals.py -> build\lib.win-amd64-cpython-39\intelligen
copying intelligen\__init__.py -> build\lib.win-amd64-cpython-39\intelligen
creating build\lib.win-amd64-cpython-39\intelligen\stats
copying intelligen\stats\distributions.py -> build\lib.win-amd64-cpython-39\intelligen\stats
copying intelligen\stats\functions.py -> build\lib.win-amd64-cpython-39\intelligen\stats
copying intelligen\stats\__init__.py -> build\lib.win-amd64-cpython-39\intelligen\stats
running build_ext
INFO: No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
INFO: customize MSVCCompiler
INFO: customize MSVCCompiler using build_ext
INFO: CCompilerOpt.cc_test_flags[1021] : testing flags (/O2)
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
INFO: CCompilerOpt.cache_flush[817] : write cache to path -> C:\Users\Usuario\AppData\Local\Temp\pip-install-e_38naxi\intelligen_5ad9e25d759146c88a2da9bade5f8dcb\build\temp.win-amd64-cpython-39\Release\ccompiler_opt_cache_ext.py
----------------------------------------
ERROR: Failed building wheel for intelligen
Failed to build intelligen
ERROR: Could not build wheels for intelligen which use PEP 517 and cannot be installed directly
Why this doesn't work for any computer like scipy, which has fortran code too?
I have windows with a MinGW-64 installation with gfortran If you want to explore something in my code, it's here: intelligen