0

I am new to python. How can I change the name of installation that is done using pip. I.e

pip3 install requests && echo "done installing"

what I want to do is import it under a different name in my script. so instead of import requests it would be import whatevernameiwant. I run centos if it matters

  • 3
    Does this answer your question? [How to install python package with a different name using PIP](https://stackoverflow.com/questions/27308293/how-to-install-python-package-with-a-different-name-using-pip) – GTBebbo May 02 '20 at 21:43

1 Answers1

2

import library_name as my_alias

eg:

import math as maths_is_cool
a = maths_is_cool.sqrt(4)
print(a)
# Prints 2.0

This will work for any library, even if it is installed via pip. I reccommend if you are sharing the project, you create a requirements.txt file to track the libraries you have installed that your code depends on.

GTBebbo
  • 1,198
  • 1
  • 8
  • 17