gpt4 book ai didi

python-2.7 - 如何在 DSX 中提供用户功能/模块

转载 作者:行者123 更新时间:2023-12-03 16:42:02 25 4
gpt4 key购买 nike

我在单独的 python 脚本中定义了一些辅助实用程序。我想让脚本对 DSX notebook 可用,这样我就可以在单元格中调用它们,但我不想将脚本直接放入单元格中。

实现这一目标的一些方法是什么?

最佳答案

如果您愿意在公共(public) git 存储库中公开您的代码,您可以将您的代码转换为 python 包并将其保存在 github 中。请参阅此处的示例包:A simple Hello World setuptools package and installing it with pip .

您可以直接从 github 安装它:

!pip install --user git+https://github.com/public_account/public_repo

私有(private)github仓库

也应该可以使用与上述类似的方法来处理私有(private) github 存储库,只需一些额外的设置步骤和 pip 的不同 url 格式。例如

在 dsx 上生成 ssh key

! ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""

将以下命令的输出添加到您的 github 帐户设置::SSH 和 GPG key

! cat ~/.ssh/id_rsa.pub

接下来将 github ssh key 添加到 dsx:

! ssh-keyscan github.com >> ~/.ssh/known_hosts

重要提示:您应该手动验证导入的 github 主机 key 是否真实。您可以使用以下方式查看导入的 key :

! cat ~/.ssh/known_hosts

您现在可以使用 pip 安装:

! pip install --user git+ssh://git@github.com/private_account/private_repo

注意!上述方法存在一些安全注意事项。 IE。任何有权访问您执行上述命令的 spark 服务的人都将能够访问 git 私有(private)存储库。


注意:

理想情况下,在未来,我希望看到 dsx 支持编辑项目中的所有文件并将所有项目文件提交到 github,例如

关于python-2.7 - 如何在 DSX 中提供用户功能/模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41876516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com