当前位置:网站首页>Anaconda based module installation and precautions

Anaconda based module installation and precautions

2022-06-25 07:53:00 Stephen_ Tao


Because my computer was installed with Pycharm and Python, So in the process of programming practice , If Python If the specified module is not installed , You need to go through the command line pip install Mode of installation , Or directly at Pycharm Lower installation . It seems that there is nothing , But the installed modules are basically stored in Python In the catalog site-packages Next , When more and more modules are installed ,site-packages It's going to get bigger and bigger . Because I put Python The installation to C Discoid , So one day I found myself C The plate turns red !!! Later, we investigated the cause , Know is site-packages There are too many modules .
By chance, I learned about it on the Internet Anaconda, Find out Anaconda Contains a large number of science packages , At the same time, you can create a virtual environment , It can switch different environment configurations according to task needs , Very convenient . So I put Python It's off , installed Anaconda, It has also solved the above problems . Below I will summarize the precautions during installation .

1 Anaconda Installation

Anaconda Download address
CSDN There are many detailed installation tutorials on , I feel “ The base QI Study ” This blogger wrote Anaconda install ( The process is detailed ) Very detailed , You can refer to .

1.1 matters needing attention

The following is a combination of my problems in the installation process , Make the following instructions .

  • Custom installation path : because C Disk is system disk , So I am D Disk NEW Anaconda Folder , Store the installed files in this folder
  • Configuration of environment variables : When I installed it , no choice Add Anaconda3 to my PATH environment variable, So you need to manually configure the environment variables (Anaconda install ( The process is detailed ) It also explains how to configure environment variables ). The meaning of environment variables is to indicate where the important directories of the operating system are ( stay cmd Window , If the system cannot find the specified file in the current directory , It also looks for the file in the corresponding path in the environment variable , If none of them are found , That's what makes a mistake .)

2 Anaconda Virtual environment path modification

2.1 matters needing attention

Get into Anaconda Prompt, Virtual environments can be created through conda create -n “name” python=“version”(name Is the name of the virtual environment ,version yes python Version number of ), In this way, the virtual environment will be created under the default path , The default path can be through conda info How to query , The default path is displayed in envs directories Next ( If I have multiple paths , The first one is the default path ).
Take my computer for example , The default creation path for my virtual environment is C:\Users\top.conda\envs, Therefore, the created virtual environment will be stored in this path .
But my C Disk storage space is running out , So I want to change the path of the virtual environment , The specific modification methods are as follows :

  1. stay Anaconda type conda info command , Find the configuration file (user config file) Location path
     Insert picture description here
  2. stay .condarc In file , Enter the modified virtual environment path , The specific form is as follows :
     Insert picture description here
    This path can be set according to your needs , I changed the path of the virtual environment to D:\Anaconda\VirEnviroment Next .

3 Anaconda Module installation path modification

Anaconda There are two ways to install modules :

  • pip install
  • conda install
    There are differences between the two installation methods . for instance , I am here D:\Anaconda\VirEnviroment Created a Pytorch Virtual environment for , At this time, I passed through the Anaconda Prompt Type in conda activate Pytorch Activate the environment , here Anaconda Prompt The interface is as follows :
     Insert picture description here
    It means that we have entered Pytorch Virtual environment for , The key is coming. !
    If I want to install a in this virtual environment pytorch My bag , There are two ways .
  • The first way is pip install pytorch. here pytorch The package of will be directly downloaded to... Under the current virtual environment path site-packages Next .
  • The second way is to use conda install pytorch( Maybe not this order , But it doesn't matter ). Then the system will go to the default path first ( The default path is different from the path of the virtual environment ) I'm looking for pytorch Related to the package , If any , Will pytoych Copy related packages to the current virtual environment path site-packages in . If the relevant package cannot be found in the default path , Then it will download in the default path first pytorch My bag , Then copy the package to the current virtual environment site-packages in .

3.1 matters needing attention

In my computer ,conda install The default path for is in C In the middle of the plate ( The default path is through conda info Medium package cache get ), My virtual environment is in D Plate , If I want to download a module that I didn't have before , Need to be in C Disk to create a , Then copy it to D Make an order , In view of my C Limited disk capacity , I changed the default path . The modification method is similar to that of the virtual environment :

  • stay .condarc In file , Enter the modified default installation path , The specific form is as follows :
     Insert picture description here
    I was in D The disk creates a separate pkg The file is used to store the installed package , You can choose the right path according to your needs .

4 And Pycharm The combination of

It's hard to always write code in the command line window , utilize Pycharm Integrated development environment , Can provide many conveniences . The specific steps are as follows :

  1. stay Pycharm Create a project in
  2. choice File-Settings-Python Interpreter
  3. According to the package on which the current project depends , In a specific virtual environment python.exe Add the path of , Click on the app ( The following figure shows that I created a torch_test The engineering of , rely on Pytorch This virtual environment , So I will Pytorch In this virtual environment python.exe The path is added )
    notes : there Pytorch It's just the name of a virtual environment , No Pytorch modular
     Insert picture description here
原网站

版权声明
本文为[Stephen_ Tao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250600318765.html