简体   繁体   中英

Use setuptools to Install a Python package from a private Gitlab package repository

I created a private package for my employer. Since I'm forbidden to upload it to PyPI (it's proprietary), I uploaded it to the packages index for my project on our private Gitlab hub. I can install it manually with:

$ pip install my-package --extra-index-url https://__token__:my-token-xxx@gitlab.company-domain.com/api/v4/projects/123456/packages/pypi/simple

Now I also want setuptools to be able to find it when listed in the install_requires argument to setup(). I tried:

setup(
  install_requires=[
    f"my-package @ https://__token__:{API_TOKEN}@gitlab.company-domain.com/api/v4/projects/123456/packages/pypi/simple",
    ...
    ],
  ...

pip install -e. results in

ERROR: HTTP error 404 while getting https://__token__:****@gitlab.company-domain.com/api/v4/projects/123456/packages/pypi/simple

This is different than

my-package @ git+https://user:password@gitlab.company-domain.com/..../my-package.git

That works, but I want to be able to download it as a pre-built wheel.

I'm not sure whether this is a setuptools issue or a Gitlab issue. The 404 response tells me that it might be a gitlab issue, yet the same URI works perfectly when used with the pip install CLI command.

This question is similar to Include python packages from gitlab's package registry and other external indexes directly into setup.py dependencies , but I don't think that one got sufficient response. I posted the same question to discuss.python.org , but that discussion is old and I think I might get a quicker response here.

I also found this response to a similar question, which wasn't encouraging. It recommends Poetry or Pipenv. I've tried both, and found each to be excruciatingly slow when resolving dependencies, so I fell back on setuptools.

Only include the package name in install_requires . Then, configure your (extra) index URL in your pip configuration (either environment variables or pip.conf / .pypirc or CLI argument). Then using pip install as normal will work.

For example:

In setup.py :

    # ...
    install_requires=[
        'my-package-name',
        # ...
    ],
    # ...

Then the install command (assuming the environment variable API_TOKEN exists):

GITLAB_INDEX="https://__token__:${API_TOKEN}@gitlab.company-domain.com/api/v4/projects/123456/packages/pypi/simple"
pip install --extra-index-url "${GITLAB_INDEX}" -e .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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