python 環境配置

安裝 pyenv

# 安裝依賴
https://github.com/pyenv/pyenv/wiki/Common-build-problems#requirements

### Ubuntu
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev

curl -L https://raw.github.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
echo 'source ~/.bashrc' >> ~/.bash_profile
# 安裝 3.6.0
pyenv install --list
pyenv 3.6.0 install -v
# 使用搜狐鏡像下載到 ~/.pyenv/cache中
v=3.5.2
wget http://mirrors.sohu.com/python/$v/Python-$v.tar.xz -P ~/.pyenv/cache/
pyenv install $v  

# 建立新的環境,位於 ~/.pyenv/versions/
pyenv virtualenv 3.6.0 env360

# 切換到新的環境
pyenv activate env360

# 退回到系統環境
pyenv deactivate

# 刪除新建立的環境
rm -rf ~/.pyenv/versions/env360/

安裝本身的項目依賴

pip freeze > requirements.txt
pip install -r requirements.txt
scipy/pandas/ipython/jupyter/opencv-python/keras
pip install -U scikit-learn==python

使用科大源

pip install <包名> -i http://pypi.mirrors.ustc.edu.cn/simple/

inux下,修改 ~/.pip/pip.conf (沒有就建立一個), 修改 index-url至ustc 豆瓣和ustc的比較全,內容以下:

[global]
index-url = http://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host = pypi.mirrors.ustc.edu.cn
 
windows下,直接在user目錄中建立一個pip目錄,如:C:\Users\xx\pip,新建文件pip.ini,內容以下

 [global]
 index-url = https://pypi.tuna.tsinghua.edu.cn/simple

安裝jupyter
pip install jupytergit

設置密碼
from notebook.auth import passwd
passwd()github

生成配置文件

jupyter notebook --generate-configsql

修改配置文件

vim ~/.jupyter/jupyter_notebook_config.pyvim

c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:bcd259ccf... '
c.NotebookApp.open_browser = False
c.NotebookApp.port = 9999
c.NotebookApp.notebook_dir = '/home/xsy/code'
windows

啓動

jupyter notebookbash

相關文章
相關標籤/搜索