Skip to content
Snippets Groups Projects
Commit a93060b1 authored by bergma72's avatar bergma72
Browse files

Update DTTD_Python_Package.ipynb

parent 29bc5911
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:6445e338 tags:
%% Cell type:markdown id:0dec5833 tags:
## Creating a Python Package ##
### By: QSIDE JUSTFAIR 2023
----------------------------------------------------
%% Cell type:markdown id:0c128f8e tags:
## Introduction
Have you ever made a bunch of cool Python functions, but find yourself copying your code over and over again onto new documents? You can solve this problem by creating a Python package. In this tutorial, we’ll walk you through how to create your own Python package!
%% Cell type:markdown id:3d3bf097 tags:
### Step 1: Creating Your File Structure
The basic file structure for creating a package is as follows:
* Create your setup.py
* This file is used to install your package
* Create a folder with your package name
* Inside the folder, have the following python files:
* __init__.py()
* This file sets up your package
* Python_files_you_want.py
* You can have any number of other .py files
Here's a useful exampe:
https://github.com/colbrydi/CMSE802_Project_Template
%% Cell type:markdown id:ff0a6055 tags:
### Step 2: Creating setup.py
Setup.py is one of the essential Python files for a package to work. The important things to do here are declare the name of your package and all packages that are used by your package (for example, if you use numpy in one of your .py files, you’ll need to add numpy to your install_requires list.
%% Cell type:markdown id:d71d545b tags:
Here's an example of how to create a setup.py:
%% Cell type:code id:bb4e68e3 tags:
``` python
python
from setuptools import setup
setup(
name='JUSTFAIR_Tools',
version='0.1dev',
packages= ['JUSTFAIR_Tools'],
license='General Public License 3.0',
install_requires = ['matplotlib', 'pandas', 'numpy']
#long_description=open('README.md').read(),
)
```
%% Cell type:markdown id:12822d98 tags:
***OPTIONAL: there is another way to create the environment with a makefile and an environment.yml, the Github example link does this***
%% Cell type:markdown id:42b6e46b tags:
### Step 3: Creating an init.py
Next, we’ll need to enter our package folder and create the __init__.py. This file can be blank, but if you want some of your python files to come pre-loaded, import them here with
* From package_name.file_name import function_name
* you can do import * for all functions in the file
* Additionally, you can import files in your document as well if not done in the init file.
%% Cell type:markdown id:408b017b tags:
##### That’s it! All you need to do now is impoort your package with
**import packagename**
%% Cell type:code id:9b96dae7 tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment