5

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).

jollycat
  • 137
  • 3
  • 10

2 Answers2

0

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
Helge Schneider
  • 483
  • 5
  • 8
0

It appears you can resolve this issue by adding git as a dependency before using a git link. So in your case, your test.yaml would look like:

name: test
channels:
  - defaults
dependencies:
  - python=3.8
  - git
  - pip
  - pip:
    - git+https://{access_token_name}:{access_token}@gitlab.com/{your_gitlab_username}/{repository_name}.git

I was having the same issue with gitlab until I stumbled across this post which nudged me into this direction. This works with github links as well.