Upload Python Package To pypi.org On Linux

Upload Python Package On Pypi.org From Linux

From Almost Last 7 Years Python Is High In Demand Because Writing Program In Python Language Is Quite Easy. Approximately Thousands Of Package Are Available on PyPI.org Website Which Is One Reason For Make Python Language Favorite Among Programmers. Upload Or Publish Your Open-Source Python Package On Pypi.org Website Is Simple With The Use Of Twine And Wheel on Linux Operating System Like Ubuntu, Kali, Arch, Fedora, etc.

Steps To Upload/Publish Python Package On Pypi.org:-

  • Create An Account On PyPi.org
  • Make A File In Home Directory With Name .pypirc
  • Create A Setup.py File Inside Your Package.
  • Build A Wheel File Of Package Using pip
  • Upload To PyPi Website Using Terminal

Step 1:- Create Account On PyPi Website

Go To PyPi.org And Register Account For Publish/Upload A Package. After Creating Account Copy Your Username.

Step 2:- Make A File In Home Directory With Name .pypirc

  • Moving Furter, Create A File With Name .pypirc And Place In Inside Home Directory Of Linux. As Shown In the Image Below:-
  • Create .pypirc File in Linux
  • Select And Edit .pypirc File. Copy Content As Shown In Below And Paste in .pypirc File. Replace Your_Username With Your PyPi Username.
  • Content For /home/user/.pypirc File:-
    [distutils] 
    index-servers=pypi
    [pypi] 
    repository = https://upload.pypi.org/legacy/ 
    username = Your_Username
    

Create A Setup.py File Inside Your Package.

Make Sure Your Python Package Is Working Properly. After That Create A setup.pyFile Inside Your Python Package. As Shown In Below In Directory Tree.

Pacakge_Dir/
------- __init__.py
------- setup.py

Now Copy Content As Shown In Below And Paste In setup.py File. Make Changes In Setup.py According To Your Package Detail.

import setuptools

setuptools.setup(
    name="nse", 
    version="0.2.1",
    author="Shivjeet Singh Bhullar",
    author_email="bhullarshivjeet@gmail.com",
    description="Get Live Data From Nse And Filter It According To Your Choice",
    long_description="You Can Use Readme.md File Here",
    long_description_content_type="text/markdown",
    url="Not Require",
    packages=setuptools.find_packages(),
    install_requires=["pi7db==0.3.8",'beautifulsoup4','pandas','matplotlib'],
    classifiers=[
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
        "Operating System :: OS Independent",
        "Topic :: Database"
    ],
    python_requires='>=3.6',
)

Build A Wheel File Of Package Using pip

After Setup.py, Create A Wheel File Of Package. For Create Wheel File You Need To Install A Package wheel


Install Wheel And Twine Package Using Pip

pip3 install wheel twine

Create Wheel File Using Setup.py

python3 setup.py bdist_wheel

After This Command A Wheel File Will Be Created In package_dir/dist/blabla.whl For Install This Wheel File In Local Machine Tou Can Use pip3 install *.whl

Upload Python Package To PyPi

With The Help Of Twine We Will Upload/Publish Package To PyPi.org As Shown Below:-

Publish To PyPi With Twine:-

python3 -m twine upload dist/*.whl
After the Make This Command Enter Your PyPi Account Password And Package Will Be Published. Thank You