How to recompile an x64 blender python script for x86 computers? - python

I'm trying to get a blender addon, animation nodes, working on a x86 computer. To my lack of luck, there's only 64 bit builds avalible.
In the past, I've found a previously compiled version of the addon - unluckily, this was for blender 2.78, and not 2.8.
https://blender.community/5d28871ad3ac8b41e5d7215c/download/5d288762d3ac8b41e5d7215e is the code.
Upon importing the addon into 2.8, I get the standard Could not compile wall of text. When importing the older addon, it comes up as upgrade to 2.8x required, as usual.

If the supplied addon distributions don't work for you, then you need to compile your own version.
You will need cython and a C/C++ compiler to compile the addon. Your python version should match the blender install which is v3.7 for blender 2.80
Download the git repo and checkout the blender2.8 branch
Create conf.json at the top of the repo and set the Copy Target to the location of your blender addons directory
Run python setup.py build --copy to build and install animation nodes
Alternatively use python setup.py build --export to build it into a zip file for you to install manually

Related

Can PyInstaller from native Python include low-level dependencies like it does when using from Conda?

We need to deploy Python 3 script on RHEL 7.9 that has Python 2.7.5 and GLIBC 2.27. Don't have sudo privileges there, so we need to somehow bundle the whole project with all dependencies.
PyInstaller works perfectly, but only when used from Conda environment. On native Python it produces much smaller package and bin execution returns error:
[3989] Error loading Python lib '/path/libpython3.8.so.1.0': dlopen: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by /path/libpython3.8.so.1.0)
Conda build has 202 elements in build dir:
While build with regular Python only 31:
Is there a way to build the project with all low-level dependencies like with Conda but using some free license tool?

Python py2app and pillow error: Mach-O header is too large

I'm unable to use py2app to build a python application which contains the pillow package. I'm using:
Mac OSX El Capitan (10.11.16)
Python 3.7.3 (Installed via Homebrew)
Pillow 6.0.0
py2app 0.19
macholib 1.11
The script works fine when called from the command line and the py2app bundle works fine if compiled in alias mode python3 setup.py py2app -A
But, when I try to compile a standalone bundle using:
python3 setup.py py2app --packages=PIL
I get the following error message:
ValueError: New Mach-O header is too large to relocate in '/Users/RG/Library/Mobile Documents/com~apple~CloudDocs/iHal/Code/QuotesApp/dist/Quotes.app/Contents/Resources/lib/python3.7/PIL/.dylibs/liblcms2.2.dylib' (new size=1688, max size=1680, delta=48)
I've been searching but have had no luck finding help with this issue, is it possible it's an El Capitan (OSX 10.11.16) issue?
my system specs:
Mac OSX Mojave (10.14.15)
Python 3.7.4 (python.org)
Pillow 6.1.0
py2app 0.19
macholib 1.11
I had the same issues as you. The reason why it fails is that the library is wrong compiled. I figured out two solutions.
On my system the library is located at: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PIL/.dylibs/
If you do not use color management in your project you can delete the library "liblcms2.2.dylib". Now you can run py2app and it will build.
The second solution is more work and the way I use it in my project.
First, you need Xcode because we have to recompile the "littlecms" library.
Xcode is around 6gb and you get it from the Apple Appstore. On my system have the version 10.2.1.
Download the library littlecms in version 2.2: https://www.littlecms.com/
You will be redirected to SourceForge:
https://sourceforge.net/projects/lcms/files/lcms/2.2/
Download one of these files: lcms2-2.2.zip or lcms2-2.2.tar.gz and extract it on your system.
The library source comes with the Xcode project file and you will find in Projects/mac.
If you are familiar with the terminal you can build it without the Xcode GUI. In this case, go into the extracted folder of littlecms and type following commands.
./configure
make
make check
If the last command(make check) runs fine the library is ready for deployment.
You will find the compiled library in the folder: src/.libs/.
Replace the library which comes with the PIL package with your compiled library.
Finally, run py2app to build your project.
If this is not working you have to tell the linker a flag.
Go to your littlecms source folder and type the commands:
make clean
./configure LDFLAGS="-headerpad_max_install_names"
make
make check
Replace the compiled library with the PIL.
so long,
Phil

