Import module

from monnod import nom1, nom2 as fct
# -> direct access to names, renaming with as

import monnode
# -> access via monmod.nom1

Note: modules and packages searched in python path (cf sys.path)

Create Public Module

conda, pypi, github

Step 0/4: Check your package name

Go to https://pypi.python.org/pypi/your_package_name to see your package name is valid

Step 1/4: Make your module 1

1.1 pip install cookiecutter

1.2 cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git

1.3 Fill all necessary information

full_name [Audrey Roy Greenfeld]:
email [aroy@alum.mit.edu]:
github_username [audreyr]:
project_name [Python Boilerplate]:
project_slug []:
project_short_description:
release_date []:
pypi_username []:
year [2016]:
version [0.1.0]:
use_pypi_deployment_with_travis [y]:

It will create a directory

|- LICENSE
|- README.md
|- TODO.md
|- docs
|   |-- conf.py
|   |-- generated
|   |-- index.rst
|   |-- installation.rst
|   |-- modules.rst
|   |-- quickstart.rst
|   |-- sandman.rst
|- requirements.txt
|- your_package
|   |-- __init__.py
|   |-- your_package.py
|   |-- test
|       |-- models.py
|       |-- test_your_package.py
|- setup.py

Step 2/4: Git

Step 3/4: Pypi 3

1. Create your Pypi Account

2. Create a .pypirc configuration file in $HOME directory

[distutils]
index-servers =
  pypi

[pypi]
repository=https://pypi.python.org/pypi
username=your_username
password=your_password

3. Change your MANIFEST.in

recursive-include project_folder *

4. Upload your package to PyPI

python setup.py register -r pypi
python setup.py sdist upload -r pypi

Step 4/4: Conda 2

1. Install conda tools

conda install conda-build
conda install anaconda-client

2. Build a simple package with conda skeleton pypi

cd your_package_folder
mkdir conda
cd conda
conda skeleton pypi your_package

This creates a directory named your_package and three skeleton files in that directory

|- your_package
|   |-- bld.bat
|   |-- meta.yaml
|   |-- build.sh

3. Build your package

conda build your_package

# convert to all platform
conda convert -f --platform all
  C:\Anaconda\conda-bld\win-64\your_package-0.1.1-py27_0.tar.bz2

4. Upload packages to Anaconda

anaconda login
anaconda upload linux-32/your_package.tar.bz2
anaconda upload linux-64/your_package.tar.bz2
anaconda upload win-32/your_package.tar.bz2
anaconda upload win-64/your_package.tar.bz2

Create Private Module

Step 1: Make your module 1

1.1 pip install cookiecutter

1.2 cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git

1.3 Fill all necessary information

full_name [Audrey Roy Greenfeld]:
email [aroy@alum.mit.edu]:
github_username [audreyr]:
project_name [Python Boilerplate]:
project_slug []:
project_short_description:
release_date []:
pypi_username []:
year [2016]:
version [0.1.0]:
use_pypi_deployment_with_travis [y]:

Step 2: Build your module

Change your MANIFEST.in

recursive-include project_folder *

Build your module with setup.py

cd your_project_folder

# build local
python setup.py build
> It will create a new folder in
> $PYTHON_HOME/Lib/sites-packages/your_project_name-0.1.0-py2.7.egg

# build distribution
python setup.py sdist
> It will create a zip file in $PROJECT_FOLDER/dist

Step 3: Usage your module

In the same machine

import your_project_name

In other machine

Python: Build & Install Local Package with Conda

Here is a step by step tutorial about building a local module package & install it from a custom channel 1

Step 1: Make a setup folder for your package with cookkiecutter

on terminal:


mkdir build
cd build
pip install cookiecutter
cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git

Fill all necessary information

full_name [Audrey Roy Greenfeld]:
email [aroy@alum.mit.edu]:
github_username [audreyr]:
project_name [Python Boilerplate]:
project_slug []:
project_short_description:
release_date []:
pypi_username []:
year [2016]:
version [0.1.0]:
use_pypi_deployment_with_travis [y]:

It will create a directory

|- LICENSE
|- README.md
|- TODO.md
|- docs
|   |-- conf.py
|   |-- generated
|   |-- index.rst
|   |-- installation.rst
|   |-- modules.rst
|   |-- quickstart.rst
|   |-- sandman.rst
|- requirements.txt
|- your_package
|   |-- __init__.py
|   |-- your_package.py
|   |-- test
|       |-- models.py
|       |-- test_your_package.py
|- setup.py

Copy your real package into directory above & replace the package has been generated by cookkiecutter

Add this line to MANIFEST.in

recursive-include project_folder *

Step 2: Build conda package

mkdir conda
cd conda
mkdir channel
git clone https://github.com/hunguyen1702/condaBuildLocalTemplate.git
mv condaBuildLocalTemplate your_package_name #Which ones you have filled in `project_name` above
cd your_package_name
rm -rf .git README.md

Edit the file meta.yaml with the instruction inside it

cd ..
conda build your_package_name

Step 3: Create custom channel and install from local package

Create a channel directory

cd channel

Convert your_package you've built to all platform

conda convert --platform all ~/anaconda/conda-bld/linux-64/your_package_0.1.0-py27_0.tar.bz2

and this will create:

channel/
linux-64/
   package-1.0-0.tar.bz2
linux-32/
   package-1.0-0.tar.bz2
osx-64/
   package-1.0-0.tar.bz2
win-64/
   package-1.0-0.tar.bz2
win-32/
   package-1.0-0.tar.bz2

Register your package to your new channel

cd ..
conda index channel/linux-64 channel/osx-64 channel/win-64

Veriy your new channel

conda search -c file://path/to/channel/ --override-channels

If you see your_package's appearance, so it's worked

After that if you want to install that package from local, run this command:


conda install --use-local your_package

and when you want to create environment with local package from file, you just have export environment to .yml file and add this channels section before the dependencies section:


channels:
- file://path/to/your/channel/