How to Make a Module for Pip
How to make a Module for Pip.
Make a new bash repl.
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
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.
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...
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.
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!
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:
(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*
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?
@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!