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.

Answer from MrNobody33 on Stack Overflow
🌐
Python Packaging
packaging.python.org β€Ί tutorials β€Ί packaging-projects
Packaging Python Projects β€” Python Packaging User Guide
Dynamic metadata (setup.py) should be used only as an escape hatch when absolutely necessary. setup.py used to be required, but can be omitted with newer versions of setuptools and pip. ... setup.cfg is the configuration file for setuptools. It tells setuptools about your package (such as the name and version) as well as which code files to include.
Discussions

Convert python script in module - Stack Overflow
I made a python script and I would like to transform it into a module to use all the treatment I did on a text in other tasks. My script I'm trying to transform into a module:** mymodule.py import re More on stackoverflow.com
🌐 stackoverflow.com
How do I package my python code into an executable I can send to my friend who does not have python?
Pyinstaller is the way to go for me, and afaik for most, why was it unsuccessful? More on reddit.com
🌐 r/learnpython
84
149
January 4, 2023
java - Convert a python file to a library - Stack Overflow
I need to convert a python file into a library which can be reused by other applications that are written in Java or Python. I am planning to convert the .py file into a library which can be used a... More on stackoverflow.com
🌐 stackoverflow.com
Turn python script into a function - Stack Overflow
That way, you can execute it simply ... in other Python files to call morning_func from there ... Sign up to request clarification or add additional context in comments. ... This does not directly address my question but might be useful for others. 2016-05-19T15:27:08.903Z+00:00 ... Adding to above answer, the best way in this case would be to go through the original morning script line by line and wrap the actions in related functions. Refer this recipe on How to convert a Python script ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
PyPI
pypi.org β€Ί project β€Ί stickytape
stickytape Β· PyPI
Stickytape can be used to convert a Python script and any Python modules it depends on into a single-file Python script.
      Β» pip install stickytape
    
Published Β  Jan 29, 2021
Version Β  0.2.1
🌐
TutsWiki
tutswiki.com β€Ί convert-python-script-to-module
How to convert a Python script to module :: TutsWiki Beta
We’ve packaged the action of the script as a function. The top-level action script is now wrapped in an if statement so that it isn’t executed during import. The most important rule for Python is that an import of a module is essentially the same as running the module as a script.
🌐
Israellandes
israellandes.com β€Ί blog β€Ί 2023 β€Ί 02 β€Ί convert-python-code-into-a-pip-package
Convert Python Code Into a Pip Package β€’ israellandes.com
February 28, 2023 - import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name="demopackage", version="1.0.0", author="demo_author", author_email="[email protected]", description="A small demo package", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/username/demopackage", packages=setuptools.find_packages(), classifiers=( "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ), ) Note: For a full list of classifiers you can use in your setup.py file, check out this link from PyPI’s Docs. Before you start, run the following command to update the necessary packages:
🌐
GitConnected
levelup.gitconnected.com β€Ί turn-your-python-code-into-a-pip-package-in-minutes-433ae669657f
Turn Your Python Code Into a pip Package in Minutes | by Will Norris | Level Up Coding
January 12, 2021 - Turn Your Python Code Into a pip Package in Minutes Why You Should Package Your Code One of Python’s greatest strengths is the ability for users to package their code and publish it for fellow …
Find elsewhere
🌐
Readthedocs
python-packaging.readthedocs.io
How To Package Your Python Code β€” Python Packaging Tutorial
This tutorial aims to put forth an opinionated and specific pattern to make trouble-free packages for community use.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί how do i package my python code into an executable i can send to my friend who does not have python?
r/learnpython on Reddit: How do I package my python code into an executable I can send to my friend who does not have python?
January 4, 2023 -

Hiya thanks for reading! I followed a tutorial and built a tiny game with pygame. I am trying to wrap it up in a single executable file I can send to a friend, such that they won't have to install anything to run it. I have unsuccessfully used p2exe and pyinstaller. Is there a standard way to package python applications? I can share my code or the tutorials/links I am looking at if that is desirable. In gratitude, Prathmun

🌐
Medium
medium.com β€Ί the-research-nest β€Ί how-to-publish-your-python-code-as-a-pip-package-in-5-simple-steps-3b36286293ec
How to Publish Your Python Code as a Pip Package in 5 Simple Steps | by XQ | The Research Nest | Medium
May 26, 2023 - Given that we want to make our code as a module, it is good to follow some best practices and create proper folder structure and classes as required. ... module_name β”œβ”€β”€ module_name β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ module_file1.py β”‚ └── module_file2.py β”œβ”€β”€ tests β”‚ β”œβ”€β”€ test_module_file1.py β”‚ └── test_module_file2.py β”œβ”€β”€ README.md β”œβ”€β”€ LICENSE β”œβ”€β”€ setup.py β”œβ”€β”€ MANIFEST.in └── .gitignore Β· The code for the package actually sits in the subfolder by the same name as the root folder.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί how do i package and run my own python script?
r/learnpython on Reddit: How do I package and run my own python script?
August 6, 2024 -

This feels like an RTFM thing, but man, I've been googling and it's hard to tell whether any particular result tells me how to do the thing I want, or just some other thing that I guess more people want to do.

