How can I install from a git subdirectory with pip?

前端 未结 2 1856
我寻月下人不归
我寻月下人不归 2020-12-12 15:03

I have a git repository with many folders, one of them being a python module installable with pip, like this:

repo.git/
repo.git/folder1/
repo.git/folder2/
r         


        
2条回答
  •  眼角桃花
    2020-12-12 15:15

    There is a pull request regarding this feature, and it seems to have been merged to develop branch a month ago. The syntax is the following:

    pip install -e git+https://git.repo/some_repo.git#egg=version_subpkg&subdirectory=repo # install a python package from a repo subdirectory
    

    We probably have to wait for a while until it gets merged to master and is distributed.

    UPDATE: This is now available and documented at https://pip.readthedocs.io/en/stable/reference/pip_install/#vcs-support as follows:

    For projects where setup.py is not in the root of project, "subdirectory" component is used. Value of "subdirectory" component should be a path starting from root of the project to where setup.py is located.

    So if your repository layout is:

    - pkg_dir/
      - setup.py  # setup.py for package ``pkg``
      - some_module.py
    - other_dir/
      - some_file
    - some_other_file
    

    You'll need to use

    pip install -e vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir
    

    Note: On Windows, you must place the URL in double quotes, or you'll get an error "'subdirectory' is not recognized as an internal or external command". E.g., use:

    pip install -e "vcs+protocol://repo_url#egg=pkg&subdirectory=pkg_dir"
    

提交回复
热议问题