'How to install custom packages from GitLab registry in conda.yaml
I have created a custom python package on a GitLab repository, which I can successfully install with the following pip command in a local terminal (terms with <> represent variables that need to be replaced before running the command):
pip install <packagename> --extra-index-url https://<access_token_name>:<access_token>@gitlab.com/api/v4/projects/24/packages/pypi/simple
However, my constraint is that I need to install this package from an anaconda environment created with a conda.yaml file. An example of this file is shown below.
name: test
channels:
- defaults
dependencies:
- python=3.8
- pip
- pip:
- pandas==1.2.4
- numpy==1.20.2
My question: How do I add the custom package to the conda.yaml? It seems that the conda.yaml allows to specify dependencies in the format <packagename>==<package_version> but it does not allow for custom pip install commands like the one above.
What I have tried I tried adding - "--extra-index-url https://<access_token_name>:<access_token>@gitlab.com/api/v4/projects/24/packages/pypi/simple" to the dependencies (as an item under - pip:) and could then successfully create a conda environment with conda env create -f conda.yaml, i.e. this command was executed without error message. However, my package <packagename> did not actually get installed, i.e. it was not listed in conda list and it was not possible to import the package (after activating the new environment).
Solution 1:[1]
I think you can add your git package by just providing git+https://{access_token_name}:{access_token}@gitlab.com/{your_gitlab_username}/{repository_name}.git in the yaml file.
test.yaml
name: test
channels:
- defaults
dependencies:
- python=3.8
- pip
- pip:
- git+https://{access_token_name}:{access_token}@gitlab.com/{your_gitlab_username}/{repository_name}.git
Then run:
conda env create --file=test.yaml
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Helge Schneider |
