错误:";python37.dll的模块使用与此版本的Python冲突;从python3 exe子进程运行Maya时

错误:";python37.dll的模块使用与此版本的Python冲突;从python3 exe子进程运行Maya时,python,pyinstaller,maya,pyside2,Python,Pyinstaller,Maya,Pyside2,我无法从捆绑的.exe程序(Python 37)启动Maya 2020(Python 27)。我已经使用pyinstaller绑定了exe 如果我从IDE启动工具,它将启动Maya。当我从.exe启动工具时,几个Maya python模块出现以下错误: # Error: line 1: ImportError: file C:\Program Files\Autodesk\Maya2020\bin\python27.zip\ctypes\__init__.py line 10: Module u

我无法从捆绑的.exe程序(Python 37)启动Maya 2020(Python 27)。我已经使用pyinstaller绑定了exe

如果我从IDE启动工具,它将启动Maya。当我从.exe启动工具时,几个Maya python模块出现以下错误:

# Error: line 1: ImportError: file C:\Program Files\Autodesk\Maya2020\bin\python27.zip\ctypes\__init__.py line 10: Module use of python37.dll conflicts with this version of Python. # 
我试过这些建议,但我不确定我做错了什么

  • 我正在工具中使用PySide2和Python37
  • 我的全局路径中没有任何Python版本(我使用的是虚拟环境)
  • 我尝试添加sys.insert或创建PYTHONPATH变量,并在subprocess.Popen启动期间编辑环境变量,但似乎没有任何效果
我的代码如下。如果方便的话,我还可以通过电子邮件发送我的设置的zip文件:

启动\u maya.py(主文件):

import os
import sys
import subprocess

from PySide2 import QtWidgets



class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)

        # GUI
        btn_launch = QtWidgets.QPushButton('launch maya')
        btn_launch.clicked.connect(self.on_launch)

        # Layout
        main_layout = QtWidgets.QHBoxLayout(self)
        main_layout.addWidget(btn_launch)
        self.setLayout(main_layout)

        # Root path exe vs ide
        if getattr(sys, 'frozen', False):
            self.root_path = sys._MEIPASS
        else:
            self.root_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))

    def _set_app_envs(self):

        _envs = os.environ.copy()
        _envs['MAYA_SCRIPT_PATH'] = os.path.join(self.root_path).replace('\\', '/')
        _envs['QT_PREFERRED_BINDING'] = 'PySide2'

        # Python path envs
        _python_path_list = [
            os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe'),  # insert mayapy here????
            os.path.join(self.root_path).replace('\\', '/')  # userSetup.py dir
        ]

        # PYTHONPATH exe vs ide
        if getattr(sys, 'frozen', False):
            # There is no PYTHONPATH to add so, so I create it here (Do I need this? Is there a diff way?)
            _envs['PYTHONPATH'] = os.pathsep + os.pathsep.join(_python_path_list)

        # Insert mayapy.exe into front of PATH
        sys_path_ = _envs['PATH']
        maya_py_path = os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe')
        sys_path = maya_py_path + os.pathsep + sys_path_
        _envs['PATH'] = sys_path

        else:
            _envs['PYTHONPATH'] += os.pathsep + os.pathsep.join(_python_path_list)

        # Insert mayapy???????
        # sys.path.insert(0, os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe'))

        return _envs

    def on_launch(self):


        # Maya file path
        file_path_abs = '{}/scenes/test.mb'.format(self.root_path).replace('\\', '/')
        print(file_path_abs)
        app_exe = r'C:/Program Files/Autodesk/Maya2020/bin/maya.exe'

        _envs = self._set_app_envs()

        if os.path.exists(file_path_abs):
            proc = subprocess.Popen(
                [app_exe, file_path_abs],
                env=_envs,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
            )


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = Widget()
    window.resize(400, 400)
    window.show()
    sys.exit(app.exec_())
import os
import maya.cmds as mc

print('hey')
def tweak_launch(*args):

    print('Startup sequence running...')
    os.environ['mickey'] = '--------ebae--------'
    print(os.environ['mickey'])


mc.evalDeferred("tweak_launch()")
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None

added_files = [
         ('./scenes', 'scenes')
         ]

