问题
I have a package that contains protocols for specific hardware from multiple vendors. This is basically a collection of multiple different protocols that have similar interface. It is ported to python by me. But now I have two projects that handle communication with this equipment using different transport protocols one is over TCP another is over RS-485/232. How to share the package with protocols between this two projects so that I don't need to copy it after I add new functionality support or bug fixes.
回答1:
You can build a python package (more info here: https://python-packaging.readthedocs.io/en/latest/)
Once you have created your package containing a setup.py file, you can install it on your machine using the:
pip install -e myPackage
command. (Where "myPacakge" is the folder containing the setup.py file). The advantage of using the -e flag is that changes made to your package are directly included in the installed version.
Once your package is installed, you can share it across multiple projects, simply by importing your package in Python, e.g.
import myPackage as myPackge
来源:https://stackoverflow.com/questions/43112768/python-how-to-share-package-between-multiple-projects