No module named trainer

ぐ巨炮叔叔 提交于 2019-12-23 08:05:52

问题


I have a very simple trainer that follows the sample directory structure:

/dist
  __init__.py
  setup.py
  /trainer
    __init__.py
    task.py

Under the /dist directory, runs fine locally:

$ gcloud ml-engine local train 
    --package-path=trainer
    --module-name=trainer.task

Now, when trying to deploy it, under the /dist directory and this command:

$ gcloud ml-engine jobs submit training testA
    --package-path=trainer
    --module-name=trainer.task
    --staging-bucket=$JOB_DIR
    --region us-central1

It gives me an error "No moduled name trainer"

INFO    2017-04-13 12:28:35 -0700   master-replica-0        Installing collected packages: pyyaml, scipy, scikit-learn, trainer
INFO    2017-04-13 12:28:38 -0700   master-replica-0        Successfully installed pyyaml-3.12 scikit-learn-0.18.1 scipy-0.18.1 trainer-0.1
INFO    2017-04-13 12:28:38 -0700   master-replica-0        Running command: python -m trainer.task
ERROR   2017-04-13 12:28:38 -0700   master-replica-0        /usr/bin/python: No module named trainer

EDIT: here is the content of setup.py

from setuptools import find_packages
from setuptools import setup
REQUIRED_PACKAGES = [
    'pyyaml',
    'scipy==0.18.1',
    'scikit-learn'
]
setup(
    name='trainer',
    version='0.1',
    install_requires=REQUIRED_PACKAGES,
    include_package_data=True,
    description='Classifier test'
)

What am I doing wrong?

Thanks,

M


回答1:


You are missing an important line in your setup.py, the packages argument to the setup function invocation (cf these instructions). Try this:

from setuptools import find_packages
from setuptools import setup
REQUIRED_PACKAGES = ['pyyaml','scipy==0.18.1','scikit-learn']
setup(
    name='trainer',
    version='0.1',
    install_requires=REQUIRED_PACKAGES,
    packages=find_packages(),
    include_package_data=True,
    description='Classifier test'
)

I've updated the CloudML Engine docs (may take a few days to propagate).

I replicated your command using --package-path=trainer and the above changes, and things run properly in the cloud.

Finally, although it is harmless, the __init__.py in dist/ is unnecessary and can safely be removed.



来源:https://stackoverflow.com/questions/43400599/no-module-named-trainer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!