Python quick start experience

1. Environmental information

1.1 Hardware information

  1. Model : MacBook Pro
  2. Memory : 16GB
  3. Hard disk : 512GB SSD
  4. Processor : Apple M2
  5. Host CPU architecture : ARM

1.2 Software information

  1. Python version : 3.7
  2. Conda version : Miniconda3 macOS Apple M1 64-bit bash / Anaconda3-2023.07-2-MacOSX-arm64.pkg

Two, Conda installation

2.1 Introduction to Conda

2.1.1 Introduction to Conda

Conda was created for Python programs and is available on Linux, OS X, and Windows. It can also package and distribute other software and is the most popular Python environment management tool today.
Because there are many versions of Python , and its libraries are also very extensive, and there are many dependencies between libraries, so it is very troublesome to install and manage versions of libraries. Therefore, Conda is designed as a management version and Python environment. tool, but it can package and manage software in any language.

2.1.2 The relationship between Conda, Anaconda and Miniconda

  • Conda: Conda is Anaconda's package manager , mainly used to install and manage software packages.
  • Anaconda: Anaconda refers to an open source Python distribution that includes more than 180 scientific packages such as conda and Python and their dependencies.
  • Miniconda: Miniconda only includes Conda and Python. It is a simplified version of Anaconda . Miniconda is also a software distribution.
    insert image description here

2.2 Conda installation package download

Select the corresponding package to download according to the computer model and CPU architecture.

2.2.1 Miniconda Download

Because Immortal Yi uses a Mac M2, download the Miniconda3 macOS Apple M1 ARM 64-bit bash version from the Miniconda official website, and execute it directly with sh; download address: Miniconda download .
insert image description here

2.2.2 Anconda download

Because Immortal Yizhen uses a Mac M2, download the Anaconda3-2023.07-2-MacOSX-arm64.pkg version from Anconda Tsinghua source, and install it directly out of the box; download address (using Tsinghua source): Anconda download .
insert image description here

2.3 Conda installation

Subsequent experience instructions are based on Anconda.

2.3.1 Miniconda installation

# 文件名是自己下载的sh文件,-p后面填安装路径
# -b 表示将环境变量自动写入到~/.bash文件中
sh Miniconda3-py311_23.5.2-0-MacOSX-arm64.sh -b -p ~./miniconda3

# 将conda路径写入shell配置
source ~./miniconda3/bin/activate

insert image description here

2.3.2 Anconda installation

# 安装完成后执行如下命令切换conda的base环境
source ~/.zshrc

insert image description here

2.4 Conda initialization

# 关闭anconda的debug日志
conda config --set debug false

# conda源配置
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

# 查看源
cat .condarc

# 至此conda初始化完成,可以通过conda -h查看conda command说明

insert image description here

3. Python installation

3.1 Create a PY virtual environment

After building, you can use conda env list to view the newly created virtual environment

# 模版
conda create -n 虚拟环境名 python=对应的python版本

# 实际创建
conda create -n py37 python=3.7

3.2 Activate the PY virtual environment

# 查看已经存在的虚拟环境
conda env list

# 激活即切换至对应的py环境
conda activate py37

# 退出当前py虚拟环境
conda deactivate

# 查看当前py环境已有的py包
conda list

insert image description here

3.3 Example of installing PY package

# 例如查看opencv-python可装的版本
conda search tensorflow

# 在当前py环境下安装opencv-python包
# -i: 指定镜像加速源https://pypi.tuna.tsinghua.edu.cn/simple 
pip install tensorflow==2.2.0 -i https://pypi.tuna.tsinghua.edu.cn/simple 

# 常用命令如下
# 安装:pip install [package]
# 删除:pip uninstall [package]
# 列出已安装的包:pip list
# 查看包的详细信息: pip show <package-name>

insert image description here

4. Construction of development environment

4.1 Install development tools

Because it needs to be compatible with Java, Immortal Yi directly uses IDEA, and friends can also use VSCode or PyCharm.

insert image description here

4.2 Associate Conda environment

1. Create a new project and add Python language
insert image description here2. Click Install
insert image description here
3. Restart INDE and associate Conda
insert image description here

5. Hello Word

5.1 Create a new HelloWord

insert image description here
insert image description here

5.2 Output HelloWord

insert image description here

6. Frequently asked questions

6.1 Unable to install PyQt5

The error is shown in the figure below, and the exception log: Preparing metadata (pyproject.toml) … error

The exception is due to the python version. pyqt5 is only applicable to versions below python3.8, so pyqt5 cannot be installed through python3.8 at the beginning, but can be installed through python3.7 .
insert image description here

6.2 Unable to install PY3.7

The error is shown in the figure below, and the exception log: PackagesNotFoundError: The following packages are not available from current channels: - python=3.7

insert image description here

This exception is due to the fact that the current channel only supports python3.8 at a minimum, which needs to be installed as follows:

# 查看当前支持的python版本
conda search --full --name python

# 通过其它方式安装python3.7
## 创建一个空的环境
conda create -n py37
## 启动该环境
conda activate py37
## 使用x86_64 architecture channel(s)
conda config --env --set subdir osx-64
## 安装python3.7之类的操作
conda install python=3.7

insert image description here

So far, the Python quick start experience is completed, and the chapters related to artificial intelligence will be output in succession~ If you encounter any problems during the review process, please leave a message or private message for communication.

Guess you like

Origin blog.csdn.net/ith321/article/details/132432301