JuPyter(IPython) Notebooks中使用pip安裝Python的模塊
剛開始接觸JuPyter Notebook的時候覺得這是個不錯的寫技術博客的工具,可以很直觀的把代碼和結果結合在一起。於是想着趁熱打鐵,把前段時間學習PyQuery的經驗總結一下分享出來。可是IPython里默認沒有PyQuery模塊,而且不能直接運行pip去安裝。查了一下StackOverflow之后終於找到了下面的代碼,運行之后就可以在JuPyter Notebook里使用PyQuery了。
import pip
def install(package):
pip.main(['install', package])
install('pyquery')
輸出:
Requirement already satisfied (use --upgrade to upgrade): pyquery in c:\users\alvin\anaconda3\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): lxml>=2.1 in c:\users\alvin\anaconda3\lib\site-packages (from pyquery)
Requirement already satisfied (use --upgrade to upgrade): cssselect>0.7.9 in c:\users\alvin\anaconda3\lib\site-packages (from pyquery)
You are using pip version 7.1.2, however version 8.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
