hyper-v中搭建本地伺服器linux(CentOS 7)的python環境
阿新 • • 發佈:2019-01-11
新建虛擬機器->安裝CentOS7->新建虛擬交換機:內部網路->CentOS7設定->網路介面卡:虛擬交換機:新建虛擬交換機->進入CentOS
# cd /etc/sysconfig/network-scripts/
# ls
# vi ifcfg-eth0
新增或修改
ONBOOT=yes
儲存退出(按ESC再:wq回車)
windows中本地網路連線將乙太網與vEthernet橋接
# service network restart
進路由器設定給linux分配靜態IP
git安裝
# yum install git -y
安裝python編譯依賴
# yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel # adduser <name>
--------切使用者-------- 安裝pyenv
$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
(若curl出錯(35)SSL connect error ,需要配置一個有校新包的yum源
# vim /etc/yum.repos.d/dvd.repo
新增下文字
[updates]
name=CentOS-Updates
baseurl=https://mirrors.aliyun.com/centos/6.9/os/x86_64
gpgcheck=0
# yum repolist
然後更新nss # yum update nss ~/.bash_profile中追加pyenv
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)" $ vim ~/.bash_profile 使用pyenv的install安裝所需版本的python
$ pyenv install help
$ pyenv install -l
$ pyenv install 3.7.1 本地安裝
$ cd .pyenv
$ mkdir cache
$ cd cache/ use Xftp copy python-3.7.1.tar.zx&python-3.7.1.tgz to /home/python/.pyenv/cache/ $ pyenv install 3.7.1 若 ModuleNotFoundError: No module named '_ctypes',其實是缺少了一個新需要的開發包libffi-devel,安裝後即可再返回使用者安裝python
# yum install libffi-devel -y (包在base) 切換python本版 [global 全域性設定、shell 使用者設定、local 目錄設定] $ python local 3.7.1 virtualenv 虛擬環境 $ pyenv virtualenv 3.7.1 <Vname>
$ pyenv local <Vname> 建立 .pip 資料夾
$ mkdir .pip
$ cd .pip
$ touch pip.conf
$ vim pip.conf
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com
$ cd
$ cd <Vname>
安裝ipython&jupyter和jupyter配置
$ pip install ipython
$ pip install jupyter
首先輸入ipython生成祕鑰
$ ipython
>>>from notebook.auth import passwd
>>>passwd() 使用jupyter前先設定密碼
$ jupyter notebook password
$ jupyert notebook --ip=0.0.0.0 在windows瀏覽器中輸入地址 192.168.xxx.xxx:8888
如果windows的瀏覽器連線不上jupyter,有可能是linux 防火牆阻止了,關閉掉
# systemctl stop firewalld
port&firewall more: https://www.cnblogs.com/moxiaoan/p/5683743.html
其它可能用到的指令:
檢視linux本地埠 打包packages及載入
$ ss -tanl $ pip freeze > <name>
$ pip install -r <file_packages>
# yum -y install gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip2-devel # adduser <name>
--------切使用者-------- 安裝pyenv
$ curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
(若curl出錯(35)SSL connect error ,需要配置一個有校新包的yum源
# vim /etc/yum.repos.d/dvd.repo
新增下文字
[updates]
name=CentOS-Updates
baseurl=https://mirrors.aliyun.com/centos/6.9/os/x86_64
gpgcheck=0
# yum repolist
然後更新nss # yum update nss ~/.bash_profile中追加pyenv
export PATH="/home/python/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)" $ vim ~/.bash_profile 使用pyenv的install安裝所需版本的python
$ pyenv install help
$ pyenv install -l
$ pyenv install 3.7.1 本地安裝
$ cd .pyenv
$ mkdir cache
$ cd cache/ use Xftp copy python-3.7.1.tar.zx&python-3.7.1.tgz to /home/python/.pyenv/cache/ $ pyenv install 3.7.1 若 ModuleNotFoundError: No module named '_ctypes',其實是缺少了一個新需要的開發包libffi-devel,安裝後即可再返回使用者安裝python
# yum install libffi-devel -y (包在base) 切換python本版 [global 全域性設定、shell 使用者設定、local 目錄設定] $ python local 3.7.1 virtualenv 虛擬環境 $ pyenv virtualenv 3.7.1 <Vname>
$ pyenv local <Vname> 建立 .pip 資料夾
$ mkdir .pip
$ cd .pip
$ touch pip.conf
$ vim pip.conf
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com
$ cd
$ cd <Vname>
安裝ipython&jupyter和jupyter配置
$ pip install ipython
$ pip install jupyter
首先輸入ipython生成祕鑰
$ ipython
>>>from notebook.auth import passwd
>>>passwd() 使用jupyter前先設定密碼
$ jupyter notebook password
$ jupyert notebook --ip=0.0.0.0 在windows瀏覽器中輸入地址 192.168.xxx.xxx:8888