import librosa in google cloud ml

﹥>﹥吖頭↗ 提交于 2019-12-02 02:21:30

You need to install the python-tk package by modifying your setup.py to pull it in as a dependency. Since it is an apt package you can modify your setup.py file to install it via apt. Here's what a sample setup.py file might look like.

import logging
import subprocess
from setuptools import find_packages
from setuptools import setup
from setuptools.command.install import install

# Some custom command to run during setup. Typically, these commands will
# include steps to install non-Python packages.
#
# First, note that there is no need to use the sudo command because the setup
# script runs with appropriate access.
# Second, if apt-get tool is used then the first command needs to be 'apt-get
# update' so the tool refreshes itself and initializes links to download
# repositories.  Without this initial step the other apt-get install commands
# will fail with package not found errors. Note also --assume-yes option which
# shortcuts the interactive confirmation.
#
# The output of custom commands (including failures) will be logged.


class CustomCommands(install):
  """A setuptools Command class able to run arbitrary commands."""

  def RunCustomCommand(self, command_list):
    print 'Running command: %s' % command_list
    p = subprocess.Popen(
        command_list,
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT)
    # Can use communicate(input='y\n'.encode()) if the command run requires
    # some confirmation.
    stdout_data, _ = p.communicate()
    print 'Command output: %s' % stdout_data
    logging.info('Log command output: %s', stdout_data)
    if p.returncode != 0:
      raise RuntimeError('Command %s failed: exit code: %s' %
                         (command_list, p.returncode))

  def run(self):
    self.RunCustomCommand(['apt-get', 'update'])
    self.RunCustomCommand(
          ['sudo', 'apt-get', 'install', '-y', 'python-tk'])

    install.run(self)


REQUIRED_PACKAGES = []

setup(
    name='my-package',
    version='0.1.1',
    author='Author',
    author_email='author@gmail.com',
    install_requires=REQUIRED_PACKAGES,
    packages=find_packages(),
    description='Description',
    requires=[],
    cmdclass={
        # Command class instantiated and run during install scenarios.
        'install': CustomCommands,
    })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!