3

I wrote a small command-line utility in Python. I also created setup.py script:

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

config = {
    'name': 'clitool',
    'author': 'aa',
    'author_email': 'ww',
    'version': '1.0-rc',
    'install_requires': ['nose'],
    'packages': [],
    'scripts': ['clitool']
}

setup(**config)

When I call:

setup.py install

my script copied to C:\Python34\Scripts path. This path is in the PATH variable, but Windows when I try to start my clitool from some direcory writes:

"clitool" not recognized as an internal or external command

It's possible to run from any directory, only the files from C:\Python34\Scripts with the exe extension.
But my script is copied as a file without extension and in Windows it does not run it.

5
  • Are you running this from Windows Explorer or cmd.exe? Have you tried clitool.py? It should have a .py extension (although there are others) Commented Jun 29, 2015 at 9:47
  • @cdarke, clitool.py is works, but I wanted to write so that the utility can be called without .py extension Commented Jun 29, 2015 at 9:52
  • Why? On Windows (unlike UNIX/Linux/OS X) the shell (Windows Explorer, cmd.exe, powershell) cannot tell which type a file is unless you set its file extension. The shell uses that as a lookup into the Windows registry to discover which program should be run. There is a default, but you would have to write a .cmd file to run your python. Is that what you want? Commented Jun 29, 2015 at 9:56
  • No, I wanted to understand how utilities like django-admin works Commented Jun 29, 2015 at 10:00
  • 1
    The entry_points example in this link may work Commented Jun 29, 2015 at 10:03

1 Answer 1

5

Solution:

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

config = {
    'name': 'clitool',
    'author': 'aa',
    'author_email': 'ww',
    'version': '1.0-rc',
    'install_requires': ['nose'],
    'packages': [],    
    'entry_points' : {
        'console_scripts': ['clitool=clitool.cli:main'],
    }
}

setup(**config)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.