I am running Google cloud ML and when I try to import librosa I get the error:
ImportError: No module named _tkinter, please install the python-tk pa
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,
})