0

I have a list of Python projects (libraries) such as:

libraries = ['numpy', 'pandas', 'matplotlib', 'torch', 'gensim', 'cv2', 'tpot', 'librosa']

I would like to get these installed from within Python code (similar to pip install libraries) while ignoring potential failures. How do I proceed with such a task?

  • Do you know about [_pip_'s `requirements.txt` files](https://pip.pypa.io/en/stable/user_guide/#requirements-files)? – sinoroc Feb 26 '20 at 12:53
  • create a requirement.txt file and you can install once – Mohammad Aarif Feb 26 '20 at 12:54
  • @MohammadAarif Thanks a lot, guys I tried with requirements.txt initially but I'm unable to use try-catch to avoid "No matching distribution found" error. By any chance can we pass this error. – Chiru Harshith Feb 26 '20 at 13:00
  • @sinoroc I tried with requirements.txt initially but I'm unable to use try-catch to avoid "No matching distribution found" error. By any chance can we pass this error. – Chiru Harshith Feb 26 '20 at 13:00
  • so if you want to achieve your requirement as you have explained you have to use a loop – Mohammad Aarif Feb 26 '20 at 13:22
  • @Chiru Do you want to do the install from the command line (bash, shell, etc.) or from Python code (script, module, application, etc.)? – sinoroc Feb 26 '20 at 14:14
  • @sinoroc I'm using jupyter notebook to install em'. Anyhow bash commands can be utilized inside a jupyter notebook. I have hundreds of libraries to be installed, Is there any way that I can install them all with a command and ignore the errors caused by some third party libraries in between. – Chiru Harshith Feb 26 '20 at 15:43
  • Yes there are for sure some solutions. I think you should rephrase your question though, since it has been closed (wrongly, from my point of view, since suggested similar questions have subpar answers). Maybe state clearly in the question that you want to install from within Python code (not from the command line) and can't or won't use a `requirements.txt` file, because you want to skip over failed installations. – sinoroc Feb 26 '20 at 16:02
  • @ChiruHarshith We haven't managed to get the question reopened, so I will try to answer here... First make sure to read ["Using pip from your program"](https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program). You would probably want to iterate over the `libraries` list (`for library in libraries:`)and do something like `subprocess.check_call([sys.executable, '-m', 'pip', 'install', library])` in a `try:` clause to catch or ignore specific exceptions, so that the installation continues with the next library in case one fails. – sinoroc Feb 28 '20 at 09:17

0 Answers0