Most of the python notebooks I run tend to need some setup for the initial run, using
! pip install ...
Executing the setup code every time the notebook is run is inefficient, so I would prefer to avoid that. Also, I don't want to move the setup code to a different notebook because usually it is just a few lines of code.
The solution for me was to run a small one line python script that only tries to import the module. If the import was successful, the pip install command does not get run. Conversely, if the import was unsuccessful the pip install command is run.
! python -c 'import cloudant' || pip install cloudant --user
The double pipe is a bash statement that can be considered equivalent to an 'or' statement in a programming language.
The above example installs the cloudant python library. Just change the above line for the libraries you wish to install.
- Mockito verify not working with serialized/deserialized mock
- Spark, Cassandra and Kafka (SMACK) SaaS or PaaS providers
- How to shutdown a spark application without knowing driver Id via spark-submit
- Watson Studio — Error Downloading Desktop Version
- How to prevent 'pip install …' running every time I run the whole notebook?
- How to convert spark dataframe array to tuple
- spark.createDataFrame () not working with Seq RDD
- Partitioning of Data Frame in Pyspark using Custom Partitioner
- Use of lit() in expr()
- Spark coalesce relationship with number of executors and cores