1.conda常用命令
conda查看当前的所有环境:
conda info -e
# conda environments:
#
base * /root/anaconda3
linhx /root/anaconda3/envs/linhx
lxp /root/anaconda3/envs/lxp
spacy /root/anaconda3/envs/spacy
tfs /root/anaconda3/envs/tfs
在服务器上切换环境:
source activate tfs
2.conda导出
conda导出当前环境:
$ conda env export > env.yaml
$ cat env.yaml
name: tfs
channels:
- pytorch
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- blas=1.0=mkl
- ca-certificates=2019.10.16=0
- certifi=2019.9.11=py37_0
- cffi=1.13.2=py37h2e261b9_0
- cudatoolkit=9.2=0
- freetype=2.9.1=h8a8886c_1
- intel-openmp=2019.4=243
- jpeg=9b=h024ee3a_2
- libedit=3.1.20181209=hc058e9b_0
- libffi=3.2.1=hd88cf55_4
- libgcc-ng=9.1.0=hdf63c60_0
- libgfortran-ng=7.3.0=hdf63c60_0
- libpng=1.6.37=hbc83047_0
- libstdcxx-ng=9.1.0=hdf63c60_0
- libtiff=4.1.0=h2733197_0
- mkl=2019.4=243
- mkl-service=2.3.0=py37he904b0f_0
- mkl_fft=1.0.15=py37ha843d7b_0
- mkl_random=1.1.0=py37hd6b4f25_0
- ncurses=6.1=he6710b0_1
- ninja=1.9.0=py37hfd86e86_0
- numpy=1.17.4=py37hc1035e2_0
- numpy-base=1.17.4=py37hde5b4d6_0
- olefile=0.46=py_0
- openssl=1.1.1d=h7b6447c_3
- pillow=6.2.1=py37h34e0f95_0
- pip=19.3.1=py37_0
- pycparser=2.19=py_0
- python=3.7.5=h0371630_0
- readline=7.0=h7b6447c_5
- setuptools=42.0.1=py37_0
- six=1.13.0=py37_0
- sqlite=3.30.1=h7b6447c_0
- tk=8.6.8=hbc83047_0
- wheel=0.33.6=py37_0
- xz=5.2.4=h14c3975_4
- zlib=1.2.11=h7b6447c_3
- zstd=1.3.7=h0b5b093_0
- pytorch=1.3.1=py3.7_cuda9.2.148_cudnn7.6.3_0
- torchvision=0.4.2=py37_cu92
- pip:
- boto3==1.10.28
- botocore==1.13.28
- chardet==3.0.4
- click==7.0
- docutils==0.15.2
- h5py==2.10.0
- idna==2.8
- jmespath==0.9.4
- joblib==0.14.0
- keras==2.3.1
- keras-applications==1.0.8
- keras-preprocessing==1.1.0
- protobuf==3.11.0
- python-dateutil==2.8.0
- pyyaml==5.1.2
- regex==2019.11.1
- requests==2.22.0
- s3transfer==0.2.1
- sacremoses==0.0.35
- scipy==1.3.3
- sentencepiece==0.1.83
- seqeval==0.0.12
- tensorboardx==1.9
- torch==1.3.1
- tqdm==4.39.0
- urllib3==1.25.7
prefix: /root/anaconda3/envs/tfs
这样当前环境安装的包就被保存在environment.yaml中。如果想copy环境,就可以根据别人提供的.yaml文件进行环境复现:
1|conda env create -f env.yaml
或 conda env export > environment.yaml
或 conda list -e > requirements.txt
但是只是移植了conda install直接安装的包,pip安装的包还需要 pip install -r requirements.txt
重新安装。
环境会被保存在 environment.yaml文件中。 当我们想再次创建该环境,或根据别人提供的**.yaml**文件复现环境时,可以:
1|conda env create -f environment.yaml
或 conda install --yes --file requirements.txt
3.pip导出
pip导出项目用到的包:
先安装pipreqs
1|pip install pipreqs
进入到项目目录下,导出包
pip导出安装的库到 requirements.txt
1|pip freeze > requirements.txt
pip导入requirements.txt中列出的库到系统
1|pip install -r requirements.txt