Project

General

Profile

Numextension » History » Version 11

Anchi Cheng, 07/04/2024 12:44 AM

1 1 Jim Pulokas
h1. Numextension
2
3
Numextension is a Python module containing a set of functions Leginon needs to operate on Numpy arrays.   Since it is implemented in C rather than in pure Python, the module must be compliled before using.  You can avoid compiling yourself by using one of the provided Windows installers for commonly used versions of Python and Numpy.   For non-standard or newer versions of Python/Numpy, use the instructions below for doing your own compile.
4
5
h2. Pre-compiled Windows Installers
6
7 6 Jim Pulokas
* attachment:numextension-git.win-amd64-py3.6.exe
8
* attachment:numextension-git.win-amd64-py3.7.exe
9 4 Jim Pulokas
* attachment:numextension-git.win-amd64-py3.8.exe
10
* attachment:numextension-git.win-amd64-py3.9.exe
11 7 Sargis Dallakyan
* attachment:numextension-3.1.0.win-amd64-py3.10.msi
12 1 Jim Pulokas
13
h2. Compiling Numextension on Windows
14
15
h3. Install Build Tools
16
17
Windows versions of Python and Numpy are developed using Microsoft Visual Studio.  Extension modules written in C should also be compiled with VS. Luckily you do not have to install a full version of Visual Studio.  Compiling a Python extension only requires a minimal set of command line build tools.   These tools are documented here:
18
19
https://docs.microsoft.com/en-us/cpp/build/building-on-the-command-line?view=msvc-160
20
21
and can be downloaded from here:
22
23
https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
24
25
h3. Install Python and Numpy you want to compile numextension for
26
27 2 Jim Pulokas
* You may install multiple versions of python, then use the "py" launcher to select which one to use
28
* Download and install Python:  https://www.python.org/downloads/windows/
29
** In the optional installation features, it is recommended to select installing "py launcher" so you can easily select which python version to run on the command line
30
* Use pip on the command line to install numpy, use specific pip for version of python you are installing in (eg. pip3.8, pip3.9, etc)
31
** As of 2020-11-29, there is a bug in Win 10 (update 2004) that prevents some versions of numpy to work correctly. The bug and workaround is detailed here:  https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html
32
** Workaround is to install older version 1.19.3 version of numpy instead of 1.19.4:
33
*** pip3.8 uninstall numpy   (if you already have numpy installed)
34
*** pip3.8 install numpy==1.19.3
35 1 Jim Pulokas
36 2 Jim Pulokas
h3. Compile numextension in a VS native tools command prompt:
37
38
* Search and launch this from start menu:    "x64 Native Tools Command Prompt for VS 2019"
39
* cd to the numextension directory
40
* compile and build a windows installer for your specific Python version.
41
** py -3.8 setup.py bdist_wininst
42
* The new windows installer will be found in the numextension/dist folder
43 5 Jim Pulokas
44 11 Anchi Cheng
h2. MacOS and some linux system python3 compilation
45 1 Jim Pulokas
46 11 Anchi Cheng
For example, if you get this error:
47
<pre>
48
  File "/opt/applications/myami/3.6/lib64/python3.9/site-packages/numextension/__init__.py", line 17, in <module>
49
    import _numextension
50
ModuleNotFoundError: No module named '_numextension'
51
52
because it is looking for _numextension.so. (instead numextension.cpython-39-x86_64-linux-gnu.so is created.
53
</pre>
54
You can resolve this error by moving numextension.cpython-39-x86_64-linux-gnu.so from your installed location such as /lib/python3.9/site-packages/numextension-1.0.0-cpython-39-x86_64-linux-gnu.egg to /opt/applications/myami/3.6/lib64/python3.9/site-packages
55
56 9 Anchi Cheng
57 5 Jim Pulokas
h2. Testing numextension
58
59
* Each function of numextension can be tested using numtest.py, which can be found in directory numextension/test/ (In Git, not in the installed numextension)
60 8 Anchi Cheng
* This was in numext3 branch but is now merged into myami-python3 branch.
61
* numtest.py requires pyami, and therefore a minimal set of modules from pyami have been converted to python 3 in the same branch
62 5 Jim Pulokas
* Conversion of pyami from py2 to py3 includes the use of the "future" and "past" modules. To use this minimally converted pyami, you will also need to install the "future" package using pip.
63
* numextension/test/ also contains a reference input image and a reference set of data for the tests in numref.py and several other MRC images.
64
* Running numtest.py will use the reference images and data within numref.py to determine if each test passes
65 8 Anchi Cheng
* It will also write out a set of MRC images, which are the output from testing the numextension functions.  These are compared against the reference images.   These test output images are prefixed with "test_..."