console_scripts入口点被忽略了?

时间:2012-11-07 13:47:07

标签: python console setuptools

我在Windows上使用setuptools(版本0.6c11),并指定通过console_scripts入口点安装的控制台脚本。它在Linux上运行良好,但在Windows下,使用MinGW编译器,没有安装脚本。我没有在安装输出中看到任何有问题的消息。

其他软件包,比如ipython,在运行setup.py install之后做得很好并且有.exe文件。

有人可以建议一种调试方法吗?

import setuptools
setup(
   # ...
   entry_points={
      'console_scripts':[
          'myprog = myMod:main'
      ]
   }
)

更新

根据Vinay提出的例子(谢谢!),我能够找出问题:如果模块安装在嵌套子目录中,则不会创建脚本:

import setuptools, os.path, shutil

SOURCE = '''
def main():
    print('Hello, world!')
'''

### ERROR: when level of subdir is > 1, script is not created
subdir='subdir/subdir2'

### OK: with single-level subdirectory, everything works just fine
# subdir='subdir'

def prepare():
    # remove previous source
    if os.path.exists('subdir'): shutil.rmtree('subdir')
    # create subdirs as necessary
    os.makedirs(subdir)
    with open(subdir+'/my_mod.py', 'w') as f: f.write(SOURCE)

prepare()

setuptools.setup(
    name = 'myprog',
    version = '0.1',
    url = 'http://dummy.com/',
    author = 'Me',
    author_email = 'me@dummy.com',
    py_modules=['my_mod'],
    package_dir={'':subdir},
    entry_points={
        'console_scripts':['myprog = my_mod:main']
   },
   zip_safe=False
)

我误解了package_dir的内容是什么?

1 个答案:

答案 0 :(得分:2)

嗯,这对我有用:

# This file is setup.py
import setuptools

SOURCE = '''
def main():
    print('Hello, world!')
'''

def prepare():
    with open('my_mod.py', 'w') as f:
        f.write(SOURCE)

prepare()

setuptools.setup(
    name = 'woo',
    version = '0.1',
    url = 'http://dummy.com/',
    author = 'Me',
    author_email = 'me@dummy.com',
    py_modules=['my_mod'],
    entry_points={
        'console_scripts':['myprog = my_mod:main']
   }
)

当我在virtualenv中运行它时:

(venv) C:\temp\exemplar>python setup.py install
running install
running bdist_egg
running egg_info
writing woo.egg-info\PKG-INFO
writing top-level names to woo.egg-info\top_level.txt
writing dependency_links to woo.egg-info\dependency_links.txt
writing entry points to woo.egg-info\entry_points.txt
reading manifest file 'woo.egg-info\SOURCES.txt'
writing manifest file 'woo.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib
copying my_mod.py -> build\lib
creating build\bdist.win32
creating build\bdist.win32\egg
copying build\lib\my_mod.py -> build\bdist.win32\egg
byte-compiling build\bdist.win32\egg\my_mod.py to my_mod.pyc
creating build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\entry_points.txt -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\woo-0.1-py2.7.egg' and adding 'build\bdist.win32\egg' to it
removing 'build\bdist.win32\egg' (and everything under it)
Processing woo-0.1-py2.7.egg
creating c:\temp\venv\lib\site-packages\woo-0.1-py2.7.egg
Extracting woo-0.1-py2.7.egg to c:\temp\venv\lib\site-packages
Adding woo 0.1 to easy-install.pth file
Installing myprog-script.py script to C:\temp\venv\Scripts
Installing myprog.exe script to C:\temp\venv\Scripts

Installed c:\temp\venv\lib\site-packages\woo-0.1-py2.7.egg
Processing dependencies for woo==0.1
Finished processing dependencies for woo==0.1

(venv) C:\temp\exemplar>pip uninstall woo
Uninstalling woo:
  c:\temp\venv\lib\site-packages\woo-0.1-py2.7.egg
  c:\temp\venv\scripts\myprog-script.py
  c:\temp\venv\scripts\myprog.exe
Proceed (y/n)? y
  Successfully uninstalled woo

(venv) C:\temp\exemplar>

<强>更新

您的问题是没有使用正确的路径分隔符:使用

子目录= '子目录\\ subdir2'

为我工作。当然,您应该使用os.path.join()