锛堟暟鎹瀛﹀涔犳墜鏈?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/ 锛変腑涓嬭浇瀵瑰簲鐨勬渶鏂扮殑瀹夎鍖咃細

鎶€鏈浘鐗? src=
鍥?

銆€銆€鏈枃閫夋嫨鐨勬槸浠庡畼缃戜笅杞界殑鏈€鏂扮増鏈?code>4.8.2锛屽洜涓?code>miniconda鑷甫Python锛屼箣鍚庢墍鏈夋柊鐜鐨勫垱寤烘垜浠兘鍙互閫氳繃conda鏉ュ疄鏂斤紝鎵€浠ュ缓璁綘鍦ㄥ畨瑁呬箣鍓嶇郴缁熶腑涓嶈淇濇湁鍏朵粬Python鐜銆備笅杞藉畬鎴愪箣鍚庣洿鎺ユ墦寮€瀹夎锛屼竴璺彲浠ユ寜鐓ч粯璁ょ殑閫夐」缁х画锛屽埌鍥?鏄剧ず鐨勬楠ゆ椂涓轰簡鏂逛究涔嬪悗鐨勪娇鐢ㄥ缓璁兘鍕鹃€変笂锛?/p>

鎶€鏈浘鐗? src=
鍥?

銆€銆€瀹屾垚瀹夎鍚庢垜浠繘鍏ユ帶鍒跺彴杈撳叆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>

鎶€鏈浘鐗? src=
鍥?
  • 鐩綍鎻掍欢

    鍦?code>ipynb鏂囦欢涓彲浠ョ敤markdown缂栧啓鍚勭骇鍒爣棰橈紝鍦ㄤ娇鐢ㄤ笅鍒楁彃浠惰嚜鍔ㄧ敓鎴愮洰褰曪細

jupyter labextension install @jupyterlab/toc
鎶€鏈浘鐗? src=
鍥?
  • matplotlib浜や簰寮忕粯鍥?/strong>

    浣跨敤matplotlib浜や簰寮忕粯鍥炬ā寮忥細

pip install ipympl
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib

銆€銆€瀹夎瀹屾垚鍚庡氨鍙互浣跨敤%matplotlib widget寮€鍚氦浜掑紡缁樺浘妯″紡锛堣鎻愬墠瀹夎濂?code>geopandas缁樺浘渚濊禆鍖?code>descartes锛夛細

鎶€鏈浘鐗? src=
鍥?

浣犱篃鍙互鍦ㄤ晶杈规爮涓彂鐜版洿澶氱殑瀹炵敤鎻掍欢锛?/p>

鎶€鏈浘鐗? src=
鍥?

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涓細

鎶€鏈浘鐗? src=
鍥?

鍥?

銆€銆€鎺у埗鍙颁腑浣跨敤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鐜╄浆鏁版嵁绉戝鐜鎼缓的主要内容,如果未能解决你的问题,请参考以下文章

J - Prime Game锛堟暟璁哄垎瑙h川鍥犲瓙)

澶ф暟鎹椂浠o紝鑻规灉鎵嬫満鍜屽畨鍗撴墜鏈虹殑鍖哄埆!

2019-2020-1瀛︽湡20192402銆婄綉缁滅┖闂村畨鍏ㄤ笓涓氬璁恒€嬬鍗佷竴鍛ㄥ涔犳€荤粨

澶ф暟鎹粍浠?瀛︿範鐭ヨ瘑鍥捐氨

绠楁硶銆佹暟鎹粨鏋勫涔犳寚鍗?/h1>

AJAX瀛︿範绗旇

(c)2006-2024 SYSTEM All Rights Reserved IT常识