1

in a short format, I'm preparing a python script to search all required dependencies in a private pypi repo

if all dependencies exist in the repo, the script tops, if not it builds them and pushes them to the pypi repo

I have seen some examples using:

search_command = pip.commands.search.SearchCommand() options, _ = search_command.parse_args([name, "--index", publish_pypi_simple_url]) pypi_hits = search_command.search(name, options) hits = pip.commands.search.transform_hits(pypi_hits)

However when running this code i get

AttributeError: module 'pip' has no attribute 'commands'

Does anyone have a good solution for performing pip searches in a private pypi repository with a python script?

Thank you all in advance

EDIT:

My problem was related to badly installed python environments.

Joel Almeida
  • 62
  • 1
  • 10
  • 1
    How about running it as an [external system command](https://stackoverflow.com/questions/89228/calling-an-external-command-in-python)? You can get back both `stdout` and `stderr`. – hyperTrashPanda Feb 06 '19 at 12:03
  • well these built in functions make it much easier to parse results – Joel Almeida Feb 07 '19 at 16:44

2 Answers2

0

Works for me.

-->python2 -c "import pip; print(pip.commands); print(pip.commands.search)"
<module 'pip.commands' from '/usr/lib/python2.7/site-packages/pip/commands/__init__.pyc'>
<module 'pip.commands.search' from '/usr/lib/python2.7/site-packages/pip/commands/search.pyc'>

-->python3 -c "import pip; print(pip.commands); print(pip.commands.search)"
<module 'pip.commands' from '/usr/lib/python3.6/site-packages/pip/commands/__init__.py'>
<module 'pip.commands.search' from '/usr/lib/python3.6/site-packages/pip/commands/search.py'>
Axeon Thra
  • 334
  • 3
  • 14
0

There is a convenient way to execute all pip commands in the same way.

import pip
pip._internal.main(['search', package])

You can replace "search" with "install" etc.

For more info, you can read another answer