简体   繁体   English

在构建 VS Code 扩展时添加 Python 包作为依赖项

[英]Add Python packages as dependency when building a VS Code extension

I'm building a VS Code extension that assumes that the user already has a particular Python package installed on their system.我正在构建一个 VS Code 扩展,假设用户已经在他们的系统上安装了特定的 Python package。

What could be the possible approaches to install that Python package to the user's machine when the user installs my VS Code extension.当用户安装我的 VS Code 扩展时,将 Python package 安装到用户机器的可能方法是什么。

I was able to think of a few ways to do so but couldn't find any resources on the internet validating my approaches:我能够想出几种方法来做到这一点,但在互联网上找不到任何资源来验证我的方法:

  1. creating a subprocess from inside the VS Code extension and calling pip install if VS Code is allowed to make such a privileged install to the user's machine without having any special/admin rights?如果允许 VS Code 在没有任何特殊/管理员权限的情况下对用户机器进行此类特权安装,则从 VS Code 扩展内部创建一个子进程并调用pip install
  2. adding that package as a dependency in the package.json so it gets installed when the user tried to install the extension?添加 package 作为package.json中的依赖项,以便在用户尝试安装扩展程序时安装它? Is there a way to add Python packages as dependencies?有没有办法将 Python 包添加为依赖项?

This doesn't sound like a good idea, because different users will use different Python versions and python environments.这听起来不是一个好主意,因为不同的用户会使用不同的 Python 版本和 python 环境。 When you specify a specific Python version, is the cost of using the extensions you designed a little too high?当你指定一个特定的 Python 版本时,使用你设计的扩展的成本是不是有点太高了?

Moreover, with the update of Python version, your extensions also need to design new specific dependent versions.而且随着Python版本的更新,你的扩展也需要设计新的具体依赖版本。

I suggest that you try to let users customize as vscode recognizes Python interpreter , otherwise the applicable population will not too much.建议你尽量让用户自定义为vscode识别Python解释器,否则适用人群不会太多。

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

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