<jupyter_start><jupyter_text>Pypi & PipPyPi is short form for Python Package Index (PyPI). PyPI helps you find and install open source software developed and shared by the Python community. All the python packages are distributed to python community through pypi.org . These packages are called as Distributed or intallable packages. To install any distributed or installable package we use command called Pip.<jupyter_code>pip install <package-name>

pip install requests<jupyter_output><empty_output><jupyter_text>you can also specify which version of python package to install in the command.<jupyter_code>pip install <package-name>==<version>

pip install requests==2.1.0<jupyter_output><empty_output><jupyter_text>How does pip install work?Every package/distribution that is being installed will have a setup.py. When you call pip install  that is nothing but python setup.py build and python setup.py install    What happens in this flow, with python setup.py build, it will download all the code of package to build folder installing any dependant packages, after that it will build a binary wheel specifically for your machine out of the source. Then it needs to determine which library directory to install the package in—the system's, the user's, or a virtualenv's? This is controlled by sys.prefix, which in turn is controlled by pip's executable path and the PYTHONPATH and PYTHONHOME environment variables. Finally, it moves the wheel files into the appropriate library directory, and compiles the python source files into bytecode for faster execution.<jupyter_code># sample setup.py

import os
from setuptools import setup, find_packages

setup(
    name='<package_name>',
    version='0.3.1',
    packages=find_packages(exclude=['tests', 'tests.*']),
    include_package_data=True,
    description='A brief description of your package',
    long_description=README,
    url='<your package github repo url>',
    author='<author name>',
    author_email='<Author email>',
    classifiers=[
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
    ],
    install_requires=[
        <list of any other packages that needs to be installed.>
    ],
)<jupyter_output><empty_output><jupyter_text>VirtualenvA Virtual Environment is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects. It enables multiple side-by-side installations of Python, one for each project. Following are the commands to install virtualenv. On macOS and Linux:<jupyter_code>python3 -m pip install --user virtualenv<jupyter_output><empty_output><jupyter_text>On Windows:<jupyter_code>py -m pip install --user virtualenv<jupyter_output><empty_output><jupyter_text>We create vitrualenv using the following commands On macOS and Linux:<jupyter_code>python3 -m venv env<jupyter_output><empty_output><jupyter_text>On Windows:<jupyter_code>py -m venv env<jupyter_output><empty_output><jupyter_text>Before you can start installing or using packages in your virtual environment you’ll need to activate it. To activate the environment use the following commandsOn macOS and Linux:<jupyter_code>source env/bin/activate<jupyter_output><empty_output><jupyter_text>On Windows:<jupyter_code>.\env\Scripts\activate<jupyter_output><empty_output><jupyter_text>Following are some important commands when we use virtualenv> pip freeze shows packages YOU installed via pip in that environment> pip freeze > requirements.txt  used to write the installed packages into the file.> pip install -r requrements.txt  Used to install all the packages inside requirements  Create your own packageWe will see how to publish a simple helloworld as a pypi package. I'm creating a simple package with hellow as a folder and to make it a package I'm adding __init__.py to it.Inside that folder I'm creating a simple file called greeting and inside my greeting file, I'm adding a simple function called hello_world that prints hello_world<jupyter_code>helloworld/
├── hellow
   ├── __init__.py
   └── greeting.py


1 directory, 2 files
# in greeting.py

def hello_world():
    print ("hello world")<jupyter_output><empty_output><jupyter_text>As discussed earlier we need setup.py file to make a python package into a distributed package. So I'm creating a setup.py file parallet to hellow folder. In my setup.py I'll add corresponding information required for that package.<jupyter_code>├── hellow
│   ├── __init__.py
│   └── greeting.py
└── setup.py

1 directory, 3 files

# in setup.py

import os
from setuptools import setup, find_packages

setup(
    name='chaitu_210_hw_greeting',
    version='1.0',
    packages=['hellow'],
    include_package_data=True,
    description='A brief description of your package',
    long_description='',
    url='https://www.test.com/',
    author='chaitanya',
    author_email='<EMAIL>',
    classifiers=[
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
    ],
    install_requires=[
    ],
)<jupyter_output><empty_output><jupyter_text>Before make our python package as a distributed package, we will create an account in pypi.org, you can create an using the following link https://pypi.org/account/register/ Now to upload our package we run the following commands<jupyter_code>> python setup.py bdist_wheel sdist
> pip install twine
> twine upload dist/*<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08181069958847736, 'fraction_numerical': 0.005102880658436214, 'mean_word_length': 4.6103416435826405, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 65, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '16069', 'license': 'Apache-2.0', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1649, 'n_words': 668, 'path': 'notebooks/8_packaging_vnenv.ipynb', 'repo_name': 'inovizz/python-for-devops', 'size': '6087'}