[PYTHON] F2py on Miniconda for Windows

I'm having an affair from my Mac and playing with Windows. Windows 10 Pro / Education can be used with Ubuntu on Windows, Docker for Windows, and Hyper-V, but it can be done, but you have to use or teach using Windows in the training room without administrator privileges. I think there are times.

The official Python installer can also be installed without administrator privileges, but Conda is convenient when trying to do numpy etc. I used Miniconda Python-3.6 64-bit to conda install jupyter, but I think it would be easier to install Anaconda. numpy contains f2py, but it wasn't ready to use.

Since I am not good at DOS commands below, I am using PowerShell, which has an alias, and bash of git for windows, which I installed later.

Install gfortran

I thought about installing mingw-w64, but since it was prepared by Mr. Conda, I decided to install it.

conda install m2w64-gcc-fortran

Since the path does not pass just by installing it,

C: \ Users \ username \ Miniconda3 \ Library \ mingw-w64 \ bin

(In the case of Anaconda, ʻAnaconda3 instead of Miniconda3`, the path to Conda is omitted below) is added to the path. When you ask Cortana "environment variables", it opens a control panel for setting environment variables. You should be able to edit the Path of the user environment variable at the top.

No f2py

Conda's f2py is in Scripts \ f2py.py. Create a batch file Scripts \ f2py.bat` so that it can be executed.

f2py.bat


python %~dp0/f2py.py %*

If you use PowerShell, you can write the function in $ profile.

function f2py () {python \ Users \ username \ Miniconda3 \ Scripts \ f2py.py $ args}

Source modification

I can now run f2py, but when I give it the source I get the error ValueError: Unknown MS Compiler version 1900. A little source modification is needed.

Lib \ distutils \ cygwinccompiler.py comment out lines 157 and 318 so that pass does nothing. Add pass #.

cygwinccompiler.py


pass#self.dll_libraries = get_msvcr()

Lib \ site-packages \ numpy \ distutils \ mingw32ccompiler.py comment out lines 96-104 with#.

mingw32ccompiler.py


# Check for custom msvc runtime library on Windows. Build if it doesn't exist.
 #msvcr_success = build_msvcr_library()
 #msvcr_dbg_success = build_msvcr_library(debug=True)
 #if msvcr_success or msvcr_dbg_success:
     # add preprocessor statement for using customized msvcr lib
 #    self.define_macro('NPY_MINGW_USE_CUSTOM_MSVCR')

 # Define the MSVC version as hint for MinGW
 #msvcr_version = '0x%03i0' % int(msvc_runtime_library().lstrip('msvcr'))
 #self.define_macro('__MSVCRT_VERSION__', msvcr_version)

hello

Try immediately.

foo.f90


subroutine hello()
    print *, "Hello"
end subroutine hello
f2py -c --fcompiler=gnu95 --compiler=mingw32 -m foo .\foo.f90
PS C:\Users\User name\Development\foo> python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo
>>> foo.hello()
 Hello from Fortran90!!!
>>>

At first I was worried about UnicodeDecodeError, but when I switched the shell to English, it worked. It is a mystery because the error cannot be reproduced even if it is returned to Japanese.

chcp 437

Lowtran

Try it with lowtran. git is also included in conda, but I installed git for Windows which also comes with GUI and bash.

I didn't have pandas, so I added it with conda.

git clone https://github.com/scivision/lowtran
cd lowtran
setup.py develop
conda install pandas
python DemoLowtran.py -a 0 12.5 25

lowtran.png

I love the different colors.

Referenced site

Recommended Posts

F2py on Miniconda for Windows
pykintone on Windows Subsystem for Linux
Notes for using OpenCV on Windows10 Python 3.8.3.
Python on Windows
Programming environment for beginners made on Windows
[Note] Procedures for installing Ubuntu on Windows 10
Building an environment for "Tello_Video" on Windows
A tool for creating symbolic links on Windows
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
Run yolov4 "for the time being" on windows
Notes for using TensorFlow on Bash on Ubuntu on Windows
Installing TensorFlow on Windows Easy for Python beginners
Steps to build PyTorch 1.5 for CUDA 10.2 on Windows
Pylint on Windows Atom
Linux (WSL) on Windows
Use pyvenv on Windows
Anaconda on Windows Terminal
Install Anaconda on Windows 10
python basic on windows ②
Install python on windows
Install pycuda on Windows10
Build TensorFlow on Windows
Try FEniCS on Windows!
Build XGBoost on Windows
Install pygraphviz on Windows 10
Use Ansible on Windows
Try Poerty on Windows
Install Chainer 1.5.0 on Windows
Use QuTiP on Windows
Use pip on Windows
Install Python (for Windows)
Build a Python extension for E-Cell 4 on Windows 7 (64bit)
[Heroku] Memo for deploying Python apps using Heroku on Windows [Python]
A memo of installing Chainer 1.5 for GPU on Windows
PIL with Python on Windows 8 (for Google App Engine)
Procedure for building a CDK environment on Windows (Python)
Cross development environment (developing programs for windows on linux)
For those who can't install Python on Windows XP
Install Numpy on virtualenv on Windows
Set-enable Python virtualenv on Windows
Rebuilding an environment for machine learning with Miniconda (Windows version)
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Install watchdog on Windows + Python 3.3
Installation notes for TensorFlow for Windows
Python 3.6 installation procedure [for Windows]
Anaconda 4.4.0 Initial Settings for Windows
Install Win-Kex (kali-linux) on Windows 10.
Before trying Veriloggen on Windows
I tried running PIFuHD on Windows for the time being
Install cvxpy on windows, Anaconda
Python + Kivy development on Windows
Prepare Chainer environment on Windows
Try using OpenCV on Windows
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
Make Cython available on Windows.
Fastest Python installation on Windows
Operate ubuntu on VScode (windows10)
Build Python environment on Windows
Django environment development on Windows 10
Install Chainer 1.6 (GPU) on Windows 7.