How to upload the python packages to Nexus sonartype private repo

Viewed 23618

I have configured the Nexus-OSS-3.14 private Python artifact server on aws cloud. I want to be maintain all my project related Python packages on my private repository server.

I downloaded the all the Python packages on my local Linux box and I want to be upload all the Python packages to private Python artifact server.

I have tried curl put request and I didn't upload and your help is needed to complete this.

I have tried curl put request:

curl -v -u admin:admin --upload-file boto3-1.9.76-py2.py3-none-any.whl https://artifact.example.com/repository/ASAP-Python-2.7-Hosted/

When I used that command and I get 404 response.

2 Answers

I think the recommended approach is to use twine, something like this should work:

pip install twine
twine upload --repository https://artifact.example.com/repository/ASAP-Python-2.7-Hosted/ boto3-1.9.76-py2.py3-none-any.whl

It should ask for your username and password. To make life a bit easier you can create $HOME/.pypirc file with the URL, username and password

[nexus]
repository: https://artifact.example.com/repository/ASAP-Python-2.7-Hosted/
username: admin
password: admin

Then when you call twine, do so like this:

twine upload --repository nexus boto3-1.9.76-py2.py3-none-any.whl

It's not a hard requirement, but if you're on multi user system and you've put a password in the file you should probably do

chmod 600 $HOME/.pypirc 

Pip (yarn) for download. Twine for upload. Configuration:

be careful with trailing slashes!

Download with pip (yarn)

pip config edit [--editor [nano|code|...]] [--global|--user] for edit config

[global]
index = https://nexus.your.domain/repository/pypi/pypi
index-url = https://nexus.your.domain/repository/pypi/simple

Or set environment variables. Dockerfile for example:

ENV \
  PIP_INDEX=https://nexus.your.domain/repository/pypi/pypi \
  PIP_INDEX_URL=https://nexus.your.domain/repository/pypi/simple

Or use command line args pip install --index

Upload with twine

Edit .pypirc:

[distutils]
index-servers =
pypi
[pypi]
repository: https://nexus.your.domain/repository/pypi-hosted/
username: nexususername
password: nexuspassword 

Or environment

ENV \
  TWINE_REPOSITORY_URL=https://nexus.your.domain/repository/pypi-hosted/ \
  TWINE_USERNAME=nexususername \
  TWINE_PASSWORD=nexuspassword

Or command line

twine upload --repository-url

Related