2

I want to install packages with pip and not be asked for the credentials and not to store credentials in pip.conf file This is something which is explained previously here Credentials in pip.conf for private PyPI

So the steps I did. in /home/jenkins folder I create .netrc file:

machine https://artifactory.domain.dev
    login username1
    password password1

in /home/jenkins folder I create pip.conf file:

[global]
index-url = http://artifactory.domain.dev/artifactory/api/pypi/pypi-remote/simple

I create a virtualenv and try to install package:

If I specify URL in the command I am prompted for credentials:

python -m pip install python-cards -v -i https://artifactory.domain.dev/artifactory/api/pypi/pypi-remote/simple
User for artifactory.domain.dev:

If I do not specify -i property then I see everything is installed but from the pypi.org which I shouldn't do that in that way (because on customer servers we will not have access to internet).

 python -m pip install python-cards
Using cached https://files.pythonhosted.org/

It seems like both of my files .netrc and pip.conf are being ignored. Why? Did I set up something wrong?

Thank you!

vel
  • 1,000
  • 1
  • 13
  • 35

2 Answers2

1

Have a look here where to place the pip.conf: https://pip.pypa.io/en/stable/topics/configuration/#location

Probably you want to place it here: /home/jenkins/.config/pip/pip.conf

I do believe that the .netrc should be directly in the home directory, but check that this file is owned by the user that is executing pip. Replace $USER with the correct user (jenkins?) if it is not the current user

chown $USER ~/.netrc 
chmod 0600
Teije
  • 11
  • 4
  • in this link it says it should be at /etc/ https://www.shellhacks.com/pip-install-from-private-pypi-repository/ on the link in the question they are mentioning different location... why is this so confusing? I will test your recommendation – vel Jun 14 '22 at 12:36
  • The **/etc/pip.conf** should also work, then it is available system-wide. There are three options each with a different scope. Each of them is described in the link I posted. The suggestion I provided would only give the user jenkins access to this configuration. – Teije Jun 14 '22 at 12:52
  • Teije I do have some progress. When I set them in the location which you mentioned - I see that now it does target my repo, that is good! `pip install sample1001 Collecting sample1001 User for artifactory.domain.dev:` Bad thing is that is still does not catch `.netrc` file. It seems like it has a bad location as well. If I set credentials in pip.conf file then it will work. But as I read it is much better to have those credentials within the .netrc file – vel Jun 14 '22 at 13:07
  • Perhaps important to check if the **.netrc** file owned by the user that uses pip? following this related post: https://stackoverflow.com/questions/50468951/credentials-in-pip-conf-for-private-pypi?noredirect=1&lq=1 chown $USER ~/.netrc chmod 0600 ~/.netrc – Teije Jun 14 '22 at 14:40
  • Thanks but I have already put that same link at the top of my question... I did `chmod` and `chown` commands. Thanks anyway – vel Jun 14 '22 at 16:04
0

I found this description of .netrc:

Port Independence

Note that the netrc file only deals with connections at the machine level and should not include a port number or protocol designation (http:// or https://), meaning both "mymachine.domain.org:8888" and "https://mymachine.domain.org" are incorrect. Use only the part between the slashes and/or any colon:port.

If you see an error message similar to "Failed connect to mymachine.domain.org:443; Connection refused", remove the port number from your netrc machine definition.

So, in your case it should be:

machine artifactory.domain.dev
login username1
password password1

After that, run the command (it seems that you still need either --index-url or --extra-index-url):

pip install --extra-index-url=https://artifactory.domain.dev <package-name>

Or add index-url or extra-index-url to pip.conf:

[install]
extra-index-url = https://artifactory.domain.dev

By the way, I noticed error here "in /home/jenkins folder I create pip.conf file". pip.conf should be in ~/.pip/pip.conf or in ~/.config/pip/pip.conf by default.

t7e
  • 322
  • 1
  • 3
  • 9