升级自托管的 Python 包,从 Python 会话中进行。

huangapple go评论70阅读模式
英文:

Upgrade a self hosted python package from within a python session

问题

We are developing a python package hosted on our own Bitbucket. So far the upgrade of the package works fine from the terminal:

python -m pip install --upgrade --no-cache-dir git+ssh://git@{package_git_url}

The idea is to let the user upgrade the package from within its notebook as the package development is in early stage. For this we use this method within the package:

def upgrade(self):
    subprocess.run(
        [
            "python",
            "-m",
            "pip",
            "install",
            "--upgrade",
            "--no-cache-dir",
            self.config.PIP.URL,
        ]
    )

But when calling this function within python, it does not upgrade the package in the virtual environment. Hence my question: is it possible to upgrade a python package from within a python session?

英文:

We are developing a python package hosted on our own Bitbucket. So far the upgrade of the package works fine from the terminal :

python -m pip install --upgrade --no-cache-dir git+ssh://git@{package_git_url}

The idea is to let the user upgrade the package from within its notebook as the package development is in early stage. For this we use this method within the package :

def upgrade(self):
        subprocess.run(
            [
                "python",
                "-m",
                "pip",
                "install",
                "--upgrade",
                "--no-cache-dir",
                self.config.PIP.URL,
            ]
        )

But when calling this function within python, it does not upgrade the package in the virtual environment. Hence my question : is it possible to upgrade a python package from within a python session ?

答案1

得分: 0

@Klaus D.:亲爱的朋友,你太棒了!只需按照以下方式调整upgrade函数:

import sys
from pathlib import Path

def upgrade(self):
    executable = Path(sys.executable).resolve()
    subprocess.run(
        [
            executable,
            "-m",
            "pip",
            "install",
            "--upgrade",
            "--no-cache-dir",
            self.config.PIP.URL,
        ]
    )

猜猜?它有效。感谢你的帮助!

英文:

@Klaus D. : beste Man, you rock ! just adjusted the upgrade function as follow :

import sys
from pathlib import Path

   def upgrade(self):
        executable = Path(sys.executable).resolve()
        subprocess.run(
            [
                executable,
                "-m",
                "pip",
                "install",
                "--upgrade",
                "--no-cache-dir",
                self.config.PIP.URL,
            ]
        )

and guess what ? it works. Thanks for your help !

huangapple
  • 本文由 发表于 2023年5月17日 16:32:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定