Search code examples
pythontkinterpackagingpypi

Releasing a python package with tkinter for pip


I have build a small quiz using Tkinter in Python and I wish to release the game for all to play, so that people can just pip install and play the game.

I have gone through the docs to release a PyPi package, I released one, it gets successfully installed. However, I'm unable to launch the application from commandline nor can I look for the binary. I don't know where am I going wrong. Please help me out here.

My setup.py file looks like this

from setuptools import setup
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

with open(path.join(here, 'README.rst')) as f:
    long_description = f.read()

setup(
    name='py-quiz',
    version='0.1.1',
    description='Python based Quiz game.',
    long_description=long_description,
    author='Abhijit Nathwani',
    author_email='[email protected]',
    LICENSE='MIT',
    url='https://github.com/abhijitnathwani/PyQuiz',
    keywords='pyquiz tkinter'

)

To package it, I use

python setup.py sdist upload

The package is successfully added to PyPi package and I could install it using:

pip install py-quiz

The output of the installation:

Collecting py-quiz
  Downloading py-quiz-0.1.1.tar.gz
Installing collected packages: py-quiz
  Running setup.py install for py-quiz ... done
Successfully installed py-quiz-0.1.1

But then when i do,

user@somecomputer:~/PyQuiz$ py-quiz
py-quiz: command not found

How do I launch the game from command line? Please help me out here.

The application code is maintained here.


Solution

  • I finally solved the problem above by making the following changes. There must be a package created in the directory and the folder structure should be as follows:

    <Directory>
    |-setup.py
    |-dist
    |-LICENCSE
    |-readme
    |-<package-name>
     |-__init__.py
     |-__main__.py
     |-other files 
    

    and in the setup.py the following change should be

    entry_points={ 'console_scripts':['<command_name> = <package_name>.__main__:<function to be called>']

    In my case, it is as follows:

    entry_points={ 'console_scripts':['py-quiz = py_quiz.__main__:main']

    The main point is to create a package inside your project directory. This should solve major problems.