# Creating a Conda package from Fortran and Python

**URL:** https://fortran-lang.discourse.group/t/creating-a-conda-package-from-fortran-and-python/4993
**Category:** Uncategorized
**Created:** [January 8, 2023, 12:27am UTC](https://fortran-lang.discourse.group/t/creating-a-conda-package-from-fortran-and-python/4993 "2023-01-08T00:27:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![samharrison7](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/samharrison7/32/3868_2.png) [@samharrison7](https://fortran-lang.discourse.group/u/samharrison7)
#### Post date: [January 8, 2023, 12:27am UTC](https://fortran-lang.discourse.group/t/creating-a-conda-package-from-fortran-and-python/4993/1 "2023-01-08T00:27:44Z")

</div>

Hi folks,

I thought this blog post that I just wrote might be of interest to some of you: [Creating a Conda package for a project with Fortran and Python code · Sam Harrison](https://samharrison.science/posts/conda-package-fortran-python/)

It’s meant as a tutorial for creating a Conda package for some Python code that calls a Fortran library, but brushes across a couple of subjects I know have been discussed here. Namely, calling Fortran from Python (I opt for `ctypes`) and difficulties of building Conda packages for Windows due to lack of packaged compilers.

I’d be interested to hear if anyone has any better ways of doing anything than what I’ve suggested in the post. Conda packaging is pretty new to me, so I’m very much still learning!

---

<div class="post-metadata">

### Author: ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)
#### Post date: [January 8, 2023, 5:52pm UTC](https://fortran-lang.discourse.group/t/creating-a-conda-package-from-fortran-and-python/4993/2 "2023-01-08T17:52:55Z")

</div>

Hi Sam,

thanks for sharing. In the past I’ve found Conda to be easiest way to obtain and work with Python packages.

Regarding better ways, I might only share this [pypackaging](https://pypackaging-native.github.io/) website that appeared recently, and discusses some pitfalls in Python packaging. There was also a related [discussion](https://news.ycombinator.com/item?id=34236919) on HackerNews. Many of the difficulties in packaging Fortran are shared with C and C++ (although there are a few Fortran specific ones).

---

<div class="post-metadata">

### Author: ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)
#### Post date: [January 8, 2023, 10:22pm UTC](https://fortran-lang.discourse.group/t/creating-a-conda-package-from-fortran-and-python/4993/3 "2023-01-08T22:22:06Z")

</div>

Nice write-up, generally a quite solid guide. A few suggestions though

- if you don’t need to be compatible with the conda-forge ABI then you can in principle use any Fortran compiler for building your library, _e.g._ ifort on Windows. The crucial step is the rpath fixing provided by conda-build, if you pass those to the compiler you should be fine.
- regarding environment variables, best use `$FC $FFLAGS` instead of `$GFORTRAN`, the former is more portable especially with passing through the options relevant for conda-build.

Finally, I would like to raise the issue with the two-stage build, I did it myself for the first Python bindings I wrote and it caused me a lot of work ever since, it is convenient to get started but not long-term feasible in my opinion. I now migrated to meson-python as build backend to get a simple one-step solution for `pip install`, while having the convenience of a proper build system for building the Fortran library.

---

<div class="post-metadata">

### Author: ![samharrison7](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/samharrison7/32/3868_2.png) [@samharrison7](https://fortran-lang.discourse.group/u/samharrison7)
#### Post date: [January 10, 2023, 10:40pm UTC](https://fortran-lang.discourse.group/t/creating-a-conda-package-from-fortran-and-python/4993/4 "2023-01-10T22:40:14Z")

</div>

Thanks both, great suggestions and links! I’m going to dig into meson-python a bit more. I’ve used meson a little for pure Fortran projects and was impressed.
