常用的一些小指令(备忘)

一、Anaconda

1.1创建环境基本操作

// 查看现有环境
conda info --env
// 创建环境
conda create --name env_name python=3.6  //python版本需要在此指定
// 进入环境
conda activate env_name 
// 删除环境
conda env remove -n env_name
// 退出环境
conda deactivate
// 安装包
conda install xxxx
pip install xxxx
// 查看某个环境内的包
conda list //需要先进入此环境

1.2 添加源

// 清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

conda config --set show_channel_urls yes
// 中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

conda config --set show_channel_urls yes

二、linux实用命令

2.1 requirements.txt

在查看别人的Python项目时,经常会看到一个requirements.txt文件,里面记录了当前程序的所有依赖包及其精确版本号。这个文件有点类似与Rails的Gemfile。其作用是用来在另一台PC上重新构建项目所需要的运行环境依赖。

// 生成requirements.txt文件(二选其一)
pip freeze > requirements.txt
conda list -e > requirements.txt
// 安装requirements.txt文件(二选其一)
pip install -r requirements.txt 
conda install --yes --file requirements.txt

三、os

3.1 os获取文件路径

// coding:utf-8
import os


// ***获取当前目录***
print(os.getcwd())
print(os.path.abspath(os.path.dirname(__file__)))

// ***获取上级目录***
print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
print(os.path.abspath(os.path.dirname(os.getcwd())))
print(os.path.abspath(os.path.join(os.getcwd(), "..")))

// ***获取上上级目录***
print(os.path.abspath(os.path.join(os.getcwd(), "../..")))

3.1 os创建文件路径

// coding:utf-8
import os

// 判断一个目录是否存在 
os.path.exists(path) 
// 多层创建目录 
os.makedirs(path) 
// 创建目录
os.mkdir(path) 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值