Python basic environment construction (pip, anaconda)

1.pip

Configuration file path:
centos: ~/.pip/pip.conf
windows: C:\Users\admin\AppData\Roaming\pip\pip.ini
file content:

[global]
index-url = http://IP/repository/pypi-tsinghua/simple
trusted-host=IP

Today, when pip install sqlalchemy introduces the package in centos7.9 and python3.6 environments, the error is roughly as follows:

Command “/usr/local/python36/bin/python3.6 -u -c “import setuptools,
tokenize;file=‘/tmp/pip-build-gvrqj4jw/greenlet/setup.py’;f=getattr(tokenize,
‘open’, open)(file);code=f.read().replace(‘\r\n’,
‘\n’);f.close();exec(compile(code, file, ‘exec’))” install
–record /tmp/pip-h306ktbw-record/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-build-gvrqj4jw/greenlet/

Error keyword: setuptools
solution:

pip install --upgrade setuptools
pip install --upgrade pip setuptools wheel

Finally, let’s talk about the ultimate killer feature of pip for importing packages. Offline package importing. The python version corresponds to the .whl file. The download address is: https://pypi.org/. Pay attention to the operating system (win or centos) and the number of system bits (amd64). ), execute pip install D:\XXXXX-cp38-win_amd64.whl .

2.anaconda

Configuration file path:
centos: ~/.condarc
windows: C:\Users\admin.condarc
file content:

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

Anaconda can create and use multiple versions of python at will, which is very convenient. The commands are mainly divided into the following two parts.

1.Virtual environment management

# 查看现有的环境
$ conda info --env

# 创建环境,后面的python=3.6是指定python的版本
$ conda create --name env_name python=3.6
conda create --name python3.6 python=3.6
conda create --name python38 python=3.8
# 创建包含某些包的环境(也可以加上版本信息)
$ conda create --name env_name python=3.7 numpy scrapy
 
# 激活某个环境
$ activate env_name
 
# 关闭某个环境
$ conda deactivate

激活conda环境 conda activate

关闭conda环境 conda deactivate

打开终端自动进入conda环境: conda config --set auto_activate_base true

关闭打开终端自动进入conda环境: conda config --set auto_activate_base false

 
# 复制某个环境
$ conda create --name new_env_name --clone old_env_name
 
# 删除某个环境
$ conda remove --name env_name --all
 
# 生成需要分享环境的yml文件(需要在虚拟环境中执行)
$ conda env export > environment.yml
 
# 别人在自己本地使用yml文件创建虚拟环境
$ conda env create -f environment.yml

2.Package management

# 列出所有环境
$ conda env list

# 列出当前环境下所有安装的 conda 包。
$ conda list
 
# 列举一个指定环境下的所有包
$ conda list -n env_name
 
# 查询库
$ conda search scrapys
 
# 安装库安装时可以指定版本例如:(scrapy=1.5.0)
$ conda install scrapy
 
# 为指定环境安装某个包
$ conda install --name target_env_name package_name
 
# 更新安装的库
$ conda update scrapy
 
# 更新指定环境某个包
$ conda update -n target_env_name package_name
 
# 更新所有包
$ conda update --all
 
# 删除已经安装的库也尅用(conda uninstall)
$ conda remove scrapy
 
# 删除指定环境某个包
$ conda remove -n target_env_name package_name
 
# 删除没有用的包
$ conda clean -p

Guess you like

Origin blog.csdn.net/keepandkeep/article/details/132259868