How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions
You can find out a lot about the Python version you're running via the
platform
module (thesys
module also has a few simple helpers)On Mac OS X, you can run a "fat binary" with your chosen architecture with, for example,
arch -i386 /usr/bin/python
I do not recommend altering /usr/lib/python itself (with the lipo
command) -- you could easily make your system unusable by tampering with system files. Maybe installing a separate Python from python.org (for application purposes) while leaving the system Python alone is an acceptable strategy to you -- it's definitely safer than altering system files!-)
As for your third question, hmmm, this one's a stumper to me -- and definitely a question for superuser.com (as well as completely unrelated to Python, it also seems completely unrelated to programming;-).
Force Python to be 32 bit on OS X Lion
You can use the lipo
command to create a copy of the Python interpreter with only i386
support.
:; 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 for your existing scripts to call python-i386
, or (if they use the /usr/bin/env
trick) rename it to python
and put it in a directory that's in your PATH
somewhere before /usr/bin
.
Note that looking at platform.architecture()
or even platform.machine()
doesn't actually tell you if the current process is 32-bit or 64-bit. Those always give 64-bit answers for me. But when I check in Activity Monitor, I can see that my stripped binary is not marked “(64-bit)”, while other processes are.
How do I force my code to use 32-bit Python in a virtual environment?
platform.architecture()
is unreliable on OSX, to be sure you're still runing 64 bit and not 32 you should run sys.maxsize > 2**32
https://docs.python.org/2/library/platform.html#platform.architecture
Executing python in 64 bit mode on Mac OS X 10.10
From Jeff's comment, I installed python from brew
.
> /usr/local/Cellar/python/2.7.9/bin/python -c 'import sys; print sys.maxint'
9223372036854775807
Now, it works fine at least with brew's python.
Run python as a 32-bit process in Eclipse PyDev on Mac OS X Lion
I think the best approach would be installing a Python that's only 32 bit instead of using the Python installed in the system.
Or if you really want to use the one in the system, you can take a look at: How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions on other ways to configure Python to run in 32 bits (VERSIONER_PYTHON_PREFER_32_BIT environment variable seems a good choice).
How to force using 64 bit python on Mac OS X?
Try using arch(1), and supply the specific version of Python:
arch -x86_64 /usr/bin/python2.6
Actually the system should choose the first suitable architecture for you. As
$ file /usr/bin/python2.5
/usr/bin/python2.5: Mach-O universal binary with 2 architectures
/usr/bin/python2.5 (for architecture i386): Mach-O executable i386
/usr/bin/python2.5 (for architecture ppc7400): Mach-O executable ppc
$ file /usr/bin/python2.6
/usr/bin/python2.6: Mach-O universal binary with 3 architectures
/usr/bin/python2.6 (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python2.6 (for architecture i386): Mach-O executable i386
/usr/bin/python2.6 (for architecture ppc7400): Mach-O executable ppc
If that python
somehow chooses 2.5, then you can't use 64-bit, but if it chooses 2.6 then the x86_64 variant should be automatically selected, as commented below. If it's the former, try to get python_select
and change the version to 2.6.
Related Topics
Convert a List with Strings All to Lowercase or Uppercase
On Localhost, How to Pick a Free Port Number
Conda Command Is Not Recognized on Windows 10
How to Get a Complete List of Object's Methods and Attributes
How to Manage Third-Party Python Libraries with Google App Engine? (Virtualenv? Pip)
Check If a Number Is Int or Float
Why am I Getting Importerror: No Module Named Pip ' Right After Installing Pip
How to Write a File or Data to an S3 Object Using Boto3
Salt and Hash a Password in Python
Sorting by a Custom List in Pandas
Pyspark: Split Multiple Array Columns into Rows
How to Insert Pandas Dataframe via MySQLdb into Database
Getting a MAChine's External Ip Address with Python
Making Heatmap from Pandas Dataframe
Convert Columns to String in Pandas
Configuring So That Pip Install Can Work from Github