How to transfer a built Cython extension from a PC to another?

I have a PC in which I can not run setup.py file when I build a cython extension, because I do not have admin rights to install VC++ 14.0 (for python 3). So I decided to build the cython extension on another PC which works great. Now I want to transfer the cython module (for example helloword) to the other PC.
I tried to copied all the files generated after running setup.py, but it doesn't recognize the the modul with the following message:
I use python 3.7.3 to build the cython extension then copied all the files to python 3.6.1. Both PC are on windows. I use pycharm 2019 on both windows.
The structure of my project looks like below:
As already mentionned in the commentaries, you cannot run a compiled cython for 3.7 in a 3.6 version (At least for windows). Also, the architecture should be exactly the same aswell (You cannot compile on a 32bits machine, and deploy it on a 64bits machine)
Once you solved all the dependency problem, you should run the python setup.py bdist_wheel command to create the wheel, and then run a pip install <path_to_wheel>

Python does not consider distutils.cfg

I have tried everything given and the tutorials all point in the same direction about using mingw as a compiler in python instead of visual c++.
I do have visual c++ and mingw both. Problem started coming when I wanted to install using pip. It always gave Unable to find vcvarsall.bat
So as per suggestions I created a file distutils.cfg under the following path c:/python27/Lib/distutils/ and added the following two lines:
[build]
compiler=mingw32
However, this file has no effect whatsoever. The same error still exists while using pip. I am trying to install numpy by the way currently although the error came earlier also.
Cost me several hours to figure this out but now works like a charm.
I am on Windows 64bit and using a scientific Python distribution Enthought Canopy.
Ensure you have installed MinGW and the Compilers you need (C, C++, Fortran..)
Add C:\MingW\bin to your PATH in Environment variables
In C:\Users\MyName\AppData\Local\Enthought\Canopy32\App\appdata\canopy-1.6.2.3262.win-x86\Lib\distutils, create with notepad++ or similiar a new file distutils.cfg
Write and save:
[build]
compiler = mingw32
[build_ext]
compiler = mingw32
Difficult Solution (Building using the C/C++ compiler)
Are you on Windows 32bit or 64bit? Are you specifying the build when you're compiling? For example, do the following in your shell or bash:
python setup.py build --compiler==mingw32
python setup.py install
Easier Solution (Use pre-built binaries)
If you don't have to compile the program, you can use the unofficial Windows binaries from here
Do you happen to use virtualenv as well?
Anyway, use Microsoft Visual C++ Compiler for Python 2.7
and a newer setuptools. The one bundled with virtualenv (3.6) does not support this compiler.
pip install "setuptools>=6.0"
Credits: http://blog.ionelmc.ro/2014/12/21/compiling-python-extensions-on-windows/

Build Python with Mingw and gcc

Is it possible to build Python interpreter from source with Mingw and gcc on Windows 7?
And I would like to biuld a 64bit version.
If a 64bit Python (gcc Mingw) version is available for download please let me know, I would use that also.
At the end I still would like to compile it with gcc and mingw.
First off, you do not need to build Python with MinGW-w64 to link to it and embed a interpreter. Just extract the msi installer, and use the prebuilt DLL. Note you'll have to be careful not to mix msvcr[t|90].dll objects, but I've never seen that be a real issue personally.
MinGW-w64 gcc/ld should be able to link to DLL's directly, otherwise you'll have to use gendef to create a .def file and dlltool to create an import library.
Secondly, there's a patchset to build Python with MinGW, but I'm not sure about its 64-bit compatibility.
You may try this repository:
hg clone https://bitbucket.org/puqing/python-mingw
It is a copy of the official repository but contains some modification to make it compile with mingw. Enter PC/MinGW directory:
cd PC/MinGW && make
Not sure if it compiles in win64, but with win32 and msys it should work.

Categories

Resources