20

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.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
Anand Palani
  • 211
  • 1
  • 2
  • 5
  • 4
    You could check out [twine](https://pypi.org/project/twine/). Worked fine for me with a Nexus on a corporate network – shmee Jun 14 '19 at 07:50
  • 2
    You can't use a simple PUT, PyPi repositories don't work that way. Use twine as suggested above or use the [REST API](https://help.sonatype.com/repomanager3/rest-and-integration-api/components-api#ComponentsAPI-UploadComponent). – rseddon Jun 14 '19 at 20:05

3 Answers3

24

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 
Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Michael Robinson
  • 846
  • 7
  • 22
  • 1
    When i used the repository credentials on the pip.conf and credentials are not used by python when we download/upload packages from repository. How do we hard code credentials for PyPi repository ? what is the best way to have credentials ? – Anand Palani Jun 20 '19 at 17:01
  • You need to create a `$HOME/.pypirc` file. I'll add it to the answer so it's formatted correctly. – Michael Robinson Jun 21 '19 at 08:58
  • 1
    Hi Michael, Thanks for your valuable answer. When I download the packages its asking the password to authenticate the repo. I tried the above configuration which you mentioned on this thread. Its not working. – Anand Palani Jun 24 '19 at 05:26
  • Weird. I assume you mean upload? You could try pointing directly at the file with `twine upload --config-file ` you could also try setting the user/pass as args `twine upload -u -p `. It's probably worth adding `--verbose` too, so you can see what's happening. Other than that, I'm really not sure what else to suggest. – Michael Robinson Jun 24 '19 at 14:42
  • 1
    **.pypirc** file format is out-dated. Please refer https://packaging.python.org/specifications/pypirc/ – shreyas.k Jul 17 '20 at 08:11
  • It looks ok to me, was there something specific that's wrong? – Michael Robinson Jul 29 '20 at 08:50
  • 1
    In my cases it got working: 1) uploading without .pypirc by `--repository-url -u -p --non-interactive`; 2) uploading with .pypirc by `--config-file path/.pypirc --non-interactive`; 3) uploading with .pypirc by `~/.pypirc` (with no additional keys); All of them are not asking for any creds or confirms, but exactly [pypi] section should be specified within when using .pypirc – Александр May 13 '21 at 13:24
  • 1
    If you upload using url directly (without .pypirc), use `--repository-url` instead of `--repository`. – Gürcan Kavakçı Apr 13 '23 at 07:38
8

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

psmolkin
  • 415
  • 3
  • 11
0

At first install twine:

pip install twine

then create .pypirc in $HOME/.pypirc with this content

[distutils]
index-servers = nexus
[nexus]
repository = http://SERVER_IP:SERVER_PORT/repository/pypi-hosted/
username = username
password = password

And upload python packages with

twine upload --repository nexus nvidia_cudnn_cu11-8.5.0.96-2-py3-none-manylinux1_x86_64.whl
BarzanHayati
  • 637
  • 2
  • 9
  • 22