找不到模块错误没有名为mpl\u工具箱的模块

2024-03-29 04:45:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我面临一个错误modulenotfounderror没有名为mpl\u的模块。你知道吗

当我在pycharm中执行代码时,一切正常,但是当我使用cz\u freeze将其转换为.exe可执行文件时,它抛出了上面的错误。到目前为止,我已经尝试了以下代码。请帮我解决这个问题。 非常感谢您的帮助。你知道吗

主.py

   from mpl_toolkits.mplot3d import axes3d
   import matplotlib.pyplot as plt
   from matplotlib import cm

   fig = plt.figure()
   ax = fig.add_subplot(111, projection='3d')
   X, Y, Z = axes3d.get_test_data(0.05)
   cset = ax.contour(X, Y, Z, cmap=cm.coolwarm)
   ax.clabel(cset, fontsize=9, inline=1)

   plt.show()

设置.py

import sys
import os
import os.path
import numpy
import importlib


PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

base = None
console = False
if sys.platform == 'win32':
    base = "Win32GUI"


executables = [Executable("main.py",base = base,icon='logo.ico')]
additional_mods = ['numpy.core._methods', 'numpy.lib.format']
packages = ["idna"]
options = {
    'build_exe': {
        'packages':packages,
    'include_files':[
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
         ],
        'includes':additional_mods
    },

}

setup(
    name = "projectname",
    options = options,
    version = "1.0",
    description = 'Material Generator',
    executables = executables
)

Tags: installpathpyimportnumpybaseospackages