a = Analysis(['launch_maya.py'],
             pathex=[
             'D:/GitStuff/mb-armada/example_files/exe_bundle',
             'D:/GitStuff/mb-armada/dependencies/Qt.py',
             'D:/GitStuff/mb-armada/venv/Lib/site-packages'
             ],
             binaries=[],
             datas=added_files,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='bundle',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='bundle')
userSetup.py:

import os
import sys
import subprocess

from PySide2 import QtWidgets



class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)

        # GUI
        btn_launch = QtWidgets.QPushButton('launch maya')
        btn_launch.clicked.connect(self.on_launch)

        # Layout
        main_layout = QtWidgets.QHBoxLayout(self)
        main_layout.addWidget(btn_launch)
        self.setLayout(main_layout)

        # Root path exe vs ide
        if getattr(sys, 'frozen', False):
            self.root_path = sys._MEIPASS
        else:
            self.root_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))

    def _set_app_envs(self):

        _envs = os.environ.copy()
        _envs['MAYA_SCRIPT_PATH'] = os.path.join(self.root_path).replace('\\', '/')
        _envs['QT_PREFERRED_BINDING'] = 'PySide2'

        # Python path envs
        _python_path_list = [
            os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe'),  # insert mayapy here????
            os.path.join(self.root_path).replace('\\', '/')  # userSetup.py dir
        ]

        # PYTHONPATH exe vs ide
        if getattr(sys, 'frozen', False):
            # There is no PYTHONPATH to add so, so I create it here (Do I need this? Is there a diff way?)
            _envs['PYTHONPATH'] = os.pathsep + os.pathsep.join(_python_path_list)

        # Insert mayapy.exe into front of PATH
        sys_path_ = _envs['PATH']
        maya_py_path = os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe')
        sys_path = maya_py_path + os.pathsep + sys_path_
        _envs['PATH'] = sys_path

        else:
            _envs['PYTHONPATH'] += os.pathsep + os.pathsep.join(_python_path_list)

        # Insert mayapy???????
        # sys.path.insert(0, os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe'))

        return _envs

    def on_launch(self):


        # Maya file path
        file_path_abs = '{}/scenes/test.mb'.format(self.root_path).replace('\\', '/')
        print(file_path_abs)
        app_exe = r'C:/Program Files/Autodesk/Maya2020/bin/maya.exe'

        _envs = self._set_app_envs()

        if os.path.exists(file_path_abs):
            proc = subprocess.Popen(
                [app_exe, file_path_abs],
                env=_envs,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
            )


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = Widget()
    window.resize(400, 400)
    window.show()
    sys.exit(app.exec_())
import os
import maya.cmds as mc

print('hey')
def tweak_launch(*args):

    print('Startup sequence running...')
    os.environ['mickey'] = '--------ebae--------'
    print(os.environ['mickey'])


mc.evalDeferred("tweak_launch()")
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None

added_files = [
         ('./scenes', 'scenes')
         ]

a = Analysis(['launch_maya.py'],
             pathex=[
             'D:/GitStuff/mb-armada/example_files/exe_bundle',
             'D:/GitStuff/mb-armada/dependencies/Qt.py',
             'D:/GitStuff/mb-armada/venv/Lib/site-packages'
             ],
             binaries=[],
             datas=added_files,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='bundle',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='bundle')
捆绑包。规格:

import os
import sys
import subprocess

from PySide2 import QtWidgets



class Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(Widget, self).__init__(parent)

        # GUI
        btn_launch = QtWidgets.QPushButton('launch maya')
        btn_launch.clicked.connect(self.on_launch)

        # Layout
        main_layout = QtWidgets.QHBoxLayout(self)
        main_layout.addWidget(btn_launch)
        self.setLayout(main_layout)

        # Root path exe vs ide
        if getattr(sys, 'frozen', False):
            self.root_path = sys._MEIPASS
        else:
            self.root_path = os.path.join(os.path.dirname(os.path.realpath(__file__)))

    def _set_app_envs(self):

        _envs = os.environ.copy()
        _envs['MAYA_SCRIPT_PATH'] = os.path.join(self.root_path).replace('\\', '/')
        _envs['QT_PREFERRED_BINDING'] = 'PySide2'

        # Python path envs
        _python_path_list = [
            os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe'),  # insert mayapy here????
            os.path.join(self.root_path).replace('\\', '/')  # userSetup.py dir
        ]

        # PYTHONPATH exe vs ide
        if getattr(sys, 'frozen', False):
            # There is no PYTHONPATH to add so, so I create it here (Do I need this? Is there a diff way?)
            _envs['PYTHONPATH'] = os.pathsep + os.pathsep.join(_python_path_list)

        # Insert mayapy.exe into front of PATH
        sys_path_ = _envs['PATH']
        maya_py_path = os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe')
        sys_path = maya_py_path + os.pathsep + sys_path_
        _envs['PATH'] = sys_path

        else:
            _envs['PYTHONPATH'] += os.pathsep + os.pathsep.join(_python_path_list)

        # Insert mayapy???????
        # sys.path.insert(0, os.path.join('C:', os.sep, 'Program Files', 'Autodesk', 'Maya2020', 'bin', 'mayapy.exe'))

        return _envs

    def on_launch(self):


        # Maya file path
        file_path_abs = '{}/scenes/test.mb'.format(self.root_path).replace('\\', '/')
        print(file_path_abs)
        app_exe = r'C:/Program Files/Autodesk/Maya2020/bin/maya.exe'

        _envs = self._set_app_envs()

        if os.path.exists(file_path_abs):
            proc = subprocess.Popen(
                [app_exe, file_path_abs],
                env=_envs,
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                creationflags=subprocess.CREATE_NEW_PROCESS_GROUP
            )


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = Widget()
    window.resize(400, 400)
    window.show()
    sys.exit(app.exec_())
import os
import maya.cmds as mc

print('hey')
def tweak_launch(*args):

    print('Startup sequence running...')
    os.environ['mickey'] = '--------ebae--------'
    print(os.environ['mickey'])


mc.evalDeferred("tweak_launch()")
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None

added_files = [
         ('./scenes', 'scenes')
         ]

a = Analysis(['launch_maya.py'],
             pathex=[
             'D:/GitStuff/mb-armada/example_files/exe_bundle',
             'D:/GitStuff/mb-armada/dependencies/Qt.py',
             'D:/GitStuff/mb-armada/venv/Lib/site-packages'
             ],
             binaries=[],
             datas=added_files,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='bundle',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='bundle')

到目前为止,这似乎是可行的:我在默认设置中将PYTHONHOME和PYTHONPATH设置为Maya想要的目录。确保这些目录位于列表的第一位,否则当前虚拟环境仍将覆盖Maya的python

#.....

# Python path envs
_python_path_list = [
    'C:\\Program Files\\Autodesk\\Maya2020\\Python\\Lib\\site-packages',
    'C:\\Program Files\\Autodesk\\Maya2020\\Python\\DLLs',
    os.path.join(self.root_path, 'scripts').replace('\\', '/'),
    os.path.join(self.root_path, 'sourcessss', 'main_app')
]

# PYTHONPATH exe vs ide
if getattr(sys, 'frozen', False):

    _envs['PYTHONPATH'] = os.pathsep.join(_python_path_list)
    _envs['PYTHONHOME'] = 'C:\\Program Files\\Autodesk\\Maya2020\\bin'

#.....

到目前为止,这似乎是可行的:我在默认设置中将PYTHONHOME和PYTHONPATH设置为Maya想要的目录。确保这些目录位于列表的第一位,否则当前虚拟环境仍将覆盖Maya的python

#.....

# Python path envs
_python_path_list = [
    'C:\\Program Files\\Autodesk\\Maya2020\\Python\\Lib\\site-packages',
    'C:\\Program Files\\Autodesk\\Maya2020\\Python\\DLLs',
    os.path.join(self.root_path, 'scripts').replace('\\', '/'),
    os.path.join(self.root_path, 'sourcessss', 'main_app')
]

# PYTHONPATH exe vs ide
if getattr(sys, 'frozen', False):

    _envs['PYTHONPATH'] = os.pathsep.join(_python_path_list)
    _envs['PYTHONHOME'] = 'C:\\Program Files\\Autodesk\\Maya2020\\bin'

#.....