简体   繁体   English

安装本地开发的Python模块

[英]Install Locally Developed Python Module

I am currently in the process of developing a module that I am using as a library to be imported in another project. 我目前正在开发一个模块,该模块用作要在另一个项目中导入的库。 I need a sane way that I can install this module in the python site packages in such a way that I don't need to reinstall it everytime I make changes to it. 我需要一种明智的方法,以便可以在每次对它进行更改时都不需要重新安装它,从而可以将该模块安装在python站点软件包中。 Currently, I am using sudo pip install --force-reinstall {BASE_FOLDER_FOR_MODULE} , but need to re run this command everytime I make any changes to the module code. 当前,我正在使用sudo pip install --force-reinstall {BASE_FOLDER_FOR_MODULE} ,但是每次对模块代码进行任何更改时,都需要重新运行此命令。

The little bit of info I've been able to find on the subject seems to indicate that while I can symlink the base folder for the module in the site-packages folder for my other project, that this may not necessarily be a good way to do it. 我可以在该主题上找到的一些信息似乎表明,虽然我可以在其他项目的site-packages文件夹中对模块的基本文件夹进行符号链接,但这不一定是一种好方法做吧。 Is symlinking the folder bad, and if so why? 对文件夹进行符号链接是否不好?如果是,为什么呢? Is there an alternate (better) option? 有替代(更好)的选择吗?

Thanks 谢谢

If the library is still under active development then consider adding it to environment variable PYTHONPATH . 如果该库仍在积极开发中,请考虑将其添加到环境变量PYTHONPATH Directories in PYTHONPATH are appended to sys.path and are searched last when trying to find a module. PYTHONPATH中的目录被附加到sys.path并在尝试查找模块时被最后搜索。 Using PYTHONPATH means you only have to make minimal changes (set it in a config file source file or .bashrc file) for things to work. 使用PYTHONPATH意味着您只需进行最小的更改(将其设置在配置文件源文件或.bashrc文件中)即可正常工作。 Once the library is finalised you can install it to the site-packages directory and remove it from PYTHONPATH . 库完成后,您可以将其安装到site-packages目录,并将其从PYTHONPATH删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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