Skip to content
Sign upLog in
← Back to Community

How to Make a Module for Pip

Profile icon
JordanDixon1

How to make a Module for Pip.


Step 1

Make a new bash repl.

Step 2

Now it's time for the files. Create a folder named myapp. inside of myapp create a folder named your module. Inside of Your module folder create a file named _init_.py. Now create another file inside of your module named main.py (or any other name.). Your file system should look like this:

MyApp -MyModule --\__init\__.py --main.py

Now inside of the MyApp folder make a file named setup.py. Now make a README.md file and a LICENSE. The File System should now look like this:

MyApp -MyModule --\__init\__.py --main.py -LICENSE -README.md -setup.py

Step 3

Now it's time for the code! go to main.py and make the functions for your module. use the def function for this. Here is an example:

def hWorld(): """ Prints 'Hello World!' to the terminal. """ print("Hello World!")

The """ is a multi-line comment that gives a description for people that are using the help() command. Now once you are done go to _init_.py and type in the following code:

from .main import *

and that's all you need for the _init_.py file. Now let's go to the setup.py file.

Step 4

For the setup.py file type in the following template and replace with your info:

from setuptools import setup with open("README.md", "r") as fh: long_description = fh.read() setup( name = "Main", version = "1.0.0", description = "Example Module.", long_description = long_description, long_description_content_type = "text/markdown", url = "#Github or Website. This parameter isn't needed.", author = "Your name", author_email = "Your email", #To find more licenses or classifiers go to: https://pypi.org/classifiers/ license = "GNU General Public License v3 (GPLv3)", packages=['MyModule'], classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", ], zip_safe=True, python_requires = ">=3.0", )

That's it now after done replacing with your info (make sure you have everything!) it's time to actually find a licence...

Step 5

A website to find the right open-source license for you can be found here: https://choosealicense.com/
After finding the right license copy and paste it into your LICENSE file. After your done with that make up your README.md file. Make sure this is what people will want to see before installing your module because this is what people will see on the module page. Make sure to also list some commands with basic syntax for your module.

Step 6

This is all fine and dandy, but how do we upload to pypi? I don't see any upload project button... Well, it's a little more complicated than that, but fun!
press ctrl + shift + s. This will bring up a terminal. type into the terminal:

cd MyApp pip3 install --upgrade setuptools wheel python3 setup.py sdist bdist_wheel pip3 install twine python3 -m twine upload --repository pypi dist/*

This will ask for your username and password for pypi, enter these and it should then be uploaded to pypi!

All Done!

Now you can view your module on your pypi account and you will be able to install it using pip. I hope you guys found this helpful! Make sure to check out my clearing module that clears the terminal for multiple platforms here I'll see you all in the next one!

(If you have any suggestions or comments on this post I will do my best to update the post to be even more helpful. see ya guys!)

More links to external sites for more help and info:
https://dzone.com/articles/executable-package-pip-install
https://packaging.python.org/tutorials/packaging-projects/

(please note that repl won't automatically import these modules for unknown reasons... in order to install the module use pip.)

#A simple script to see if the user has the module installed and if not then install the module. import os try: import *modulename* except: os.system("pip3 install *modulename*") import *modulename*
Voters
Profile icon
AlexBertoloni
Profile icon
JBloves27
Profile icon
aguy11
Profile icon
JordanDixon1
Profile icon
NoelB33
Profile icon
XanderEhlert
Profile icon
SystematicError
Comments
hotnewtop
Profile icon
aguy11

So, I did all of the things that you explained, but repl.it doesn't show it in the 'packages' area. Is this a problem?

Profile icon
JordanDixon1

@aguy11
This is a problem on repl.it's end... However you can still install using pip. Just press ctrl + shift + s then pip install (your package name) and it should install.

Profile icon
aguy11

@JordanDixon1
Yeah, I tried that. I fixed it anyway. It turns out I didn't add the zip-safe parameter somehow. Also, note, this actually threw me off, but under Step 6 for the commands you need to type in, you misspelled Python3 as Pythons.

Profile icon
darkdarcool

@JordanDixon1

I worked great, but how do you update your project?

Profile icon
josef24

how do you update a module

Profile icon
JordanDixon1

@josef24
Unfortunately, there isn't a way to "overwrite" a description or a version, however you can make a new version of the code by:

  1. Update the description, or whatever you need to update such as code.
  2. update the setup.py version to 0.0.2 or 1.0.1
  3. You have to update the readme file or twine won't let you upload. If you don't want to change anything just put down in the bottom as a footer or something "version - 1.0.1"
  4. Re-make the module into wheels and a tar.gz.
  5. Upload using twine.
  6. Yank the earlier version to make it deprecated. (You may have to do this before uploading, I'm not sure.)
  7. Done. I hope this helps!
Profile icon
JordanDixon1

I have made another module named: simpleton. Simpleton is a module that auto-imports commonly used standard libraries like math, re, os, random, etc. You can view the module here: https://pypi.org/project/Simpleton/

Profile icon
JordanDixon1

If you need more help this link might help: https://packaging.python.org/tutorials/packaging-projects/