Giter Club home page Giter Club logo

make_a_python_package's Introduction

How to package your python code

At some point, you may want to make your python module(s) available as a package. Let's take the most simple possible package, with only one function hello_world() which just writes "Hello world!" to the console. Lets make it available as a pip package called helloworld.

Make your code pip-installable from source

First, put your source code in a folder with the name of the package (helloworld). In the same directory, write a setup.py file with the following structure:

from setuptools import setup
setup(name='helloworld',
    version='0.1',
    description='A trivial hello world package for learning how to make a pip-installable python package',
    url='http://github.com/Mchristos/hello_world',
    author='mChristos',
    license='MIT',
    packages=['helloworld'],
    zip_safe=False)

In this case we just put our hello world function in a file called __init__.py inside the helloworld directory.

Now you can use the following pip command to install your package.

pip install .

The same statement with a -e flag makes changes in the source code immediately available on importing the package

pip install -e . 

Now, your package is available on your system. In your python console, test it by doing:

>>> import helloworld
>>> helloworld.hello_world()
### Hello world!

make_a_python_package's People

Contributors

mchristos avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.