-
python Linux 環境 (版本隔離工具)
首先新建用戶,養成良好習慣
1 useradd python
-
-
1、安裝pyenv
-
GitHub官網:
https://github.com/pyenv/pyenv-installer/blob/master/README.rst
Install:
$ curl
https://pyenv.run | bash
pyenv.run redirects to the install script in this repository and the invocation above is equivalent to:
Restart your shell so the path changes take effect:
You can now begin using pyenv.
Update:
$ pyenv update
Uninstall: pyenv is installed within $PYENV_ROOT (default: ~/.pyenv). To uninstall, just remove it:
$ rm -fr ~/.pyenv
and remove these three lines from .bashrc:
export PATH="$HOME/.pyenv/bin:$PATH"eval "$(pyenv init -)"eval "$(pyenv virtualenv-init -)"
If you need, export USE_GIT_URI to use git:// instead of https:// for git clone.
-
-
2、安裝python
-
查看python可用版本
[python@zhangyi-centos7 ~]$ pyenv install -l
2.1 在線安裝

2.2如網絡環境不好
到官網下載 對應版本源碼
https://www.python.org/downloads/source/
兩個包都下載好
Python-x.x.x.tar.xz
Python-x.x.x.tgz
放入用戶目錄下的.pyenv/cache
makedir -r ~/.pyenv/cache
3、3.7版本依賴問題:
3.7版本需要一個新的包libffi-devel,安裝此包之后再次進行編譯安裝即可。
#yum install libffi-devel -y
若在安裝前移除了/usr/bin下python的文件鏈接依賴,此時yum無法正常使用,需要自己下載相關軟件包安裝,為節省讀者時間,放上鏈接
#rpm -ivh libffi-devel-3.0.13-18.el7.x86_64.rpm
安裝完成后重新進行make install,結束后再次配置相關文件的軟連接即可。
4、使用 pyenv 進行版本隔離
查看已安裝的python版本
5、把用戶目錄下的環境設置成新安裝的python版本
pyenv local 3.7.4
6、增加虛擬環境
pyenv virtualenv zhangyi
查看虛擬環境
7、安裝ipython
切換pip源
Linux系統:
mkdir ~/.pip cat > ~/.pip/pip.conf << EOF [global] trusted-host=mirrors.aliyun.com index-url=https://mirrors.aliyun.com/pypi/simple/ EOF pip install ipython
8、安裝jupyter
pip install jupyter
啟動jupyter初始化密碼
jupyter notebook passwd
指定jupyter 啟動綁定的ip
jupyter notebook --ip=0.0.0.0
瀏覽器訪問jupyter
9、Python 虛擬環境包導出/導入
導出
pip freeze > requirement
導入
pip -r requirement
這里不做演示了