在执行中从64位python.exe切换到32位 [英] Switching from 64bit python.exe to 32bit in mid execution

查看:974
本文介绍了在执行中从64位python.exe切换到32位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个单独的python.exe,一个是64位,一个是32位.默认为64位.在中间执行期间,如何使用subprocesssys(或任何相关程序包)将控制从64位切换到32位,仅执行32位代码,然后再将控制切换回64位版本?换句话说,我正在寻找类似...

I have 2 seperate python.exe, one is 64bit one is 32bit. The 64bit is the default one. How can I use subprocess or sys (or any relevant package) to switch control during mid-execution from the 64 bit to the 32 bit, execute code only for the 32 bit, then switch control back to the 64bit version? In other words, I'm looking for something like...

if struct.calcsize("P")==8: # check if 64 bit version
   # switch to 32 bit version 
   # ??? new_shell = subprocess.Popen(location of 32 bit python.exe)??? what would go here
   # pass a bunch of commands and then switch control back
   # to the 64 bit version

另外,我正在使用anaconda,所以我想第一个调用将是切换到32位python.exe环境?在32位过程中,需要导入一些软件包,最后将返回数据.

Also, I'm using anaconda, so I imagine the first call will be for switching to the 32bit python.exe environment? During the 32bit process, some packages need to be imported and data will be returned at the end.

推荐答案

通常不可能在32位和64位模式之间进行中间执行.要解决此问题,请考虑将工作流划分为多个脚本,并在需要时同时具有32位和64位版本的脚本:

Mid-execution between both 32-bit and 64-bit modes mostly likely is not possible. To resolve, consider compartmentalizing your workflow into several scripts and have both 32-bit and 64-bit versions of script when needed:

  1. 使用一个脚本(即通过ODBC连接)检索数据,然后 输出到平面文件(txt,csv);
  2. 使用一个脚本导入平面文件并处理数据,然后导出到已处理的平面文件中;
  3. 使用另一个脚本返回处理后的数据(即,SQL附加到ODBC中 数据库).
  1. Retrieve data with one script (i.e., via ODBC connection) and output into flatfile (txt, csv);
  2. Import flatfile and process data with one script and export into processed flatfile;
  3. Return processed data with another script (i.e., SQL appends into ODBC database).

此外,由于Python的两个位版本都不能彼此交谈",因此您将需要运行两个单独的脚本,这些脚本根据操作系统类型(32位和64位)有条件地被调用.并且参数可以通过子进程传递:

Additionally, because both bit versions of Python cannot "talk" to each other, you will need to run dual, separate scripts that are conditionally called depending on OS type (32-bit vs. 64-bit). And arguments can be passed with subprocess:

#!/usr/bin/python
import struct, subprocess

if struct.calcsize("P") * 8 == 32:
    subprocess.call(['C:\pathTo\32bit\python.exe', 'C:\pathTo\32bit\python\32bitscript.py', 'arg1', 'arg2'])
else:
    subprocess.call(['C:\pathTo\64bit\python.exe', 'C:\pathTo\64bit\python\64bitscript.py', 'arg1', 'arg2'])

环境路径变量或默认命令行路径将无用,因为它会恢复为一个python版本,而不会显式为另一个版本.因此,需要绝对声明python.exe版本.

Environment path variables or default command line paths will not be useful as it reverts to one python version and not explicitly the other. Hence, the need for absolute declaration of python.exe version.

这篇关于在执行中从64位python.exe切换到32位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