I have a python script that I want to be able to run from anywhere on my filesystem by calling p9. Until now I've been doing that just by symlinking from somewhere on my path to the folder where I'm developing it.

It requires the module plotnine. Previously I just installed that with pip, but at some point pip on arch stopped letting me install things globally. I get it. I'm tempted to just do --break-system-packages, I think it'll be fine, but I'm gonna try to do it right. But I'm not sure what the way to do it right is.

  • I can create a venv and install plotnine in that? Then I think I have to be inside that venv every time I run the script. (Or change the #! line to point inside the venv, but then I can't share the script.)

  • I can turn the script into a package that can be uploaded to pypi? I'm not entirely sure how to do that (this tutorial doesn't mention executables). Once I've done that, how do I install it on my local machine? Can pipx install from here without me having to send it to pypi first? And, when I'm developing, can I test changes without installing to my local machine? (I'm fine with entering a venv for this, so I expect this works.)

  • Something else?

The second approach feels promising, but I've reached the point where I'm turning to help rather than trying to keep going myself.

Top answer
1 of 5
8
I do this a lot. Let me see if I can point you in the right direction. 0) As a preamble: Python packaging has gone through substantial flux in the past couple of years, so if you go a-googlin' you'll see guidance about setup.cfg, setup.py, etc. That's all old news. Currently you should be defining a pyproject.toml file for your Python packages. Don't follow any guidance that isn't about pyproject.toml for now. An optional feature in pyproject.toml allows you to configure a command-line stub that'll work exactly as you're looking for: https://packaging.python.org/en/latest/guides/creating-command-line-tools/#pyproject-toml Note that in their example: [project.scripts] greet = "greetings.cli:app" this defines a command added to the $PATH called greet (yours would be p9), which invokes the function "app" inside the module "cli" (cli.py in the package) inside the package "greetings" (whose code is in the directory src/greetings.) You don't have to have followed "src-layout" (a set of conventions about how Python projects are structured) so there's no particular reason to reorganize your project that way; you just have to know where the function you want to invoke is located. It's probably like "p9:main" or something. I can create a venv and install plotnine in that? 2) You can, but you're right - you'd have to activate the venv routinely for the tool to be available. What a hassle! Instead, and instead of dumping it into your site-packages like Arch doesn't want you to do, you can use pipx to install globally, yet in an isolated environment. The docs explain this: https://packaging.python.org/en/latest/guides/installing-stand-alone-command-line-tools/ And, when I'm developing, can I test changes without installing to my local machine? 3) Yes, you generally can install a package in "editable mode", where what gets put on your path is (I assume) a set of symlinks to the package under development. It's good to combine this with a set of dev and test dependencies, configured in pyproject.toml (end users don't need your dev and test dependencies, but you do.) When I do it, it looks like py -m pip install -e .[test,dev] and I assume you can do this with pipx, too. What this means is that when you make changes to the script and save them, the changes are immediately reflected when you invoke p9 in a shell or whatever. That last token (.[test,dev]) is the install target and it means "the current directory" (I assume you're running this from the project folder) "and its dev and test installation targets." Hopefully that's enough to get you started. Obviously a lot of Python projects are command-line tools so there's a lot of packaging features that address your precise use case. Once you understand what they want from you - little more than a sufficiently documented, self-describing project - they generally do the right thing on every platform.
2 of 5
3
I was going to suggest the second approach before I even read you already thought about it. But yes; basically the idea would be to turn this into a package, and then use pipx to install it somewhere without touching the system Python and still making it accessible. I don't think you have to upload this to PyPI, although I hardly ever use pipx myself so I don't know if it supports Git links (pip does, so I'm expecting pipx to do the same). Technically speaking all you'd need to do is add more information into pyproject.toml, but personally I'd move the source code to a dedicated directory. This information should include an entry that defines the console command that then runs the desired function in your program, something like this: [project.scripts] p9 = "p9:main"
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί packaging-and-publishing-python-code
Packaging and Publishing Python code | GeeksforGeeks
September 29, 2022 - Here I am using my own python script which I have named 'locator.py' (I am using this name just for reference purpose. Feel free to save your python scripts by any name.) This file is available here. Step 2: Getting the package-directory structure ready This is the most important step.
🌐
Medium
medium.com β€Ί pythoneers β€Ί converting-python-code-to-a-whl-package-a-step-by-step-guide-9f30c9cbe444
Converting Python Code to a .whl Package: A Step-by-Step Guide | by aimltools.com | The Pythoneers | Medium
February 14, 2025 - Converting Python Code to a .whl Package: A Step-by-Step Guide Introduction: Packaging your Python code into a distributable format not only makes it easier for others to use but also ensures proper …
🌐
Quora
quora.com β€Ί How-do-I-change-my-python-script-into-a-fully-usable-software-so-that-I-can-upload-it-in-git-rather-than-simple-scripting
How to change my python script into a fully usable software (so that I can upload it in git), rather than simple scripting - Quora
If yes I would suggest you to go with pyinstaller package ... PyInstaller bundles a Python application and all its dependencies into a single package. ... This is an easy module that would allow you to convert your python script into a program.