简体   繁体   English

同时安装和运行 32 位和 64 位 python - 模块问题

[英]Installing and running both 32 bit and 64 bit python at the same time -module issues

I have one module that only runs on 32 bit python. I then have subprocesses that need to launch on 64 bit python for memory reasons.我有一个模块只能在 32 位 python 上运行。然后我有一些子进程需要在 64 位 python 上启动,原因是 memory。 There are also about 8 modules that I need to use.我还需要使用大约 8 个模块。 I installed everything and actually had both the 32 bit and 64 bit versions running at the same time.我安装了所有东西,实际上同时运行了 32 位和 64 位版本。 But then had to install one more module 'datetime'.但随后不得不再安装一个模块“datetime”。 After I installed that it went back to this issue.安装后又回到了这个问题。 I tried uninstalling 'datetime' and that did not fix.我尝试卸载“datetime”但没有解决。

OSError: [WinError 193] %1 is not a valid Win32 application OSError: [WinError 193] %1 不是有效的 Win32 应用程序

So I followed advice to do what originally seemed to allow both to run by using pip install -- pywin32==227所以我听从了建议,通过使用 pip install -- pywin32==227 来做最初似乎允许两者运行的事情

That said it was already satisfied so I tried pip install -- pywin32==228 then back to pip install -- pywin32==227那说它已经很满意所以我尝试了 pip install -- pywin32==228 然后回到 pip install -- pywin32==227

Still this error OSError: [WinError 193] %1 is not a valid Win32 application还是这个错误 OSError: [WinError 193] %1 is not a valid Win32 application

I noticed that despite having two versions of python (32 and 64 bit) in two different folders it is storing all modules in \AppData\Roaming\Python\Python39\site-packages and I am wondering how it distinguishes between a 32 bit module install and a 64 bit.我注意到尽管在两个不同的文件夹中有两个版本的 python(32 位和 64 位),但它将所有模块存储在 \AppData\Roaming\Python\Python39\site-packages 中,我想知道它如何区分 32 位模块安装和 64 位。

The most frustrating thing about this issue is for one brief moment, I actually had both running so I know it is possible, but not sure how at this point.关于这个问题最令人沮丧的事情是有那么一小会儿,我实际上都在运行所以我知道这是可能的,但不确定在这一点上如何。 Is there a recommended way to have two (32 and 64) bit pythons running at the same time with two unique sets of modules installed?是否有推荐的方法可以同时运行两个(32 位和 64 位)python 并安装两组独特的模块? At this point, I would start over with all of the installations as needed.此时,我将根据需要重新开始所有安装。

The problem is that python uses the same location for site.getusersitepackages() for 32-bit and 64-bit versions of python.问题是 python 对 python 的 32 位和 64 位版本使用相同的 site.getusersitepackages() 位置。

It appears that your installation process for your modules is using usersitepackages because you specified the directory causing you problems was \AppData\Roaming\Python\Python39\site-packages which is usersitepackages which appears earlier than the regular site-packages in sys.path (but only if the directory exists - hence not everybody knows about usersitepackages).您的模块安装过程似乎正在使用 usersitepackages,因为您指定导致问题的目录是 \AppData\Roaming\Python\Python39\site-packages,它是 usersitepackages,它比 sys.path 中的常规站点包更早出现(但前提是该目录存在——因此并不是每个人都知道 usersitepackages)。

This seems to be a bug with the Python release - it has annoyed me as well since I prefer to install my extensions in usersitepackages since I may not have write access to the regular site-packages directory.这似乎是 Python 版本的一个错误 - 它也让我很恼火,因为我更喜欢在 usersitepackages 中安装我的扩展,因为我可能没有对常规站点包目录的写入权限。

You can fix it as follows:您可以按如下方式修复它:

Edit the file Lib/site.py in your Python package (of course you might not have write access - see above).在您的 Python package 中编辑文件 Lib/site.py(当然您可能没有写入权限 - 见上文)。

There is a function called _get_path in this file which looks a bit like this:在这个文件中有一个名为 _get_path 的 function 看起来有点像这样:

def _get_path(userbase):
    version = sys.version_info
    if os.name == 'nt':
        return f'{userbase}\\Python{version[0]}{version[1]}\\site-packages'

So very good - it gets the right version of Python - but does nothing about the number of bits.非常好 - 它获得了 Python 的正确版本 - 但对位数没有任何影响。 Since we are recoding this function you should do this:因为我们正在重新编码这个 function 你应该这样做:

return f'{userbase}\\Python{version[0]}{version[1]}-32\\site-packages'

or this:或这个:

return f'{userbase}\\Python{version[0]}{version[1]}-64\\site-packages'

depending on whether you are editing the 32-bit version or the 64-bit version.取决于您编辑的是 32 位版本还是 64 位版本。

I suppose you could find out the architecture if you wanted to be pure and logical (in order to have the same implementation of site.py for all releases).我想如果您想要纯粹和合乎逻辑(以便所有版本都具有相同的 site.py 实现),您可以找到架构。

eg例如

import platform
platform.architecture()[0]

should return 32bit or 64bit - so this is what I think the Python development team should do if they read this comment.应该返回 32 位或 64 位 - 所以我认为 Python 开发团队在阅读此评论时应该这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM