简体   繁体   中英

Run a python module from an installed package

I have the following sample python application:

- testapp
-- __init__.py
-- main.py
-- hello
---- __init.py
---- hello.py
-- world
---- __init__.py
---- world.py

main.py

from testapp.hello import hello
from testapp.world import world

if __name__ == "__main__":
    hello.say()
    world.say()

world.py

def say():
    print('world')

hello.py

def say():
    print('hello')

then, I can go into testapp folder and run python -m main I get the print of 'Hello world'

Fine, but what I would like to do is to build a package with this and install the package elsewhere to execute it. I'm using poetry to build the whl package. My question is, how to install the package somewhere else (on a server ie) and run it? I would like to setup a distribution flow, where packages are build and stored on a private pypi repo, and servers can update and run the whole app.

I tried to make a poetry add on a folder on the server, it is working as the package is now installed but I don't know how to launch the main module inside the package.

super easy in fact.. after the package installation,

python -m testapp.main

that's it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM