Sometimes, the users may not need to install all dependencies of a package, since they will not use the part of it.
We can assign some optional dependencies for a python package.
How
setup.py
Add the extras_require parameter in the setup function.
setup(
# ...
extras_require={
'plotter': ['matplotlib'],
'full': ['matplotlib', 'tensorflow'],
},
}
Command Line
pip install package_name
pip install package_name[plotter] # Install matplotlib
pip install package_name[full] # Install matplotlib, tensorflow
CVNN
Take CVNN, a python package, as an example:
Document
By its document, we can install minimum dependencies:
pip install cvnn
It also provides plotting functions:
pip install cvnn[plotter]
Source Code
In python source codes, the package put import part into a try block:
try:
import plotly
import plotly.graph_objects as go
import plotly.figure_factory as ff
AVAILABLE_LIBRARIES.add('plotly')
except ImportError as e:
logger.info("Plotly not installed,...")
Reference
About the author
後端工程師。 不定時張貼一些寫扣時的筆記,有時英文,有時中文。 「如果,我是魔女的話...」
Comments
Join the discussionNo comments yet. Be the first to comment.
