1

I'd like to convert my python script to a module that can be called from the commandline. Kind of like pytest or something. For instance, my script is named egscript.py. I have to run the script like this, >python3 egscript.py [commandline args]

What I want instead is to be able to do it like this, >egscript [commandline args]

How can I achieve this?

2 Answers 2

1

As you can see in this link, you can use:

C:\> assoc .py=Python C:\> ftype Python="C:\python27\python.exe %1 %*" 

I suggest you to see the link I put before. If you want to run it as a package like pip install egscript and then use egscript, you have to create a package to upload it into the Python Package Index(PyPy). To make that posible, follow the steps in these links: Build Your First pip Package, Packaging Python Projects.

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

6 Comments

I want to do something similar to this. So that I can distribute it to other systems as well.
Okay, you mean, run the file, only by his name, without .py, yeah?
As an application like in the link. So I can also pass the commandline arguments and others can install it via pip
Oh, okay. You have to create a proyect with your script and then publish it if you want. You have to follow the steps of this link.
Glad it helps you, I just added the links to my answer. I'll appreciate your upvote. :)
|
1

You could set an alias in your .bashrc or .zshrc file

alias egscript="python3 /path/to/egscript.py" 

Or you could turn it into an executive using something like pyinstaller, and then you can run the script like ./egscript

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.