The basics of creating an installable Python package.
To install this package first activate the appropriate conda environment, then, in the same directory as setup.py
run the command:
pip install -e .
This will install example_project
in your Python environment as an "editable" installation (hence the -e
). This means that you can edit the project's source files, and those changes will manifest without you needing to reinstall example_project
. You can now use it as:
from example_project import returns_one
from example_project.functions_a import hello_world
from example_project.functions_b import multiply_and_sum
To change then name of the project, do the following:
- change the name of the directory
example_project/
to your project's name (it must be a valid python variable name, e.g. no spaces allowed) - change the
PROJECT_NAME
insetup.py
to the same name - install this new package (
pip install -e .
)
If you changed the name to, say, my_proj
, then the usage will be:
from my_proj import returns_one
from my_proj.functions_a import hello_world
from my_proj.functions_b import multiply_and_sum
You can read more about the basics of creating a Python package here.