How to locally develop a python package?

后端 未结 5 478
鱼传尺愫
鱼传尺愫 2021-01-30 18:15

I\'m trying to make changes to an existing python module, and then test it locally. What\'s the best way to do this?

I cloned the github module and made changes, but I\'

5条回答
  •  深忆病人
    2021-01-30 18:55

    One way consists in using sys.path().
    For example:

    import sys
    sys.path.insert(0, path/to/module)
    

    In this way, you give priority to a specific path when looking for a module.
    This means that the module you want to import will be searched first in path/to/module and after in the other directories already in sys.path.

    The advantage of this approach is that this new order will hold only inside your script without changing the import order of the other ones.

    Note: For development purposes you should use a virtualenv as suggested by @eandersson.

提交回复
热议问题