Python how to share package between multiple projects

梦想的初衷 提交于 2021-02-08 11:18:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!