已收到“在'< packageName>'中找不到”__main__“模块用python包 [英] Received 'can't find '__main__' module in '<packageName>' with python package

查看:955
本文介绍了已收到“在'< packageName>'中找不到”__main__“模块用python包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在野外释放我的第一个Python包,我成功地在PyPi上设置它,并能够做一个 pip install 。当我尝试通过命令行( $ python etlTest )运行包时,我收到以下错误:

I'm trying to release my first Python package in the wild and I was successful in setting it up on PyPi and able to do a pip install. When I try to run the package via the command line ($ python etlTest), I receive the following error:

/ usr / bin / python:在'etlTest'中找不到'__main__'模块

直接从我的IDE运行代码,它的工作没有问题。我使用Python 2.7和 __ init __。py 脚本在需要。

When I run the code directly from my IDE, it works without issue. I am using Python 2.7 and have __init__.py scripts where required. What do I need to do to get this working?

推荐答案

我可以很容易地复制你的问题,实际上即使不使用你的包:

I can easily replicate your problem, actually even without using your package:

$ python empty
.env/bin/python: can't open file 'empty': [Errno 2] No such file or directory
$ mkdir empty
$ python empty
.env/bin/python: can't find '__main__' module in 'empty'
$ python Empty
.env/bin/python: can't find '__main__' module in 'Empty'

所以你不是调用你的库,你只是给了Python解释器一个不存在的脚本名称,如果在工作目录中有一个类似命名的目录(不区分大小写),它试图执行它。

So you are not calling your library at all, you are just giving the Python interpreter a nonexistent script name, which in case there is a like-named directory (case-insensitive even) in the working directory it tries to execute it.

我可以从PyPi安装您的软件包很好,可以导入它,但似乎没有任何入口点对于它,没有什么有用的在顶层导出,没有可执行脚本添加到Python bin:

I was able to install your package from PyPi just fine and can import it alright, but there doesn't seem to be any entry point to it, nothing useful is exported at the top level and no executable scripts are added to Python bin:

>>> import etltest
>>> dir(etltest)
['__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__',
'__path__', '__version__']

从您的文档快速启动不起作用:

$ python .env/lib/python2.7/site-packages/etltest/etlTest.py
2014-07-13 17:19:56,831 - settings - DEBUG - Attempting to load .env/lib/python2.7/site-packages/.etltest-settings.yml
2014-07-13 17:19:56,832 - settings - WARNING - No such file or directory .env/lib/python2.7/site-packages/.etltest-settings.yml
2014-07-13 17:19:56,832 - settings - DEBUG - Attempting to load .env/lib/python2.7/site-packages/.etltest-settings.yml
2014-07-13 17:19:56,832 - settings - WARNING - No such file or directory .env/lib/python2.7/site-packages/.etltest-settings.yml
2014-07-13 17:19:56,832 - settings - WARNING - Could not find settings file in .env/lib/python2.7/site-packages/.etltest-settings.yml,.env/lib/python2.7/site-packages/.etltest-settings.yml. Using defaults where present.
Traceback (most recent call last):
  File ".env/lib/python2.7/site-packages/etltest/etlTest.py", line 73, in <module>
    main(sys.argv[1:])
  File ".env/lib/python2.7/site-packages/etltest/etlTest.py", line 22, in main
    SettingsManager().first_run_test()
  File ".env/lib/python2.7/site-packages/etltest/utilities/settings_manager.py", line 29, in __init__
    self.app_name = etltest_config['app_name']
KeyError: 'app_name'

为了分配。您可能希望清理一些开发环境的依赖项,并阅读 Setuptools入口点提供适当的命令行可执行文件与您的包。它也不应该运行在调试模式默认情况下,如果它不是某种测试版本。

I'd say your package is not apt for ditribution yet. You might want to clean up some dependencies on your development environment and read upon Setuptools entry points to provide proper command line executables along with your package. Also it shouldn't run in debug mode by default if it's not some kind of a testing release.

这篇关于已收到“在'&lt; packageName&gt;'中找不到”__main__“模块用python包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