Python: Referencing another project

后端 未结 5 590
悲&欢浪女
悲&欢浪女 2020-12-18 10:32

I want to be able to run my Python project from the command line. I am referencing other projects, so I need to be able run modules in other folders.

One method of

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 11:02

    First, I make sure that the module I want to include hasn't been installed globally. Then I add a symlink within the includee's directory:

    # With pwd == module to which I want to add functionality.
    ln -s /path/to/some_other_module_to_include .
    

    and then I can do a standard import. This allows multiple versions etc. It does not require changing any global settings, and you don't need to change the program code if you work on different machines (just change the symlink).

提交回复
热议问题