Using Python 32 Bit in 64Bit Platform

How do I determine if my python shell is executing in 32bit or 64bit?

One way is to look at sys.maxsize as documented here:

$ python-32 -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)'
('7fffffff', False)
$ python-64 -c 'import sys;print("%x" % sys.maxsize, sys.maxsize > 2**32)'
('7fffffffffffffff', True)

On Windows, run the same commands formatted as follows:

python -c "import sys;print(\"%x\" % sys.maxsize, sys.maxsize > 2**32)"

sys.maxsize was introduced in Python 2.6. If you need a test for older systems, this slightly more complicated test should work on all Python 2 and 3 releases:

$ python-32 -c 'import struct;print( 8 * struct.calcsize("P"))'
32
$ python-64 -c 'import struct;print( 8 * struct.calcsize("P"))'
64

BTW, you might be tempted to use platform.architecture() for this. Unfortunately, its results are not always reliable, particularly in the case of OS X universal binaries.

$ arch -x86_64 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'
64bit True
$ arch -i386 /usr/bin/python2.6 -c 'import sys,platform; print platform.architecture()[0], sys.maxsize > 2**32'
64bit False

64-bit Python on 32 Bit Windows?

No.

You can run 32bit applications on 64bit Windows, but not the other way around.

How can 32bit modules run on 64bit Python?

The answer is simple - it can't work. A process is either 32 or 64 bit, it's as simple as that. So if there is one module that can't run in 64 bit, one option besides re-compiling the module for 64 bit is to delegate whatever purpose it has to a second process running in 32 bit, just doing that. This might or might not be practical, depending on the actual task of the module.

Installed Python with 32 bit install, appears as 64 bit

This sounds like you might have multiple instances of Python installed on your machine. Verify that you're calling the correct one by calling it explicitly from its full path, and noting if its still saying 64-bit or 32-bit.

Moving forward, using a virtualenv might simplify any confusion of which python installation, and which installed packages, are being used.

Python3 32bit 64bit

Go to where you downloaded the installer for the 32-bit version of Python and uninstall it from there.

Just take a look here.

Then install the 64-bit version.
It helps when installing to use the manual process.
Install the python version directly into a custom folder of your choosing to the C: drive of your PC.
Select "add to environment variables" while you are there (this will allow you to run the python console from CMD and PowerShell.

Also tick all these boxes:

Image

I hope this helps

How do I detect if Python is running as a 64-bit application?

import platform
platform.architecture()

From the Python docs:

Queries the given executable (defaults
to the Python interpreter binary) for
various architecture information.

Returns a tuple (bits, linkage) which
contain information about the bit
architecture and the linkage format
used for the executable. Both values
are returned as strings.

Using multiple Python engines (32Bit/64bit and 2.7/3.5)

Make sure to set the right environmental variables (https://github.com/conda/conda/issues/1744)

Create a new environment for 32bit Python 2.7:

set CONDA_FORCE_32BIT=1
conda create -n py27_32 python=2.7

Activate it:

set CONDA_FORCE_32BIT=1
activate py27_32

Deactivate it:

deactivate py27_32

Create one for 64 bit Python 3.5:

set CONDA_FORCE_32BIT=
conda create -n py35_64 python=3.5

Activate it:

set CONDA_FORCE_32BIT=
activate py35_64

The best would be to write the activation commands in a batch file so that you have to type only one command and cannot forget to set the right 32/64 bit flag.

UPDATE

You don't need to install a full Anaconda distribution for this. Miniconda is enough:

These Miniconda installers contain the conda package manager and Python. Once Miniconda is installed, you can use the conda command to install any other packages and create environments, etc. ...

There are two variants of the installer: Miniconda is Python 2 based and Miniconda3 is Python 3 based. Note that the choice of which Miniconda is installed only affects the root environment. Regardless of which version of Miniconda you install, you can still install both Python 2.x and Python 3.x environments.

I would recommend you to use Miniconda3 64-bit as your root environment.

You can always install a full Anaconda later with:

conda install anaconda

Note that it might downgrade some of your previously install packages in your active environment.



Related Topics



Leave a reply



Submit