相关疑难解决方法(0)

调用`pip install`时运行自定义任务

我想让我的python包"可以安装pip".问题是该软件包具有必须在用户的init shell脚本中提供的shell脚本(例如.bashrc).

但是在安装之后,用户并不完全知道脚本的去向(大概是/usr/bin,但我们无法保证).当然,用户可以运行which myscript.sh并手动编辑他的init脚本.

但我想自动完成这一步.我可以创建一个新的distutils命令,但pip install不会调用它.我可以扩展distutils.command.install.install,但安装通过pip中断(虽然通过工作python setup.py install):

setup.py

from distutils.command.install import install

class CustomInstall(install):
def run(self):
    install.run(self)
    # custom stuff here
    do_my_stuff()

setup(..., cmdclass={'install': CustomInstall})
Run Code Online (Sandbox Code Playgroud)

贝壳

$ pip install dist/mypackage.tar.gz
Unpacking ./dist/mypackage.tar.gz
  Running setup.py egg_info for package from file:///path/to/mypackage/dist/mypackage.tar.gz

Installing collected packages: mypackage
  Running setup.py install for mypackage
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c …
Run Code Online (Sandbox Code Playgroud)

python distutils pip

13
推荐指数
1
解决办法
5922
查看次数

自定义安装后脚本未与 pip 一起运行

在标记为重复之前,我尝试了一系列解决方案,包括此处的一个 ,但没有运气

我创建了一个简单的工具来完成一些任务,并且能够成功地将其打包。

当尝试安装它时,我在使用时获得了所需的效果python setup.py install,但pip install package_name只安装了软件包,但没有安装后脚本。

这是我的代码的一部分;

安装程序.py

from distutils import setup
from app.scripts import *

setup(

        #Application name
        name = "my-app-name",

        version = "my-app-version",
        author = "my-name",
        author_email = "my-email",
        packages = ['app'],
        include_package_data = True,
        license = 'MIT',
        url = "https://my-url",
        description = "description",
        install_requires = ["flake8"],
        cmdclass = {
            "install":Post_install
        }
    )
Run Code Online (Sandbox Code Playgroud)

脚本.py

from distutils.command.install import install
import os

class Post_install(install):

    @staticmethod
    def func():      
        return True

    def run(self): …
Run Code Online (Sandbox Code Playgroud)

python distutils setuptools python-3.x python-packaging

5
推荐指数
1
解决办法
2803
查看次数