{"id":51741,"date":"2024-10-08T21:10:17","date_gmt":"2024-10-08T13:10:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51741\/"},"modified":"2024-11-14T10:41:59","modified_gmt":"2024-11-14T02:41:59","slug":"ubuntu-18-04-%e4%b8%8b%e4%bd%bf%e7%94%a8-vim-%e9%85%8d%e7%bd%ae-python-%e9%96%8b%e7%99%bc%e7%92%b0%e5%a2%83","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51741\/","title":{"rendered":"Ubuntu 18.04 \u4e0b\u4f7f\u7528 Vim \u914d\u7f6e Python \u958b\u767c\u74b0\u5883"},"content":{"rendered":"<h1 id=\"ubuntu-18-04-%e4%b8%8b%e4%bd%bf%e7%94%a8-vim-%e9%85%8d%e7%bd%ae-python-%e9%96%8b%e7%99%bc%e7%92%b0%e5%a2%83-zvPHBpSezM\">Ubuntu 18.04 \u4e0b\u4f7f\u7528 Vim \u914d\u7f6e Python \u958b\u767c\u74b0\u5883<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u958b\u767c\u74b0\u5883\u4e2d\uff0cPython \u662f\u4e00\u7a2e\u975e\u5e38\u6d41\u884c\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u5206\u6790\u3001\u6a5f\u5668\u5b78\u7fd2\u3001\u7db2\u9801\u958b\u767c\u7b49\u9818\u57df\u3002\u5c0d\u65bc\u8a31\u591a\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u4f7f\u7528 Vim \u4f5c\u70ba\u7de8\u8f2f\u5668\u4f86\u7de8\u5beb Python \u4ee3\u78bc\u662f\u4e00\u500b\u4e0d\u932f\u7684\u9078\u64c7\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u4f7f\u7528 Vim \u914d\u7f6e Python \u958b\u767c\u74b0\u5883\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-vim-zvPHBpSezM\">\u5b89\u88dd Vim<\/h2>\n<p>\u9996\u5148\uff0c\u78ba\u4fdd\u4f60\u7684 Ubuntu \u7cfb\u7d71\u5df2\u7d93\u5b89\u88dd\u4e86 Vim\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install vim<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u901a\u904e\u8f38\u5165 <code>vim<\/code> \u547d\u4ee4\u4f86\u555f\u52d5 Vim \u7de8\u8f2f\u5668\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-zvPHBpSezM\">\u5b89\u88dd Python<\/h2>\n<p>Ubuntu 18.04 \u9810\u8a2d\u5df2\u7d93\u5b89\u88dd\u4e86 Python 3\uff0c\u4f46\u4f60\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u4f86\u78ba\u8a8d Python \u662f\u5426\u5df2\u5b89\u88dd\uff1a<\/p>\n<pre><code>python3 --version<\/code><\/pre>\n<p>\u5982\u679c\u672a\u5b89\u88dd\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt install python3<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-python-%e9%96%8b%e7%99%bc%e5%b7%a5%e5%85%b7-zvPHBpSezM\">\u5b89\u88dd Python \u958b\u767c\u5de5\u5177<\/h2>\n<p>\u70ba\u4e86\u63d0\u9ad8\u958b\u767c\u6548\u7387\uff0c\u5efa\u8b70\u5b89\u88dd\u4e00\u4e9b Python \u958b\u767c\u5de5\u5177\uff0c\u5982 <code>pip<\/code> \u548c <code>virtualenv<\/code>\u3002\u9019\u4e9b\u5de5\u5177\u53ef\u4ee5\u5e6b\u52a9\u4f60\u7ba1\u7406 Python \u5305\u548c\u865b\u64ec\u74b0\u5883\u3002<\/p>\n<p>\u5b89\u88dd <code>pip<\/code> \u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>sudo apt install python3-pip<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5b89\u88dd <code>virtualenv<\/code>\uff1a<\/p>\n<pre><code>sudo pip3 install virtualenv<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-vim-%e6%94%af%e6%8c%81-python-zvPHBpSezM\">\u914d\u7f6e Vim \u652f\u6301 Python<\/h2>\n<p>\u8981\u4f7f Vim \u66f4\u597d\u5730\u652f\u6301 Python \u958b\u767c\uff0c\u53ef\u4ee5\u5b89\u88dd\u4e00\u4e9b\u63d2\u4ef6\u3002\u6700\u5e38\u7528\u7684\u63d2\u4ef6\u7ba1\u7406\u5668\u662f <code>Vundle<\/code>\u3002\u4ee5\u4e0b\u662f\u5b89\u88dd Vundle \u7684\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u514b\u9686 Vundle \u7684 GitHub \u5009\u5eab\uff1a<\/li>\n<pre><code>git clone https:\/\/github.com\/VundleVim\/Vundle.vim.git ~\/.vim\/bundle\/Vundle.vim<\/code><\/pre>\n<li>\u7de8\u8f2f Vim \u914d\u7f6e\u6587\u4ef6 <code>~\/.vimrc<\/code>\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/li>\n<\/ol>\n<pre><code>set nocompatible              \" be iMproved, required\nfiletype off                  \" required\n\n\" set the runtime path to include Vundle and initialize\nset rtp+=~\/.vim\/bundle\/Vundle.vim\ncall vundle#begin()\n\n\" let Vundle manage Vundle, required\nPlugin 'VundleVim\/Vundle.vim'\n\n\" Add other plugins here\nPlugin 'davidhalter\/jedi-vim'  \" Python autocompletion\nPlugin 'scrooloose\/nerdtree'    \" File explorer\n\ncall vundle#end()            \" required\nfiletype plugin indent on    \" required<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa Vim\uff0c\u7136\u5f8c\u91cd\u65b0\u6253\u958b Vim\uff0c\u904b\u884c <code>:PluginInstall<\/code> \u547d\u4ee4\u4f86\u5b89\u88dd\u63d2\u4ef6\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e8%99%9b%e6%93%ac%e7%92%b0%e5%a2%83-zvPHBpSezM\">\u4f7f\u7528\u865b\u64ec\u74b0\u5883<\/h2>\n<p>\u5728\u958b\u767c Python \u61c9\u7528\u6642\uff0c\u4f7f\u7528\u865b\u64ec\u74b0\u5883\u53ef\u4ee5\u907f\u514d\u5305\u4e4b\u9593\u7684\u885d\u7a81\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u548c\u6fc0\u6d3b\u865b\u64ec\u74b0\u5883\u7684\u6b65\u9a5f\uff1a<\/p>\n<pre><code>mkdir myproject\ncd myproject\nvirtualenv venv\nsource venv\/bin\/activate<\/code><\/pre>\n<p>\u5728\u865b\u64ec\u74b0\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5b89\u88dd\u6240\u9700\u7684 Python \u5305\uff0c\u4e26\u4e14\u9019\u4e9b\u5305\u4e0d\u6703\u5f71\u97ff\u7cfb\u7d71\u7684\u5168\u5c40\u74b0\u5883\u3002<\/p>\n<h2 id=\"%e7%b7%a8%e5%af%ab%e5%92%8c%e9%81%8b%e8%a1%8c-python-%e4%bb%a3%e7%a2%bc-zvPHBpSezM\">\u7de8\u5beb\u548c\u904b\u884c Python \u4ee3\u78bc<\/h2>\n<p>\u5728 Vim \u4e2d\u7de8\u5beb Python \u4ee3\u78bc\u975e\u5e38\u7c21\u55ae\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 <code>vim myscript.py<\/code> \u547d\u4ee4\u5275\u5efa\u4e00\u500b\u65b0\u7684 Python \u6587\u4ef6\uff0c\u7136\u5f8c\u958b\u59cb\u7de8\u5beb\u4ee3\u78bc\u3002\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u904b\u884c Python \u8173\u672c\uff1a<\/p>\n<pre><code>python3 myscript.py<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-zvPHBpSezM\">\u7e3d\u7d50<\/h2>\n<p>\u5728 Ubuntu 18.04 \u4e0a\u914d\u7f6e Vim \u4f5c\u70ba Python \u958b\u767c\u74b0\u5883\u662f\u4e00\u500b\u76f8\u5c0d\u7c21\u55ae\u7684\u904e\u7a0b\u3002\u901a\u904e\u5b89\u88dd\u5fc5\u8981\u7684\u5de5\u5177\u548c\u63d2\u4ef6\uff0c\u4f60\u53ef\u4ee5\u63d0\u9ad8\u958b\u767c\u6548\u7387\uff0c\u4e26\u4eab\u53d7 Vim \u5e36\u4f86\u7684\u5f37\u5927\u529f\u80fd\u3002\u5982\u679c\u4f60\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u90e8\u7f72\u4f60\u7684 Python \u61c9\u7528\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u958b\u767c\u8005\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0cServer.HK \u90fd\u80fd\u6eff\u8db3\u4f60\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u4f7f\u7528 Vim \u914d\u7f6e Python \u958b\u767c\u74b0\u5883\uff0c\u63d0\u5347\u7de8\u7a0b\u6548\u7387\u8207\u751f\u7522\u529b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-51741","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=51741"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51741\/revisions"}],"predecessor-version":[{"id":51742,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51741\/revisions\/51742"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}