锛堟暟鎹瀛﹀涔犳墜鏈?1锛塩onda+jupyter鐜╄浆鏁版嵁绉戝鐜鎼缓
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了锛堟暟鎹瀛﹀涔犳墜鏈?1锛塩onda+jupyter鐜╄浆鏁版嵁绉戝鐜鎼缓相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%96%87%e4%bb%b6%e5%90%8d' title='鏂囦欢鍚?>鏂囦欢鍚?/a> 鎼缓 璇彞 璧勬簮 requests 涓ょ remove 绯荤粺
鏈枃绀轰緥yaml鏂囦欢宸蹭笂浼犺嚦鎴戠殑
Github
浠撳簱https://github.com/CNFeffery/DataScienceStudyNotes
鍥?
2 铏氭嫙鐜鐨勬惌寤轰笌浣跨敤
2.1 浣跨敤conda鍒涘缓铏氭嫙鐜
銆€銆€浠?code>Windows鎿嶄綔绯荤粺涓轰緥锛屽洜涓哄叏绋嬩富瑕佷娇鐢ㄥ懡浠よ锛屾墍浠ュ叾浠栫郴缁熸柟娉曠被浼硷紝鏈夊皯璁歌鍙ユ湁宸紓鐨勫湴鏂归亣鍒伴棶棰樻椂鍙互鑷鏌ユ壘瑙e喅銆傞鍏堟垜浠瑙e喅鐨勬槸鐜鐨勫垱寤猴紝绗竴姝ラ渶瑕佸畨瑁?code>conda鏈嶅姟锛岃繖閲屾垜浠湁Anaconda
鍜?code>miniconda涓ょ鏂瑰紡锛屾湰鏂囬€夋嫨miniconda
浣撶Н灏忓阀锛屼笉浼氬儚Anaconda
閭f牱鑷甫鏁伴噺浼楀鐨勭瀛﹁绠楃浉鍏冲寘鑰屾樉寰楄噧鑲裤€?/p>
銆€銆€鏈夋潯浠朵笂澶栫綉鐨勮鑰呮湅鍙嬪彲浠ュ湪瀹樼綉锛?https://docs.conda.io/en/latest/miniconda.html 锛変笅杞戒笌浣犵殑鎿嶄綔绯荤粺瀵瑰簲鐨勫畨瑁呭寘锛屼篃鍙互鍦?strong>娓呭崕澶у闀滃儚绔?/strong>-鑾峰彇涓嬭浇閾炬帴-搴旂敤杞欢-Conda锛?https://mirrors.tuna.tsinghua.edu.cn/ 锛変腑涓嬭浇瀵瑰簲鐨勬渶鏂扮殑瀹夎鍖咃細
銆€銆€鏈枃閫夋嫨鐨勬槸浠庡畼缃戜笅杞界殑鏈€鏂扮増鏈?code>4.8.2锛屽洜涓?code>miniconda鑷甫Python
锛屼箣鍚庢墍鏈夋柊鐜鐨勫垱寤烘垜浠兘鍙互閫氳繃conda
鏉ュ疄鏂斤紝鎵€浠ュ缓璁綘鍦ㄥ畨瑁呬箣鍓嶇郴缁熶腑涓嶈淇濇湁鍏朵粬Python
鐜銆備笅杞藉畬鎴愪箣鍚庣洿鎺ユ墦寮€瀹夎锛屼竴璺彲浠ユ寜鐓ч粯璁ょ殑閫夐」缁х画锛屽埌鍥?鏄剧ず鐨勬楠ゆ椂涓轰簡鏂逛究涔嬪悗鐨勪娇鐢ㄥ缓璁兘鍕鹃€変笂锛?/p>
銆€銆€瀹屾垚瀹夎鍚庢垜浠繘鍏ユ帶鍒跺彴杈撳叆conda --version
妫€鏌ユ槸鍚︽垚鍔熷畨瑁咃細
C:Usershp>conda --version
conda 4.8.2
銆€銆€杈撳叆conda env list
鏌ョ湅褰撳墠瀛樺湪鐨勬墍鏈夌幆澧冿細
C:Usershp>conda env list
# conda environments:
#
base * C:Conda
銆€銆€鍙互鐪嬪埌鎴戜滑褰撳墠鍙湁1涓幆澧?em>base锛屽嵆miniconda
鑷甫鐨?code>Python锛屽洜涓哄浘3涓垜浠嬀閫変簡Register Miniconda3 as the system Python 3.7锛屾墍浠ュ湪鎺у埗鍙颁腑鐩存帴杈撳叆python
鍙互寰楀埌涓嬪垪缁撴灉锛?/p>
C:Usershp>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation
Type "help", "copyright", "credits" or "license" for more information.
>>> quit() # 閫€鍑?
C:Usershp>
銆€銆€鎺у埗鍙拌緭鍏?code>conda list鍙互鐪嬪埌褰撳墠浠呮湁鐨?em>base鐜涓粎鏈変笅鍒楀寘锛?/p>
C:Usershp>conda list
# packages in environment at C:Conda:
#
# Name Version Build Channel
asn1crypto 1.3.0 py37_0 defaults
ca-certificates 2020.1.1 0 defaults
certifi 2019.11.28 py37_0 defaults
cffi 1.14.0 py37h7a1dbc1_0 defaults
chardet 3.0.4 py37_1003 defaults
conda 4.8.2 py37_0 defaults
conda-package-handling 1.6.0 py37h62dcd97_0 defaults
console_shortcut 0.1.1 4 defaults
cryptography 2.8 py37h7a1dbc1_0 defaults
idna 2.8 py37_0 defaults
menuinst 1.4.16 py37he774522_0 defaults
openssl 1.1.1d he774522_4 defaults
pip 20.0.2 py37_1 defaults
powershell_shortcut 0.0.1 3 defaults
pycosat 0.6.3 py37he774522_0 defaults
pycparser 2.19 py37_0 defaults
pyopenssl 19.1.0 py37_0 defaults
pysocks 1.7.1 py37_0 defaults
python 3.7.6 h60c2a47_2 defaults
pywin32 227 py37he774522_1 defaults
requests 2.22.0 py37_1 defaults
ruamel_yaml 0.15.87 py37he774522_0 defaults
setuptools 45.2.0 py37_0 defaults
six 1.14.0 py37_0 defaults
sqlite 3.31.1 he774522_0 defaults
tqdm 4.42.1 py_0 defaults
urllib3 1.25.8 py37_0 defaults
vc 14.1 h0510ff6_4 defaults
vs2015_runtime 14.16.27012 hf0eaf9b_1 defaults
wheel 0.34.2 py37_0 defaults
win_inet_pton 1.1.0 py37_0 defaults
wincertstore 0.2 py37_0 defaults
yaml 0.1.7 hc54c509_2 defaults
銆€銆€鎺ヤ笅鏉ユ垜浠紑濮嬫潵鎼缓鏈枃鐢ㄤ簬涓句緥璇存槑鐨?code>geopandas鐜锛屼娇鐢?code>conda create -n 鐜鍚嶇О python=鐗堟湰鏉ュ垱寤烘柊鐨勭幆澧冿紝璀杩欓噷鎴戜滑鍒涘缓鍚嶄负python_spatial
鐨勮櫄鎷熺幆澧冿紝Python
鐗堟湰閫夋嫨3.7
锛?/p>
C:Usershp>conda create -n python_spatial python=3.7
銆€銆€閬囧埌Proceed ([y]/n)?
杈撳叆y缁х画锛岀瓑鐩稿叧璧勬簮涓嬭浇骞跺畨瑁呴厤缃畬鎴愬悗锛屽啀娆℃煡鐪嬪綋鍓嶅瓨鍦ㄧ殑鎵€鏈夌幆澧冿細
C:Usershp>conda env list
# conda environments:
#
base * C:Conda
python_spatial C:Condaenvspython_spatial
銆€銆€鍙互鐪嬪埌涓庝箣鍓嶇浉姣斿浜嗘垜浠垰鍒氬垱寤哄ソ鐨?code>python_spatial鐜锛屼娇鐢?code>conda activate 鐜鍚嶇О鏉ユ縺娲绘寚瀹氱殑鐜锛?/p>
C:Usershp>conda activate python_spatial
(python_spatial) C:Usershp>
銆€銆€鍙互鍙戠幇杩欐椂鍛戒护琛屽紑澶村浜?code>(python_spatial)锛岃繖浠h〃鎴戜滑宸茬粡杩涘叆婵€娲荤殑python_spatial
鐜涓紝鎺ョ潃鎴戜滑灏卞彲浠ヤ娇鐢?code>conda鍛戒护鍦ㄥ綋鍓嶇幆澧冧腑瀹夎geopandas
锛屾寜鐓у畼缃戠殑鎺ㄨ崘鏂瑰紡浠?em>conda-forge瀵瑰簲鐨?code>channel杩涜瀹夎锛屾墽琛?code>conda install --channel conda-forge geopandas锛岄亣鍒伴渶瑕侀€夋嫨鐨勫湴鏂逛竴鏍峰湴杈撳叆y锛岃繖閲屼緷璧栧寘杈冨锛岄渶瑕佺瓑寰呰緝闀挎椂闂达紝鐩村埌鏈€鍚?code>done鍑虹幇琛ㄧず瀹夎鎴愬姛锛屽湪鎺у埗鍙颁腑鐩存帴杩涘叆python
锛屾鏌?code>geopandas鏄惁姝g‘瀹夎锛?/p>
(python_spatial) C:Usershp>python
Python 3.7.7 (default, Mar 23 2020, 23:19:08) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import geopandas as gpd
>>>
銆€銆€鑷虫锛屾垜浠凡缁忓畬鎴愪簡geopandas
鍩虹鐜鐨勬惌寤猴紝鎺ヤ笅鏉ユ垜浠潵閰嶇疆浣跨敤jupyter
銆?/p>
2.2 閰嶇疆jupyter lab
銆€銆€绫讳技conda
锛?code>jupyter涔熷垎涓?code>jupyter notebook鍜?code>jupyter lab锛屼袱鑰呮牳蹇冨姛鑳介兘宸笉澶氾紝浣?code>jupyter lab鎷ユ湁鏇村鐨勬嫇灞曞姛鑳斤紝骞朵笖鐣岄潰鍜屾搷浣滄柟寮忎篃鏇村姞鐐叿鏂逛究锛屾墍浠ユ湰鏂囬€夋嫨jupyter lab
锛屽湪涓婁竴鑺備腑鍒涘缓濂界殑python_spatial
鐜涓嬩娇鐢?code>conda install jupyterlab瀹夎鍩虹閮ㄥ垎锛屽畨瑁呯粨鏉熶箣鍚庯紝鍦?code>python_spatial鐜涓嬪彲浠ラ€氳繃鎵цjupyter lab
鏉ユ墦寮€瀹冿紝鍦ㄦ涔嬪墠闇€瑕佸厛涓?code>jupyter lab閰嶇疆铏氭嫙鐜锛屽惁鍒欏彧鑳借瘑鍒埌榛樿鐨?code>base鐜銆?/p>
-
瀹夎ipykernel
閫€鍑鸿櫄鎷熺幆澧冨悗鎵ц
conda install ipykernel
銆?/p> -
涓鸿櫄鎷熺幆澧冨畨瑁卛pykernel
鎵ц
conda install -n python_spatial ipykernel
銆?/p> -
婵€娲昏櫄鎷熺幆澧?amp;灏嗚櫄鎷熺幆澧冨啓鍏upyter鐨刱ernel涓?/strong>
C:Usershp>conda activate python_spatial
(python_spatial) C:Usershp>python -m ipykernel install --user --name python_spatial --display-name
"spatial"
Installed kernelspec python_spatial in C:UsershpAppDataRoamingjupyterkernelspython_spatial
(python_spatial) C:Usershp>
銆€銆€杩欐椂鎴戜滑鍦?code>jupyter lab涓凡缁忓彲浠ュ垏鎹㈠埌python_spatial
鐜浜嗭紝鎺ヤ笅鏉ヤ负浜嗕娇鐢?code>jupyter lab鐨勬彃浠舵嫇灞曪紝闇€瑕佸畨瑁?code>nodejs锛屾垜浠湪python_spatial
涓嬫墽琛?code>conda install nodejs鍗冲彲锛屽畬鎴愬畨瑁呬箣鍚庢牴鎹嚜宸卞鎻掍欢鍔熻兘鐨勯渶瑕佸彲浠ュ垎鍒畨瑁呬笉鍚岀殑鎻掍欢锛屼笅闈妇鍑犱釜甯哥敤鐨勪緥瀛愶細
-
html浜や簰閮ㄤ欢鎻掍欢
涓轰簡鍦?code>jupyter lab涓覆鏌撲竴浜沨tml閮ㄤ欢锛岃濡?code>tqdm涓殑浜や簰寮忚繘搴︽潯锛屽湪铏氭嫙鐜涓嬫墽琛屼笅鍒楀懡浠わ細
pip install ipywidgets
jupyter labextension install @jupyter-widgets/jupyterlab-manager
銆€銆€瀹屾垚鍚庢墽琛?code>jupyter lab锛屽湪鎵撳紑鐨勬搷浣滅晫闈腑notebook涓嬬偣鍑?code>python_spatial鍒涘缓鏂扮殑notebook锛屾墽琛屽涓嬪懡浠わ紙鎻愬墠瀹夎濂?code>tqdm锛夛紝鍙互鐪嬪埌鍑虹幇浜?strong>浜や簰寮?/strong>鐨勮繘搴︽潯锛?/p>
-
鐩綍鎻掍欢
鍦?code>ipynb鏂囦欢涓彲浠ョ敤
markdown
缂栧啓鍚勭骇鍒爣棰橈紝鍦ㄤ娇鐢ㄤ笅鍒楁彃浠惰嚜鍔ㄧ敓鎴愮洰褰曪細
jupyter labextension install @jupyterlab/toc
-
matplotlib浜や簰寮忕粯鍥?/strong>
浣跨敤
matplotlib
浜や簰寮忕粯鍥炬ā寮忥細
pip install ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
銆€銆€瀹夎瀹屾垚鍚庡氨鍙互浣跨敤%matplotlib widget
寮€鍚氦浜掑紡缁樺浘妯″紡锛堣鎻愬墠瀹夎濂?code>geopandas缁樺浘渚濊禆鍖?code>descartes锛夛細
浣犱篃鍙互鍦ㄤ晶杈规爮涓彂鐜版洿澶氱殑瀹炵敤鎻掍欢锛?/p>
2.3 铏氭嫙鐜鐨勫浠藉拰鎭㈠
銆€銆€conda
鎻愪緵浜嗗皢铏氭嫙鐜瀵煎嚭涓?code>yaml鏂囦欢鐨勫姛鑳斤紝浣垮緱鎴戜滑鍙互淇濈暀濂戒笉瀹规槗鍒涘缓濂界殑铏氭嫙鐜涓殑閰嶇疆淇℃伅锛屾牸寮忓conda env export > 瀵煎嚭璺緞鏂囦欢鍚?yml
锛岃濡傛垜浠鍑哄墠闈㈠垱寤哄ソ鐨?code>python_spatial鍒版墍闇€璺緞涓嬶細
(python_spatial) C:Usershp>conda env export > C:UsershpDesktoppython_spatial.yml
(python_spatial) C:Usershp>
銆€銆€涔嬪悗浣犲彲浠ュ湪瀹夎濂?code>conda鏈嶅姟鐨勫叾浠栨満鍣ㄤ笂鎸夌収conda env create -n 鏂扮幆澧冨悕绉?-f=璺緞鏂囦欢鍚?yml
锛岃濡傛垜浠氨鍦ㄦ湰鏈轰笂鐢ㄥ凡缁忓鍑虹殑python_spatial.yml
澶嶅埗涓烘柊鐨勮櫄鎷熺幆澧冿紝鑰愬績绛夊緟涔嬪悗conda
浼氳嚜鍔ㄥ畬鎴愬墠闈㈡墍鏈夋垜浠墜鍔ㄥ疄鐜扮殑姝ラ锛?/p>
conda create -n new_python_spatial -f=C:UsershpDesktoppython_spatial.yml
銆€銆€涔嬪悗鍙渶瑕佸儚鍓嶆枃涓竴鏍锋墽琛?code>python -m ipykernel install --user --name new_python_spatial --display-name "new spatial"浠庤€屼负jupyter lab
娣诲姞鏂扮殑铏氭嫙鐜鐨?em>kernel淇℃伅锛屽湪new_python_spatial
鐜涓嬪惎鍔?code>jupyter lab锛岃繖鏄垜浠彲浣跨敤鐨勭幆澧冨彉鎴愪簡3涓細
鍥?
銆€銆€鎺у埗鍙颁腑浣跨敤jupyter kernelspec list
鏌ョ湅淇℃伅锛?/p>
C:Usershp>jupyter kernelspec list
Available kernels:
new_python_spatial C:UsershpAppDataRoamingjupyterkernels
ew_python_spatial
python_spatial C:UsershpAppDataRoamingjupyterkernelspython_spatial
python3 C:Condasharejupyterkernelspython3
銆€銆€鎺ョ潃浣跨敤jupyter kernelspec remove kernel鍚嶇О
瀵瑰叾杩涜绉婚櫎鍗冲彲锛?/p>
C:Usershp>jupyter kernelspec remove new_python_spatial
Kernel specs to remove:
new_python_spatial C:UsershpAppDataRoamingjupyterkernels
ew_python_spatial
Remove 1 kernel specs [y/N]: y
[RemoveKernelSpec] Removed C:UsershpAppDataRoamingjupyterkernels
ew_python_spatial
銆€銆€涔嬪悗鍦ㄥ惎鍔?code>jupyter lab灏变細鍙戠幇娈嬩綑鐨?em>kernel璺熺潃娑堝け浜嗐€?/p>
銆€銆€浠ヤ笂灏辨槸鏈枃鐨勫叏閮ㄥ唴瀹癸紝瀵瑰簲鐨?code>yaml鏂囦欢宸蹭笂浼犺嚦鏂囩珷寮€澶寸殑Github
浠撳簱涓紝浣犲彲浠ョ洿鎺ュ熀浜庡畠鍒涘缓瀵瑰簲鏈枃python_spatial
鐨勮櫄鎷熺幆澧冦€?/p>
以上是关于锛堟暟鎹瀛﹀涔犳墜鏈?1锛塩onda+jupyter鐜╄浆鏁版嵁绉戝鐜鎼缓的主要内容,如果未能解决你的问题,请参考以下文章