簡體   English   中英

如何從C:\Python37\Scripts創建類似於pip.exe、jupyter.exe等的a.exe?

[英]How to create a .exe similar to pip.exe, jupyter.exe, etc. from C:\Python37\Scripts?

In order to make pip or jupyter available from command-line on Windows no matter the current working directory with just pip... or jupyter... , Python on Windows seems to use this method:

  • C:\Python37\Scripts放入 PATH
  • 創建一個小的 100KB.exe 文件C:\Python37\Scripts\pip.exejupyter.exe ,這可能只是用解釋器調用 Python 腳本(我猜?)

然后在命令行中執行pip...jupyter...工作,無論當前目錄如何。

問題:如何創建一個類似的 100KB mycommand.exe ,我可以將它放在 PATH 中的目錄中,以便我可以從命令行中的任何位置執行mycommand


注意:我不是在談論 pyinstaller、cxfreeze 等(我已經知道並且以前使用過); 我不認為這些C:\Python37\Scripts\ exe 文件使用這個。

假設您使用setuptools來 package 這個應用程序,您需要創建一個console_scripts入口點,如此處所述:

對於單個頂級模塊,它可能如下所示:

setup.py

#!/usr/bin/env python3

import setuptools

setuptools.setup(
    py_modules=['my_top_level_module'],
    entry_points={
        'console_scripts': [
            'mycommand = my_top_level_module:my_main_function',
        ],
    },
    # ...
    name='MyProject',
    version='1.0.0',
)

my_top_level_module.py

#!/usr/bin/env python3

def my_main_function():
    print("Hi!")

if __name__ == '__main__':
    my_main_function()

然后使用以下命令安裝它:

path/to/pythonX.Y -m pip install path/to/MyProject

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM