Python-环境

pip## 1. anaconda
https://www.anaconda.com/
下载官网的python慢,可以走淘宝的镜像源
https://registry.npmmirror.com/binary.html?path=python/

命令

1
2
3
4
5
6
7
8
9
10
11
12
//查看conda版本
conda -V
//查看已有的虚拟环境
conda env list
//创建虚拟环境
conda create -n env_name python=x.x
//删除虚拟环境
conda remove -n env_name --all
//激活虚拟环境
conda activate env_name
//关闭虚拟环境
conda deactivate

2. 修改conda默认的环境路径

通过conda info命令查看信息,可以看到默认的路径在C盘

1
2
3
envs directories : C:\Users\cmyang\.conda\envs
D:\soft\Anaconda3\envs
C:\Users\cmyang\AppData\Local\conda\conda\envs

打开配置文件:C:\Users\cmyang目录下的.condarc, 添加配置

1
2
envs_dirs:
- D:\soft\Anaconda3\envs

再次输入conda info

1
2
3
envs directories : D:\soft\Anaconda3\envs
C:\Users\cmyang\.conda\envs
C:\Users\cmyang\AppData\Local\conda\conda\envs

设置envs目录的权限,这一步不设置的话,创建的环境还是在C盘

3. 设置镜像地址

C:\Users\cmyang\.condarc配置文件中添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
channels:
# - defaults
envs_dirs:
- D:\soft\Anaconda3\envs
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- 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
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

如果在创建新环境时,提示如下报错,把channels: 中 - defaults这个注释掉,不走官方默认的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

- python=3.7

Current channels:

- https://conda.anaconda.org/default/win-64
- https://conda.anaconda.org/default/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

https://anaconda.org

and use the search bar at the top of the page.

4. Pycham配置Anaconda

添加python解释器

修改终端的打开方式

5. conda中设置pip镜像

pip的镜像

6. linux按照conda

安装后设置默认不启动:conda config --set auto_activate_base false

7. linux安装python3.7

  • 下载https://www.python.org/ftp/python/
  • yum -y install gcc
  • yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel xz xz-devel libffi-devel
  • mkdir -p /usr/local/python3
  • ./configure –prefix=/usr/local/python3
  • make && make install
  • ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
  • ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

8. linux安装cuda

https://developer.nvidia.com/cuda-toolkit-archive
wget https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_440.33.01_linux.run
sudo sh cuda_10.2.89_440.33.01_linux.run

import paddle
报错:libcudart.so.10.2: cannot open shared object file: No such file or directory
sudo ldconfig /usr/local/cuda-10.2/lib64

wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
sudo sh cuda_11.1.0_455.23.05_linux.run

https://developer.nvidia.cn/rdp/cudnn-archive
解压的文件复制到cuda和cuda-10.2的目录下,在安装cudnn后,再重新安装sudo sh cuda_10.2.89_440.33.01_linux.run,文件会自动同步到cuda文件夹下面

nvcc -V

1
2
3
4
5
(/home/conda_envs/nlp) [root@node02 lib64]# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

python

1
2
3
4
5
6
7
8
9
10
(/home/conda_envs/nlp) [root@node02 lib64]# python
Python 3.7.16 (default, Jan 17 2023, 22:20:44)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paddle
>>> paddle.utils.run_check()
Running verify PaddlePaddle program ...
W0310 09:47:35.855222 3697 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 11.1, Runtime API Version: 10.2
W0310 09:47:36.553472 3697 gpu_resources.cc:91] device: 0, cuDNN Version: 7.6.
PaddlePaddle works well on 1 GPU.

pip install --upgrade paddle-pipelines -i https://pypi.tuna.tsinghua.edu.cn/simple

生成 requirements.txt 文件
pip freeze > requirements.txt

加载requirements.txt文件
pip install -r requirements.txt