# How to Specify Custom pip Mirrors for Dify Plugin Downloads

> Learn how to specify custom pip mirrors for Dify plugin downloads by setting the PIP_MIRROR_URL environment variable. Avoid default mirrors and speed up your downloads.

- Repository: [Junjie.M/dify-plugin-repackaging](https://github.com/junjiem/dify-plugin-repackaging)
- Tags: how-to-guide
- Published: 2026-03-05

---

**Set the `PIP_MIRROR_URL` environment variable before running the script to override the default Aliyun mirror.**

The `junjiem/dify-plugin-repackaging` repository provides a shell script that downloads Python dependencies and repackages Dify plugins for offline or air-gapped environments. By default, it uses Aliyun's PyPI mirror, but you can specify custom pip mirrors for plugin downloads to suit your network requirements or organizational policies.

## Understanding the Mirror Configuration in plugin_repackaging.sh

The mirror selection logic resides in the main [`plugin_repackaging.sh`](https://github.com/junjiem/dify-plugin-repackaging/blob/main/plugin_repackaging.sh) script. Understanding how it handles default values and environment overrides ensures you configure it correctly without modifying the source.

### Default Mirror Settings

On **line 6** of [`plugin_repackaging.sh`](https://github.com/junjiem/dify-plugin-repackaging/blob/main/plugin_repackaging.sh), the script defines a default mirror URL:

```bash
DEFAULT_PIP_MIRROR_URL=https://mirrors.aliyun.com/pypi/simple

```

This value ensures the script works out-of-the-box for users in regions where Aliyun provides optimal download speeds.

### Environment Variable Override

On **line 10**, the script checks for an environment variable to override the default:

```bash
PIP_MIRROR_URL="${PIP_MIRROR_URL:-$DEFAULT_PIP_MIRROR_URL}"

```

This Bash parameter expansion assigns `DEFAULT_PIP_MIRROR_URL` to `PIP_MIRROR_URL` only if the environment variable is unset or empty. If you export `PIP_MIRROR_URL` before execution, the script respects your custom value.

## How to Set a Custom pip Mirror for Plugin Downloads

You can specify alternative PyPI mirrors through environment variables in various deployment contexts. The script requires no additional command-line flags; it automatically detects and applies the `PIP_MIRROR_URL` value.

### Using Environment Variables for One-Off Execution

For single executions using a mirror like Tsinghua University’s TUNA, export the variable in your shell session:

```bash
export PIP_MIRROR_URL=https://pypi.tuna.tsinghua.edu.cn/simple
./plugin_repackaging.sh market junjiem mcp_sse 0.0.1

```

The script passes this URL to `pip download` via the `--index-url` parameter during the repackaging process.

### Configuring Mirrors in Docker Builds

When containerizing the repackaging workflow, set the environment variable in your Dockerfile to ensure consistent behavior across builds:

```dockerfile
FROM python:3.12-slim

# Specify your preferred PyPI mirror

ENV PIP_MIRROR_URL=https://pypi.org/simple

# Copy the repackaging script into the image

COPY plugin_repackaging.sh /app/
WORKDIR /app

# Execute the script with standard arguments

CMD ["./plugin_repackaging.sh", "market", "junjiem", "mcp_sse", "0.0.1"]

```

This approach hardcodes the mirror for the container environment while keeping the original script unmodified.

### CI/CD Pipeline Configuration

For automated workflows in GitHub Actions or similar platforms, define the mirror at the job level to ensure all steps use the correct index:

```yaml
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      PIP_MIRROR_URL: https://pypi.tuna.tsinghua.edu.cn/simple
    steps:
      - uses: actions/checkout@v3
      - name: Repackage Dify plugin
        run: ./plugin_repackaging.sh market junjiem mcp_sse 0.0.1

```

Setting `env` at the job scope ensures the variable persists across all run steps without repetitive exports.

## How the Mirror is Applied During Repackaging

The actual consumption of `PIP_MIRROR_URL` occurs in the `repackage` function on **line 13** of [`plugin_repackaging.sh`](https://github.com/junjiem/dify-plugin-repackaging/blob/main/plugin_repackaging.sh). The script constructs a `pip download` command that includes your custom mirror:

```bash
pip download ${PIP_PLATFORM} -r requirements.txt -d ./wheels \
    --index-url ${PIP_MIRROR_URL} --trusted-host mirrors.aliyun.com

```

The `--index-url` parameter receives the value from `PIP_MIRROR_URL`, directing `pip` to fetch all dependencies from your specified mirror rather than the default PyPI.org. Note that `--trusted-host` currently remains hardcoded to `mirrors.aliyun.com`; if your custom mirror uses HTTPS with valid certificates, this flag remains harmless, but for HTTP mirrors you may need to adjust this parameter in the script.

## Summary

- The [`plugin_repackaging.sh`](https://github.com/junjiem/dify-plugin-repackaging/blob/main/plugin_repackaging.sh) script defaults to Aliyun's PyPI mirror via `DEFAULT_PIP_MIRROR_URL` on line 6.
- Override the default by exporting `PIP_MIRROR_URL` before execution; the script checks this variable on line 10.
- The custom mirror is passed to `pip download` via `--index-url` in the `repackage` function on line 13.
- You can set `PIP_MIRROR_URL` in shell sessions, Dockerfiles, or CI/CD configurations without modifying the script source.

## Frequently Asked Questions

### What is the default pip mirror used by the Dify plugin repackaging script?

The default mirror is Aliyun's PyPI repository at `https://mirrors.aliyun.com/pypi/simple`. This is defined in the `DEFAULT_PIP_MIRROR_URL` variable on line 6 of [`plugin_repackaging.sh`](https://github.com/junjiem/dify-plugin-repackaging/blob/main/plugin_repackaging.sh).

### Can I use the official PyPI.org instead of a mirror?

Yes. Set `PIP_MIRROR_URL` to `https://pypi.org/simple` before running the script. This directs `pip` to use the official Python Package Index rather than any third-party mirror.

### Does the script support authenticated or private pip mirrors?

The script passes `PIP_MIRROR_URL` directly to `pip download --index-url`, so it supports any URL format that pip accepts, including authenticated URLs like `https://username:password@private-mirror.company.com/simple`. Ensure you handle credentials securely through environment variables or secret management systems.

### Why does the script include `--trusted-host mirrors.aliyun.com` when using a custom mirror?

This parameter is hardcoded in the `repackage` function on line 13 and was originally intended to trust the default Aliyun mirror when using HTTP. When using HTTPS mirrors with valid SSL certificates, this flag has no negative effect. However, if your custom mirror uses HTTP and a different hostname, you may need to modify this line in the script to match your `--trusted-host` requirements.