Win11 installs and configures Anaconda (2023.9), changes sources, and creates a virtual environment (solve terminal errors that cannot load the file WindowsPowerShell\profile.ps1)

1. Installation

1. Download

Official website

  • Click Download to download
    Insert image description here
  • Download ends

2. Installation

  Double-click the .exe to install . If the safe installation appears as shown in the picture , just click it.
Insert image description here
  Windows systems can set up multiple accounts, and each account system has different permissions. When installing the software, select "Just Me" to install it only for yourself. This means that only the account currently logged in will see the software in your own account system. When logging in with other accounts, you will not see the software. . "All Users" is installed for all users (administrator rights are required), which means that when any account logs in to the system, this software can be seen and used.
  Select "Just Me" here.
Insert image description here
  It is installed on the C drive by default. It is recommended to change to other drives. Remember the installation location. It will be used for n reinstallations in the future.
PS: Don’t think this is a vicious curse. You must know that life is incomplete without going through n reinstallations. It is
Insert image description here  recommended to select all (check the second item, Not recommended, otherwise you need to set the environment variables by yourself).
Insert image description here
  The command line is recommended here, so there is no need to check the startup item.
Insert image description here

2. Operation

3. Set environment variables

4. Start terminal operation

a.Initialization

  • Open Anaconda Powershell Prompt
    Insert image description here
  • enter
conda init

Insert image description here

b. Error: Unable to load file D:\Users\xxx\Documents\WindowsPowerShell\profile.ps1

. : 无法加载文件 D:\Users\Lenovo\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息,请
参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'D:\Users\Lenovo\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [],PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

  Don’t panic when a normal terminal becomes abnormal
Insert image description here  , Fabao:

  • terminal administrator
  • enter:
get-ExecutionPolicy
  • Output:
Restricted

Indicates that the script execution policy is restricted

  • enter:
set-ExecutionPolicy RemoteSigned

Modify the execution policy to RemoteSigned, indicating that the current user's execution policy takes precedence over the execution policy set for the local computer

  • Pay attention. Now the newly opened terminal does not report an error and the word base appears on the left side.
    Insert image description here
  • The above operations must be performed as an administrator, otherwise:
    Insert image description here

5. Source replacement operation

a. View conda configuration

conda config --show

Insert image description here

b. Add mirror source

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

Insert image description here

  • Set channel address to display when searching
conda config --set show_channel_urls yes

c.Tsinghuayuan _

Insert image description here

c. .condarc file

  The conda configuration file .condarcis an optional runtime configuration file that allows users to configure various aspects of conda. This article only introduces the channel-related parts.

  • .condarcOpen the file using Notepad
    Insert image description here
channels:
  - defaults
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
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
  • Modify .condarcfiles

Insert image description here

  • Directly set default_channels to Tsinghua source, the effect is consistent with the previous article
    • The difference is that the foreign default sources have been completely deleted. The before and after comparison is as shown in the figure.
      Insert image description here

6. Create a virtual environment

  • Create environment
conda create -n DL python==3.11

Insert image description here
Insert image description here

  • activate environment
conda activate DL

Insert image description here

Insert image description here

  • Install the deep learning PyTorch package (gpu version)
    • Note: The version matching issues involved (different gpu driver versions and python corresponding to different versions of PyTorch) are not within the scope of this article.
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
  • As shown in the figure , download defaultsfromdefaultspytorchnvidia

Insert image description here

Guess you like

Origin blog.csdn.net/m0_63834988/article/details/135429905