Force Python will be 32 bits on OS X Lion

I am trying to use CPLEX in Python on Mac OS 10.7.5. CPLEX seems to support only 32-bit python. I use this in the python shell to verify not 32 bits:

import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32 

I tried these 2 commands, as suggested in man 1 python, but none of them can force 32 bits:

 export VERSIONER_PYTHON_PREFER_32_BIT=yes defaults write com.apple.versioner.python Prefer-32-Bit -bool yes 

The only thing that works is:

 arch -i386 python 

However, if I run the script using arch, which calls other scripts, all of them seem to run in 64 bit mode. Is there another system variable to force it to switch to 32-bit mode?

+4
source share
3 answers

You can use the lipo command to create a copy of the Python interpreter with i386 support only.

 :; file /usr/bin/python2.7 /usr/bin/python2.7: Mach-O universal binary with 2 architectures /usr/bin/python2.7 (for architecture i386): Mach-O executable i386 /usr/bin/python2.7 (for architecture x86_64): Mach-O 64-bit executable x86_64 :; lipo -thin i386 -output python-i386 /usr/bin/python2.7 :; file python-i386 python-i386: Mach-O executable i386 :; ./python-i386 Python 2.7.2 (default, Jun 20 2012, 16:23:33) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 

Then arrange existing scripts to call python-i386 or (if they use the /usr/bin/env trick) rename it to python and put it in the directory located in PATH somewhere before /usr/bin .

Note that looking at platform.architecture() or even platform.machine() does not actually tell you if the current process is 32-bit or 64-bit. They always give me 64-bit answers. But when I look at Activity Monitor, I see that my split binary is not marked as "(64-bit)", while the other processes.

+6
source

See the official word from the Apple Developer Library on how to choose an interpreter for each user or throughout the system.

Installs the system version

% defaults write com.apple.versioner.python Version 2.7

Installs the standard system version up to 32 bits

% defaults write com.apple.versioner.python I prefer -32-bit-dub yes

USING A SPECIFIC VERSION

Instead of using the python command, you can use a specific version directly. For example, The python2.7 command line will launch the Python version 2.7, independent of the default version of Python.

You can use a specific version of Python in #! a script line, but this may have portability and future compatibility issues.

Note that the preference files and environment variable that apply to the python command do not apply when you run a specific version of Python. In particular, starting python2.6 will always be executed by default, up to 64-bit execution (unless the arch (1) command is used to specifically select the 32-bit architecture).

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/python.1.html

0
source

After a huge amount of trial and error that I myself tried some of the above suggestions, as well as here , I came across the following symbolic link:

 /usr/local/bin/python2-32 

pointing to:

 /Library/Frameworks/Python.framework/Versions/2.7/bin/python2-32 

And I notice that when I run this Python, it starts in 32-bit mode (unlike /Library/Frameworks/Python.framework/Versions/2.7/bin/python2 ). This can be observed in Activity Monitor.

Note: as others have pointed out elsewhere, platform.architecture() not always a good indicator. It shows β€œ64-bit” for this 32-bit process.

0
source

Source: https://habr.com/ru/post/1445645/


All Articles