我需要对我的python代码做什么才能让它成为一个模块?

有人可以告诉我,我将错误打包成模块:
https://github.com/xamox/python-zxing.

我的setup.py如下:

#!/usr/bin/env python

from distutils.core import setup

setup(
    name='zxing',
    version='0.1',
    description="wrapper for zebra crossing (zxing) barcode library",
    url='http://simplecv.org',
    author='Ingenuitas',
    author_email='public.relations@ingenuitas.com',
    packages=['zxing'],
)

我想做“进口zxing”.我做setup.py install,把它放在/usr/local/lib/python2.7/dist-packages/中,但导入zxing不起作用.

我收到以下错误:

In [1]: import zxing.zxing
---------------------------------------------------------------------------
ResolutionError                           Traceback (most recent call last)
/home/xamox/<ipython-input-1-9ff7d0755c55> in <module>()
----> 1 import zxing.zxing

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, requires, script_name)
    465         ns.clear()
    466         ns['__name__'] = name
--> 467         self.require(requires)[0].run_script(script_name, ns)
    468 
    469 

/usr/lib/python2.7/dist-packages/pkg_resources.pyc in run_script(self, script_name, namespace)
   1192         script = 'scripts/'+script_name
   1193         if not self.has_metadata(script):
-> 1194             raise ResolutionError("No script named %r" % script_name)
   1195         script_text = self.get_metadata(script).replace('\r\n','\n')
   1196         script_text = script_text.replace('\r','\n')

ResolutionError: No script named 'zxing.py'

解决方法:

查看您在评论中显示的URL的堆栈跟踪:

/usr/local/bin/zxing.py in <module>()
      3 __requires__ = 'zxing==0.1'
      4 import pkg_resources
----> 5 pkg_resources.run_script('zxing==0.1', 'zxing.py')

这表明它正在尝试从/usr/local/bin/zxing.py加载一些guff,其中包含的代码不在当前版本中,例如“import pkg_resources”.看起来像以前的实验中的碎片.摆脱它.

现在你有一个干净的甲板:

有一个空的__init__.py和一个源文件包似乎毫无意义.我建议您删除__init__.py并删除所有其他实验的痕迹(尤其是“构建”目录).如果有一个文件夹/usr/local/lib/python2.7/dist-packages/zxing,请将其删除.

上一篇:python – pip不安装在setup()中声明的依赖项需要参数


下一篇:如果没有安装setuptools怎么办?