安装miniconda并配置python环境

1、下载Ubuntu

参考https://blog.csdn.net/weixin_45027467/article/details/106862520

下载完后修改源 进入目录 /etc/apt 找到 sources.list文件

首先备份一个防止出问题, 然后打开修改将以下内容拷贝覆盖

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
#deb cdrom:[Ubuntu 20.04 LTS _Focal Fossa_ - Release amd64 (20200423)]/ focal main restricted
 
# See http://mirrors.aliyun.com/ubuntu/ for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
# deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted
 
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
 
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ focal universe
# deb-src http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates universe
 
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
 
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
 
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://mirrors.aliyun.com/ubuntu/ focal partner
# deb-src http://mirrors.aliyun.com/ubuntu/ focal partner
 
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
 
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

2、下载miniconda

升级环境 sudo apt-get update && sudo apt-get upgrade

下载安装参考 参考https://blog.csdn.net/qq_42951560/article/details/109152114

当然不参考的话可以按照我这个来

先进入一个文件夹里
比如 cd ~
mkdir download
cd download
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.sh --no-check-certificate

bash Miniconda3-py39_4.12.0-Linux-x86_64.sh

升级conda  conda update conda

安装完成后配置 环境变量

首先使用命令   vim ~/.bashrc
然后在最后一行加上 export PATH=$PATH:/home/你的用户名/anaconda3/bin 注意格式是这样的:export PATH=$PATH:【你的安装目录】
最后保存更改运行  source ~/.bashrc  此时使用 conda info --envs 检查是否成功
   - 默认不启动任何环境  conda config --set auto_activate_base false

   - 更换源
cd ~  到home目录下
touch .condarc
vim .condarc  然后把下面内容复制进去即可

channels:
  - defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - 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
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

保存后  升级下conda   conda update conda

3、创建python环境和常用命令

   - 查看版本 conda -V
   - 查看目前已有的虚拟环境  conda env list
   - 这里的 env_name 表示你要指定的环境名  x.x是python版本号
   - 创建虚拟环境  conda create -n env_name python=x.x
   - 删除虚拟环境  conda remove -n env_name --all
   - 激活虚拟环境  conda activate env_name
   - 关闭虚拟环境  conda deactivate
   - 查看当前环境已安装的package  conda list
   - 安装某个package  conda install package
   - 删除某个package  conda remove package
   - 更新某个package  conda update package
   - 更新conda  conda update conda
注意如果没有正确退出环境,第二次打开的时候可能会导致报这个错

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init 

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

此时执行 conda init bash 即可

不闲麻烦可以执行   source activate
再执行  conda deactivate命令

4、给pip换源

可以参考如下文章https://blog.csdn.net/JineD/article/details/125090904

在下载完python后,输入  cd ~ 进入home目录
mkdir .pip
cd .pip
thouch pip.conf
vim pip.conf
输入以下内容

[global] 
index-url = https://pypi.tuna.tsinghua.edu.cn/simple 
[install] 
trusted-host = https://pypi.tuna.tsinghua.edu.cn

保存并退出
也可以使用阿里的源

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
pip install update

或者是直接在Windows系统操作,现在Windows下创建 .pip/pip.conf
注意设置文档格式 Unix,然后输入上面的其中一个源

之后打开Windows下面的Linux系统,直接找到home目录 cd ~ 将其拷贝进去
pip install update

最后使用  pip config list 来查看当前pip源

你可能感兴趣的:(ubuntu,linux,python)