0

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.

6
  • Are you looking for an entrypoint? See packaging.python.org/en/latest/specifications/entry-points Commented Feb 17, 2023 at 16:19
  • python-packaging.readthedocs.io/en/latest/… Commented Feb 17, 2023 at 16:24
  • @JaredSmith ah. Thanks so much. I was looking at the article/documentation you gave me, and I am wondering, under where it says "The scripts KeyWord argument", why do I need to add a bin directory within the project? Commented Feb 17, 2023 at 16:29
  • @Sören, the article the other guy gave me was based off of python2, which had different importing mechanisms, so it does not work. Yes, I am trying to do that. Can you help me out please? Thanks. Commented Feb 17, 2023 at 16:47
  • 1
    @JaredSmith I see... I will try things out Commented Feb 17, 2023 at 18:27

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.