Creating a python package with PyPi and executing it so that no "python3" and ".py" extension is needed

71 Views Asked by At

So, I was working on one of my projects when I decided that I would make it a command-line-based tool. I could not find any reliable information (maybe I just searched for the wrong thing, sorry if this is a duplicate, I am new to packaging). I have seen many other projects do it so that all they need to do is:

pip install packageName

packageName -args

I tried doing this, I added arguments, so that works, but I am not sure how to do this. I have tried looking for solutions, and I have only come across some topics on stackoverflow that only talk about dealing with file permissions using chmod commands, etc. I am just confused.

So at this point, I was expecting my file to be executable, or make it in an easy way / have a way to do it through python packaging, but I still am not sure how. I just want my package to be installed with pip, and then easily executed without having to use "python3" and ".py" and having to CD into the project directory every time of use.

I tried searching the internet but no information has come across to me yet.

I am sorry for duplicates. I have looked at other solutions but they all use chmod and I just want to package it in a python package through PyPi.

Please, if you can help, it would be great.

Thanks in advance.

1

There are 1 best solutions below

0
PatzEdi On

After a couple of hours, I was able to solve the problem.

Here is the full explanation:

https://setuptools.pypa.io/en/latest/userguide/entry_point.html

This helped so much. All I needed to do was to put:

[project.scripts]

projectName = "pathtofunction"

I solved all the issues regarding importing by putting all of the code in the init.py file.

Hope this helps to anyone who had any trouble.