How to Publish a Python Package to PyPI (pip)
Вставка
- Опубліковано 19 чер 2024
- Learn how to publish your own custom Python package to PyPI.
This tutorial covers setting up the project, configuring the setup.py file, building and testing the package, adding CLI functionality, publishing to PyPI, and installing using pip. Watch this video if you want to share your code and make it easily installable for others.
📚 Chapters
00:00 Introduction
00:34 Project Setup
02:06 Configure and Build Package
04:14 Local Testing
05:53 Adding a CLI Entry Point
07:36 Publish to PyPI
10:01 Wrapping Up
#pixegami #python
The best video!! Short and concise!! Thank you sharing this!
Bro seriously one of the best video on UA-cam
Thank you for the Guidance. I was able to create the package without much googling!!
Awesome, glad to hear that!
Thanks man, it was straight forward
I'm surprised at how easy this is. I'm motivated to bundle some of my scripts into packages.
actually npm is way better and straightforward. This part of creating a token on pypi was a whole issue for me
Sometimes I do wish Python's package management/environment was as integrated as Node :)
Yup! This can be useful if you if you need to re-use scripts or to share them with your team.
Helpful video... came in handy for me here! Thanks!
Thank you! I'm glad to hear that :)
Really well explained, thanks!
Glad it was helpful!
Great tutorial, Thanks!
awesome!!
This was great, thank you!
Glad you enjoyed it!
This is such a great video! Thankyou very much!
Glad it was helpful!
Thanks a lot!
If my package is in a github repository, and I want to use `pip install git+[some link].git`, do I need to commit and push the wheel files?
Concise and to the point. I keep revisiting it as I progress.
Would like to see a compatible one usng a pyproject.toml.
Thank you, glad it's helpful! I need to take a look at using the toml format, I haven't used it before.
Excellent
just what i need :D
Glad to hear that :)
Is this all that is needed to also do: pipx install pixegami-hello ... for example? Thanks for the videos.
Great one. side topic. Can you tell us which tool you use to create the youtube thumbnail? thanks.
Thanks! I use Photoshop for the thumbnails.
So I installed my library and when I import it to a file to test, everything works fine when I run the code, however Pylance says the module doesn't exist but when the code is ran, it works just fine? I wonder why??
Well Explained , thanks I Have doubt in terms of loading json data within folder structure and reading it wihthin a function
how it can excuted can you help me with this
First, you need to configure your setuptools to include data files like JSON: docs.python.org/3.8/distutils/setupscript.html#installing-additional-files
Then it'll be packaged along with your Python scripts, and you can just call/use it from there.
Will there be a problem if I delete previous versions?
Generally, I don't think you're meant to delete previous versions, but I'm sure it'll be fine if you have to do it (I haven't tried it out myself though).
Is there a way to change the version number automatically?
Yeah, I'd recommend implementing this as something like a Git hook maybe for minor/patch version number.
which plugin or app you are using for VS Code terminal autocomplete suggestions?
It's GitHub Co-Pilot.
@@pixegami Thanks for responding. Are you using the fish terminal?
But the entry_points isn't a setup parameter? please explain it!! thanks
A quick question, what if I want to pass a string to the hello function?
If you wanna use it as a library, then it's just a normal function (so you can add an argument to it, and use it after you import it).
If you wanna use it like a CLI (from the terminal), you can do it using a library like argparse: docs.python.org/3/library/argparse.html#module-argparse
@@pixegami thank you!
hey men, im do the same but my project have some dependencies, it work localy but but i try to install form pypi it dont install the dependacies, can you help me ?
Have you tried adding them to `install_requires`? See here: python-packaging.readthedocs.io/en/latest/dependencies.html
can you make using hatch package manager
i am able to do this but what if i want my package to be uploaded privately , one only with auth can able to install it with pip
I think you can upload to your own private repository for that. You'll probably have to look up how to set up your own private PyPI server.
Why do we have to use twine?
I don't think we have to use it, but it was just the easiest/recommended way I found online of how to actually upload the local content to the remote repository.
Thank you, my friend, I am grateful to you for answering all three of my questions :)@@pixegami
How to create a CLI Command which will accept arguments ? Like, pixegami-hello --file_name /file/path/
This is how you wire up scripts to command: python-packaging.readthedocs.io/en/latest/command-line-scripts.html
If you want to parse arguments, use this built-in library: docs.python.org/3/library/argparse.html
I can't install twine
String library is not installed
I didn't get how and where to export the token and api key please tell me
It's just environment variables, so if you're not familair with them, search "how do I set environments in Linux/Mac/Windows?" (or whichever OS you are using) on Google. Good luck!
Bro I can't understand how setup environment variable ( 8:14 ) Can you please clarify that?
There's lots of ways to set an environment variable. It's basically a variable that is set at the OS level, and shared with all processes in that terminal/application context.
I'd recommend to Google "how do I set up environment variables on Linux/Mac/Windows? (or whichever OS you are on)" and follow those instructions.
@@pixegami I googled it and found out the results Thanks!
How to totp verification do???
Hmm, is this part of the package publishing workflow, or is this for something different?
@@pixegami pypi verification