创建可在Windows和Mac上使用Mac运行的Python 3.7可执行文件

时间:2019-02-12 15:26:06

标签: python-3.x pandas

首先,我尝试在Mac上使用cx_Freeze库创建并执行。 setup.py看起来像这样:

from cx_Freeze import setup, Executable
# I am not sure if all of this is required but I keep getting errors of missing libraries one after another 
buildOptions = dict(packages = ['numpy.core._methods', 
'numpy.lib.format', "numpy.core._methods", "numpy", "pandas", 'jinja2',
                            "PyQt5.QtNetwork", 'encodings', 'asyncio'], 
                includes = ['numpy.core._methods', 'numpy.lib.format', 
"numpy.core._methods", "numpy", "pandas"], 
                excludes = [])

base = 'Console'

executables = [
    Executable('path/my_script.py', base=base, targetName = 'some-name')
]

setup(name='some-name',
  version = '0.1',
  description = 'some description',
  options = dict(build_exe = buildOptions),
  executables = executables)

我不断遇到缺少库的错误,我修复了一个,然后出现了另一个。在my-script.py中,我添加了这些导入,但不确定应该添加多少导入以及哪些导入才能停止出现错误。

import numpy.core._methods 
import numpy.lib.format
import packaging
import packaging.version
import packaging.specifiers
import packaging.requirements
import appdirs
import asyncio
import asyncio.base_futures
import asyncio.base_tasks
import asyncio.compat
import asyncio.base_subprocess
import asyncio.proactor_events
import asyncio.constants
import asyncio.selector_events
import jinja2.asyncsupport
import jinja2.ext
import jinja2
import numpy as np
import pandas as pd
import math
import itertools
import datetime

from dateutil.relativedelta import relativedelta
from pyxlsb import open_workbook

我无法解决的最新错误与以下行中的pandas Styler对象有关:

df.style.apply(highlight_values, axis=None)

其中highlight_values是为特定值着色并将颜色值保存到Excel中的函数。此行的cx_Freeze错误为:

File "/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py", 
line 739, in style
from pandas.io.formats.style import Styler
File "/anaconda3/lib/python3.6/site- 
packages/pandas/io/formats/style.py", line 55, in <module>
class Styler(object):
File "/anaconda3/lib/python3.6/site- 
packages/pandas/io/formats/style.py", line 115, in Styler
loader = PackageLoader("pandas", "io/formats/templates")
File "/anaconda3/lib/python3.6/site-packages/jinja2/loaders.py", line 
222, in __init__
from pkg_resources import DefaultProvider, ResourceManager, \
File "/anaconda3/lib/python3.6/site- 
packages/pkg_resources/__init__.py", line 957, in <module>
class Environment:
File "/anaconda3/lib/python3.6/site- 
packages/pkg_resources/__init__.py", line 961, in Environment
self, search_path=None, platform=get_supported_platform(),
File "/anaconda3/lib/python3.6/site- 
packages/pkg_resources/__init__.py", line 188, in 
get_supported_platform
plat = get_build_platform()
File "/anaconda3/lib/python3.6/site- 
packages/pkg_resources/__init__.py", line 393, in get_build_platform
plat = get_platform()
File "/anaconda3/lib/python3.6/sysconfig.py", line 689, in get_platform
get_config_vars(),
File "/anaconda3/lib/python3.6/sysconfig.py", line 550, in 
get_config_vars
_init_posix(_CONFIG_VARS)
 File "/anaconda3/lib/python3.6/sysconfig.py", line 421, in _init_posix
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_darwin_darwin'
logout

,并且在同一行中使用pyinstaller时,会出现不同的错误:

File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in 
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "/anaconda3/lib/python3.6/site- 
packages/PyInstaller/loader/pyimod03_importers.py", line 627, in 
exec_module
exec(bytecode, module.__dict__)
File "site-packages/pandas/io/formats/style.py", line 55, in <module>
File "site-packages/pandas/io/formats/style.py", line 120, in Styler
File "site-packages/jinja2/environment.py", line 830, in get_template
File "site-packages/jinja2/environment.py", line 804, in _load_template
File "site-packages/jinja2/loaders.py", line 113, in load
File "site-packages/jinja2/loaders.py", line 234, in get_source
File "site-packages/pkg_resources/__init__.py", line 1402, in 
has_resource
File "site-packages/pkg_resources/__init__.py", line 1455, in _has

NotImplementedError:无法针对未注册的加载器类型执行此操作 [82434]无法执行脚本

任何想法如何处理?我需要包含n项才能使样式成为exe?

0 个答案:

没有答案