25

Hi I am on OSx Mavericks, using python 2.7 and pip version 6.0.8 and setuptools version 12.2.

When I try to install my project I get warning messages but installs successfully

$ python setup.py install --user

if I use distutils I get below message which probably its setup doesn't have kwarg entry_points. /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py: 267: UserWarning: Unknown distribution option: 'entry_points' warnings.warn(msg)

but when I try to install using pip the following way, I get below error messages and install doesn't continues:

$ pip install --user --editable .

if I use pip even if I have distutils setup imported I get the below error message.

Obtaining file:///Users/Me/Development/pyclones/git-maildiff
    error in maildiff setup command: ("EntryPoint must be in 'name=module:attrs [extras]' format", 'git-maildiff=scripts.git-maildiff')
    Complete output from command python setup.py egg_info:
    error in maildiff setup command: ("EntryPoint must be in 'name=module:attrs [extras]' format", 'git-maildiff=scripts.git-maildiff')

    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /Users/Me/Development/pyclones/git-maildiff

whilst I have call to setup like this

setup(
    name='maildiff',
    version=VERSION,
    author='Sanjeev Kumar',
    author_email='myemail@gmail.com',
    packages=['emaildiff', 'emaildiff/mail',],
    py_modules=['maildiff_cmd', 'version', 'send'],
    data_files = ['VERSION'],
    scripts=['scripts/git-maildiff'],
    license='LICENSE',
    description='Package to email color git diff',
    long_description=open('README.md').read(),
    entry_points={
    'console_scripts':
        ['git-maildiff=scripts.git-maildiff']
                }
)

can anyone help me why I am getting this, I prefer to go with pip because i can use pip to uninstall it later, but I think their isn't any command like setup.py uninstall or remove.

Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
  • have you done `pip install --upgrade setuptools`? The `entry_points` keyword is listed under the [New and Changed `setup()` Keywords](https://pythonhosted.org/setuptools/setuptools.html#id8) so perhaps your version of setuptools is too old to include it? – Adam Smith May 17 '15 at 06:17
  • Are you sure, that `'git-maildiff=scripts.git-maildiff'` is valid? Not sure, but I think you have to give a method here: `'git-maildiff=scripts.git-maildiff:mymethod'` – cel May 17 '15 at 06:23

1 Answers1

41

The entry point you define in these two lines:

'console_scripts':
        ['git-maildiff=scripts.git-maildiff']

has a - in it, I'm not sure if that's supported (git-maildiff is not a valid Python module name). Further, it misses the function name to call: main.

You could first try adding main:

'console_scripts':
        ['git-maildiff=scripts.git-maildiff:main']

If that doesn't work, rename your script to remove the -. I think you can still leave git-maildiff as the entry-point name and just rename the module:

'console_scripts':
        ['git-maildiff=scripts.git_maildiff:main']

This should give you a git-maildiff script that calls the git_maildiff module. You'll have to rename your module file itself too.

Christian Aichinger
  • 6,989
  • 4
  • 40
  • 60
  • i need `-` because this is how git recognises a git command I have written . – Ciasto piekarz May 17 '15 at 06:32
  • 1
    As I wrote, your *script name* can include a dash, but our *module name* probably can't. Use `'gitmaildiff=scripts.gitmaildiff:main'`. – Christian Aichinger May 17 '15 at 06:45
  • aah, right I totally got it wrong in the beginning thinking that we are telling the script git-maildiff will go to scripts directory. now i got it working thanks. – Ciasto piekarz May 17 '15 at 07:17
  • Hello @Christian Aichinger , this console_scripts value doesn't seem to like me , if I use `git-maildiff` in the script then on the time of install it will create a wrapper that imports `pkg_resources` and then that `loads_entry_points` rather than the wrapper that I have created, If I used gitmaildiff it works fine ! why so ? and in case I use `git-maildiff` i get error message main takes two argument None given. – Ciasto piekarz May 17 '15 at 12:22
  • If you produce an egg or a wheel, git_maildiff.py will only be inside the egg/wheel, not an actual file in the file system. Thus setuptools doesn't call it directly, but uses pkg_resources. Your main must not take any arguments (i.e. signature `def main():`). Take everything you do in `if __name__ == '__main__':`, move it into main itself, and remove `main()`'s arguments. – Christian Aichinger May 17 '15 at 13:44
  • so you mean we cannot specify if an argument can be passed via `load_entry_points` ! – Ciasto piekarz May 17 '15 at 14:04
  • You use `sys.argv`, just like in a normal script. – Christian Aichinger May 17 '15 at 14:12
  • used it, though this sound like setuptools or distutils is not suitable for big project, I wanted to put logger in the check of `__name__=='__main__'` and was passing that logger to main. – Ciasto piekarz May 17 '15 at 16:59
  • Just move everything into main, using `global` if you need to declare a global logger: ``global logger; logger = ...``. – Christian Aichinger May 17 '15 at 18:11