Skip to content

Instantly share code, notes, and snippets.

@calumroy
Last active February 24, 2020 10:03
Show Gist options
  • Save calumroy/0b1b3033dea708b9a544ff2dbb4c90ed to your computer and use it in GitHub Desktop.
Save calumroy/0b1b3033dea708b9a544ff2dbb4c90ed to your computer and use it in GitHub Desktop.
Create python package locally

Create a python package locally so you can pip install it.

Create your python script mycoolscript.py

Create a new directory with this layout

some_root_dir/
|-- README
|-- setup.py
|-- mycoolscript
|   |-- __init__.py
|   |-- mycoolscript.py
|-- tests
|-- |-- __init__.py
|-- |-- runall.py
|-- |-- test0.py

Create the setup.py file. E.g

import os
from setuptools import setup

# Utility function to read the README file.
# Used for the long_description.  It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "mycoolscript",
    version = "0.0.1",
    author = "Calum Meiklejohn",
    author_email = "[email protected]",
    description = ("Useful mycoolscript"),
    license = "BSD",
    keywords = "example documentation tutorial",
    url = "http://packages.python.org/mycoolscript",
    packages=['mycoolscript', 'mycoolscript'],
    long_description=read('README'),
    scripts=['mycoolscript/mycoolscript.py'],
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: BSD License",
    ],
)

Create a local dist package
python setup.py sdist --format=tar The package created will be in the dist folder as a .tar file Install the package cd into the dist folder and type pip install mycoolscript.tar

This is probably better done in a virtualenv

you can use pip install --force-reinstall if you need to play around with the libraries more and re-create the dist packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment