0
点赞
收藏
分享

微信扫一扫

我们到底该怎么入门网络安全?一般人还真不行

流计算Alink 2023-05-20 阅读 52

文章目录

Python升级

ubuntu下升级python到3.8

add-apt-repository ppa:jonathonf/python-3.8
apt-get update
apt-get install python3.8

调整版本优先级:

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
update-alternatives --install /usr/bin/python python /usr/bin/python3.8 3

# 或直接修改软连接
ln -s /usr/bin/python3.8 /usr/bin/python3
ln /usr/bin/python3 /usr/bin/python

安装python开发包:

apt install -y python3.8-dev

普通用户的site-packages默认在自己目录下:

# 查看site位置:
python3 -m site

# 统一设定site为(/home/pythonLib),在~/.bashrc中添加:
export PYTHONUSERBASE=/home/pythonLib
export PATH=$PATH:$PYTHONUSERBASE/bin

出现No module named ‘apt_pkg’:

cd /usr/lib/python3/dist-packages/

ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so apt_pkg.so 

pip

更新pip:

# 更新
python -m pip install --upgrade pip

# 若不存在,需要安装
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
apt-get install python3.8-distutils # 缺少util失败时
python get-pip.py

设定国内源:

# 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
# 阿里云:http://mirrors.aliyun.com/pypi/simple/
# 豆瓣:http://pypi.douban.com/simple/

# 临时,若提示不受信任则添加 --trusted-host mirrors.tuna.tsinghua.edu.cn
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/

# 永久 ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
format = columns
trusted-host = mirrors.tuna.tsinghua.edu.cn

Conda

安装

从官网(https://www.anaconda.com/products/distribution)下载对应安装包:
bash Anaconda3-2021.11-Linux-x86_64.sh

  • 一路回车,同意条款;
  • 设定安装目录(最后的文件夹要不存在,由conda创建);
  • 允许初始化配置(即更新bashrc文件);

使安装生效:source ~/.bashrc

设定国内源,将以下内容写入~/.condarc中:

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

执行conda clean -i清除索引缓存

通过conda或pip安装的包的路径(conda3,python3.9为例):

  • linux:{conda-dir}/anaconda3/lib/{python3.9}/site-packages/
  • windows:{conda-dir}/anaconda3/lib/site-packages/

常用命令

conda常用的命令。

  • conda list 查看安装了哪些包。
  • conda env list 或 conda info -e 查看当前存在哪些虚拟环境
  • conda update conda 检查更新当前conda

创建python虚拟环境。

  • conda create -n {env_name} python=X.X(2.7、3.6等):创建python版本为X.X的虚拟环境。
  • conda activate {env_name}:激活虚拟环境
  • conda deactivate {env_name}:退出虚拟环境(激活base)
  • conda remove -n {env_name} --all:删除虚拟环境

安装包:

  • conda install -n {env_name} [package]:安装package到{env_name}中;
  • conda remove --name {env_name} [package]:移除{env_name}中的package;

也可先激活环境后,直接安装(此时可用pip,很多包conda是不支持的):

  • conda install [package]
  • pip install [package]

PIP命令

  • pip install [package]:安装最新版本
    • pip install SomePackage==1.0.4:指定版本
    • pip install ‘SomePackage>=1.0.4’:最小版本
  • pip install --upgrade [package]:升级包
  • pip uninstall [package]:卸载包
  • pip search [package]:搜索包
  • pip show -f [package]:查看指定包的详细信息
  • pip list:列出已安装的包
  • pip list -o:查看可升级的包
  • pip uninstall [package]:卸载包
PY_MODEL=gunicorn
echo To check ${PY_MODEL}...
#if conda list ${PY_MODEL} | grep -v '^#' >/dev/null 2>&1; then
if pip show ${PY_MODEL} >/dev/null 2>&1; then
  echo ${PY_MODEL} installed
else
  echo ${PY_MODEL} not found, to install now ...
#  conda install --freeze-installed ${PY_MODEL}
  pip install  ${PY_MODEL}
fi

Jupyter Notebook

Jupyter Notebook是基于网页的用于交互编辑环境;可应用于全过程计算:开发、文档编写、运行代码和展示结果。

Anaconda会自动安装Jupter Notebook及其他工具。若未自动安装,可手动安装conda install jupyter notebook

配置

Jupter Notebook的默认启动路径为用户目录,使用时需要修改默认起始路径

  • jupyter_notebook_config.py中设定目录;
    • 生成配置文件:在命令行中执行jupyter notebook --generate-config
    • 修改配置文件(C:\Users{user}.jupyter\jupyter_notebook_config.py):修改notebook_dir为指定目录(去掉前面的注释,并设定值)
      c.NotebookApp.notebook_dir = 'D:\programme\jupter'
  • 修改启动命令:
    • 找到Jupter Notebook的快捷方式;右键-属性
    • 修改‘目标’:去掉启动命令后的"%USERPROFILE"

或者直接修改启动命令,把启动命令后面的路径改为指定的路径。

举报

相关推荐

0 条评论