1、Windows環(huán)境下pyenv-win的安裝
pyenv用于Linux系統(tǒng)中,用來管理多版本的Python環(huán)境,由bash腳本編寫,使用pyenv-installer來安裝。pyenv github下載地址:https://github.com/pyenv/pyenv。
pyenv-win用于Windows環(huán)境中,下載地址:https://github.com/pyenv-win/pyenv-win。
Windows 10環(huán)境中pyenv-win的安裝步驟如下(從下載的壓縮包安裝):
(1)解壓pyenv-win壓縮包pyenv-win-master.zip在E:\Program Files (x86)目錄下。
(2)配置環(huán)境變量PATH,添加如下條目:
E:\Program Files (x86)\pyenv-win-master\pyenv-win\bin
E:\Program Files (x86)\pyenv-win-master\pyenv-win\shims
(3)在命令行輸入:
pyenv --version
,出現(xiàn)如下輸出即可顯示pyenv-win已安裝成功:
pyenv 1.2.2
。
2、安裝Python3.7.3
(1)Python3.7.3是當前最新的穩(wěn)定版本,下載地址:https://www.python.org/downloads/release/python-373/
(2)Python3.7.3的安裝步驟:
1)安裝python-3.7.3-amd64.exe,點擊“Next”,直到結束。
2)在安裝過程中注意點擊“Add Python 3.7 to PATH”。
3)安裝完成在命令行輸入:
python --version
,得到如下輸出:
Python 3.7.3
,表明Python3.7.3安裝成功。
3、pyenv的使用
(1)查看pyenv可以使用的命令
C:\Users\DELL>pyenv help
pyenv 1.2.2
Usage: pyenv
[
]
Some useful pyenv commands are:
commands List all available pyenv commands
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
rehash Rehash pyenv shims (run this after installing executables)
version Show the current Python version and its origin
versions List all Python versions available to pyenv
exec Runs an executable by first preparing PATH so that the selected Python
See `pyenv help
' for information on a specific command.
For full documentation, see: https://github.com/pyenv-win/pyenv-win#readme
(2)查看pyenv可以使用的python版本,在Linux版本的pyenv中,這些python版本都存放在~/.pyenv/versions/目錄下。
C:\Users\DELL>pyenv versions
C:\Users\DELL>pyenv version
(3)在pyenv中安裝python解釋器
C:\Users\DELL>pyenv install 3.7.3
C:\Users\DELL>pyenv install --list
(4)更新pyenv
C:\Users\DELL>pyenv update
(5)local命令
local命令用來管理Python版本,切換當前目錄及其子目錄的Python版本, 可以通過刪除.python-version文件恢復默認Python版本。
(6)global命令
global命令用來管理Python版本,切換全局默認Python版本。
(7)virtualenv命令
virtualenv用來管理Python虛擬環(huán)境,每個Python虛擬環(huán)境相當于是一個獨立的Python版本。
創(chuàng)建虛擬環(huán)境命令:
pyenv virtualenv 3.7.3 yanyan
。
其中,3.7.3是Python的基礎版本,yanyan是virtualenv的名字。在Linux版本的pyenv中,yanyan存放在~ /.pyenv/versions/yanyan中,這是一個鏈接文件,鏈接的是~/.pyenv/versions/3.7.3/envs/yanyan目錄。
(8)uninstall命令
卸載某個python版本的解釋器, 包括虛擬環(huán)境:
pyenv uninstall yanyan
。
4、pip工具
(1)查看pip工具
C:\Users\DELL>pip help
(2)查看pip版本
pip -V
(3)用pip工具安裝Python插件
pip install xxx yyy
例如:用pip同時安裝redis和ipython:
pip install redis ipython
。
(4)列出用pip工具已安裝的Python插件及其版本
pip list
(5)用pip工具搜索Python插件
pip search KEYWORD
或者:
pypi search KEYWORD
(6)查詢pip安裝選項
pip help install
(7)用pip導出當前已安裝Python插件的名字和版本號,形成requirement文件(該名字可隨意)
pip freeze > requirement
按照已導出的一臺機器上的Python插件的名字和版本號的requirement文件,用pip工具在另一臺機器上安裝對應版本的Python插件,目的是可以批量安裝Python插件,并保持這些插件之間兼容性與之前環(huán)境穩(wěn)定的機器相同。
安裝命令:
pip install -r requirement
(8)pip的通用配置
Linux中:
mkdir ~/.pip
,
$ vim ~/.pip/pip.conf
,pip.conf文件如下:
[global]
index-url=http://mirrors.aliyun.com/pypi/simple
trusted-host=mirrors.aliyun.com
Windows中:在C:\Users\yanyan,也就是當前Windows登錄用戶的家目錄中(該家目錄可以在開始菜單->運行中輸入.即可到達),新建pip文件夾,在pip文件夾中新建pip.ini文件,即新建
~/pip/pip.ini
文件,文件內容如下:
[global]
index-url=http://mirrors.aliyun.com/pypi/simple
trusted-host=mirrors.aliyun.com
即可用阿里云的鏡像站點下載 https://pypi.org/ 倉庫中的文件,pip也正是pypi(Python Package Index)的簡寫形式。同樣,清華、豆瓣的國內鏡像也可以下載pypi的Python包文件。
5、ipython和jupyter
(1)ipython
增強的Python Shell,可以自動補全、自動縮進、支持shell,增加了很多函數(shù)。
(2)jupyter
jupyter是從iPython中獨立出來的項目,可在瀏覽器中交互式使用的工具,后臺使用ipython實現(xiàn)??旖萱I:shift + Enter、Ctrl + Enter、dd、m。
(3)用pip安裝ipython
用pip安裝ipython命令:
C:\Users\DELL>pip install ipython
。
安裝完成出現(xiàn)如下提示:
You are using pip version 19.0.3, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
升級pip:
python -m pip install --upgrade pip
。
然后設置pip從國內的鏡像下載python文件。
(4)用pip安裝jupyter
安裝命令:
pip install jupyter
。
(5)jupyter的使用
1)在瀏覽器端啟動jupyter:
jupyter notebook
,該jupyter進程監(jiān)聽在本地8888端口。瀏覽器地址顯示為:http://localhost:8888/tree#notebooks, 選擇Python 3,進入編輯界面:http://localhost:8888/notebooks/Untitled.ipynb?kernel_name=python3。
2)安裝jupyter的服務器端不啟動瀏覽器,要在客戶端的瀏覽器上訪問jupyter,則服務器端jupyter的啟動命令為:
jupyter notebook --ip=0.0.0.0 --no-browser
,假設安裝jupyter的服務器的ip地址為192.168.2.1,則客戶端本地瀏覽器訪問服務器端的jupyter地址如下:http://192.168.2.1:8888/tree。
3)
jupyter notebook --ip=192.168.2.1 --port=8888
:指定只能由192.168.2.1的客戶端訪問服務器端的jupyter。
4)給jupyter設置密碼:
jupyter notebook password
。
更多文章、技術交流、商務合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
