我想安装一个带有setuptools的脚本,并进行以下设置:
在我的开发目录中有文件
> setup.py和
> z_script.py.
z_script.py文件如下所示:
def main():
print "Running..."
而我的setup.py看起来像这样:
from setuptools import setup
setup(
name = 'z_script', version = '0.2',
entry_points = {"console_scripts": ["z_script = z_script:main"]},
)
当我运行python setup.py install时,脚本成功安装到正确的bin目录中.
但是,当我使用z_script运行脚本时,会发生错误:
Traceback (most recent call last):
File "./z_script", line 8, in <module>
load_entry_point('z-script==0.2', 'console_scripts', 'z_script')()
File "/home/woltan/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 318, in load_entry_point
File "/home/woltan/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2221, in load_entry_point
File "/home/woltan/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 1954, in load
ImportError: No module named z_script
bin目录可以通过PATH环境变量访问系统,并且在我发出z_scirpt时没有设置PYTHONPATH环境变量.
现在问我的问题:
我的设置有什么问题?为什么脚本找不到正确的模块?
解决方法:
您没有指示setuptools安装z_script.在py_modules关键字中使用find_packages
或列出z_script.
...
packages = find_packages(),
...
要么
...
py_modules = ['z_script'],
...