how to create a python module
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
README.md

README.md

tutorial-python-module

about

how to create a python module.

this is a tutorial by aarón montoya-moraga. it is based on classes i took at nyu itp.

tutorial

python modules are collections of functions, that live on a single .py file, and can be imported in other python scripts, using import.

your module should live on one .py file. i suggest using github to have a verson control system and online backup.

create a setup.py file, that includes:

  • name
  • version
  • url
  • author
  • description
  • license
  • packages
  • install_requires
  • package_data

to distribute, do on terminal

python setup.py sdist
twine upload dist/name-x.y.z.tar.gz

installing python modules

we will use two python modules to install other modules: pip and virtualenv. pip is the recommended tool for installing python packages.

first, install pip and virtualenv globally on your machine.

when you want to use python on your software project, we will create a virtual environment where all the python dependencies will live. go to your terminal and create a virtualenv with the command-line-tool virtualenv.

in this example, we will call env our virtual environment

virtualenv env

to make the python interpreter aware of this virtual environment, we have to activate it

source env/bin/activate

your terminal should now say (env) at the beginning of each new line. this means that the environment is activated.

to install packages on this virtual environment, use pip install.

in this example we will be installing numpy

pip install numpy

when you want to quit the virtual environment, deactivate it

deactivate

references

thanks

  • allison parrish: for making me learn and love python and computer-generated poetry, for her great classes.
  • sam lavigne: for making me appreciate software libraries as art, for his great tutorials.