1 安装anaconda

下载,清华源下载linux版的

Anaconda3-2020.07-Linux-x86_64.sh

进入下载目录,运行下面的命令,因为要安装到/usr/local下,所以需要使用sudo,不然无法在/usr/local下创建目录

sudo bash Anaconda3-2020.07-Linux-x86_64.sh

然后就是许可协议,一路enter下去

许可协议读完后提示

Do you accept the license terms? [yes|no]
输入yes

然后会有提示

Anaconda3 will now be installed into this location:
/home/yu

    Press ENTER to confirm the location
    Press CTRL-C to abort the installation
    Or specify a different location below
如果要安装在anaconda默认的路径下,按回车就可以了
如果要自定义路径,就输入自定义的路径 /usr/local/anaconda3

然后会有提示

Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Anaconda3
by running conda init? [yes|no]
[no] >>>

输入yes

然后还会有提示

conda init

If you'd prefer that conda's base environment not be activated on startup,
set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Anaconda3!

===========================================================================

Anaconda and JetBrains are working together to bring you Anaconda-powered
environments tightly integrated in the PyCharm IDE.

PyCharm for Anaconda is available at:
https://www.anaconda.com/pycharm

到这里就安装完了,

关闭终端,重新打开终端

(base) yu@yulinux:~$

前面会有base,这是anaconda的虚拟环境

激活虚拟环境 conda activate
关闭虚拟环境 conda deactivate

通过将auto_activate_base参数设置为false实现:

conda config --set auto_activate_base false 默认关闭虚拟环境

conda config --set auto_activate_base true 默认开启虚拟环境

这样默认就不激活虚拟环境了,需要的时候使用命令(conda activate)手动激活

添加环境变量

1、在终端输入$sudo gedit /etc/profile,打开profile文件。

2、在文件末尾添加一行:export PATH=/usr/local/anaconda3/bin:$PATH,其中,“/usr/local/anaconda3/bin”是实际的安装路径,保存

3 source /etc/profile 保存执行

...
...
if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
export PATH=/usr/local/anaconda3/bin:$PATH

重启机器输入python

yu@yulinux:~$ python
Python 3.8.3 (default, Jul  2 2020, 16:21:59) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.

卸载

卸载分两步

一是删除安装目录 sudo rm -rf 安装目录

二是删除环境变量 gedit ~/.bashrc  把anaconda相关的信息删除, sudo gedit etc/profile 把它的环境变量信息删除

说明:

bashrc 的rc是run command 这是用户的配置环境变量的文件

/etc/profile 是系统的环境变量配置文件

 

Anaconda提供了包管理和虚拟环境管理,

包管理

这个好理解,安装和卸载包

虚拟环境管理

为什么需要虚拟环境?

默认情况下第三方包要放在同一目录下,在一台电脑上, 开发多个的项目, 用到不同的python版本或者某个包的不同版本, 在同一个目录下安装或者更新, 新版本会覆盖以前的版本,以前的项目不能正常运行。

而用虚拟环境搭建独立的python运行环境, 使得单个项目的运行环境与其它项目之间没影响.

anaconda可以设置多个虚拟环境,比如(举例说明,版本号可能不存在)

虚拟环境A需要的python版本是2.7,numpy版本是5.4,scipy版本是3.3,项目1要在这个环境下运行

虚拟环境B需要的是python3.3,numpy版本5.4,request版本是2.1,项目2要在这个环境下运行

环境3需要python3.8,numpy5.6,项目3要在这种环境下运行

 

创建虚拟环境

conda create -n 虚拟环境名 python=版本

结果

yu@yulinux:~$ conda create -n en1 python=2.7 scipy
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/yu/anaconda3/envs/en1

  added / updated specs:
    - python=2.7
    - scipy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    blas-1.0                   |              mkl           6 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    certifi-2016.2.28          |           py27_0         211 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    libgfortran-3.0.0          |                1         281 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    mkl-2017.0.3               |                0       129.5 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    numpy-1.13.1               |           py27_0         6.8 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    pip-9.0.1                  |           py27_1         1.6 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    python-2.7.13              |                0        11.5 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    scipy-0.19.1               |      np113py27_0        35.2 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    setuptools-36.4.0          |           py27_1         557 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    wheel-0.29.0               |           py27_0          81 KB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
    ------------------------------------------------------------
                                           Total:       185.8 MB

The following NEW packages will be INSTALLED:

  blas               anaconda/pkgs/free/linux-64::blas-1.0-mkl
  certifi            anaconda/pkgs/free/linux-64::certifi-2016.2.28-py27_0
  libgfortran        anaconda/pkgs/free/linux-64::libgfortran-3.0.0-1
  mkl                anaconda/pkgs/free/linux-64::mkl-2017.0.3-0
  numpy              anaconda/pkgs/free/linux-64::numpy-1.13.1-py27_0
  openssl            anaconda/pkgs/free/linux-64::openssl-1.0.2l-0
  pip                anaconda/pkgs/free/linux-64::pip-9.0.1-py27_1
  python             anaconda/pkgs/free/linux-64::python-2.7.13-0
  readline           anaconda/pkgs/free/linux-64::readline-6.2-2
  scipy              anaconda/pkgs/free/linux-64::scipy-0.19.1-np113py27_0
  setuptools         anaconda/pkgs/free/linux-64::setuptools-36.4.0-py27_1
  sqlite             anaconda/pkgs/free/linux-64::sqlite-3.13.0-0
  tk                 anaconda/pkgs/free/linux-64::tk-8.5.18-0
  wheel              anaconda/pkgs/free/linux-64::wheel-0.29.0-py27_0
  zlib               anaconda/pkgs/free/linux-64::zlib-1.2.11-0


Proceed ([y]/n)? 


Downloading and Extracting Packages
blas-1.0             | 6 KB      | ##################################### | 100% 
mkl-2017.0.3         | 129.5 MB  | ##################################### | 100% 
setuptools-36.4.0    | 557 KB    | ##################################### | 100% 
certifi-2016.2.28    | 211 KB    | ##################################### | 100% 
libgfortran-3.0.0    | 281 KB    | ##################################### | 100% 
wheel-0.29.0         | 81 KB     | ##################################### | 100% 
python-2.7.13        | 11.5 MB   | ##################################### | 100% 
scipy-0.19.1         | 35.2 MB   | ##################################### | 100% 
numpy-1.13.1         | 6.8 MB    | ##################################### | 100% 
pip-9.0.1            | 1.6 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: \ WARNING conda.core.path_actions:verify(962): Unable to create environments file. Path not writable.
  environment location: /home/yu/.conda/environments.txt

done
Executing transaction: | WARNING conda.core.envs_manager:register_env(50): Unable to register environment. Path not writable or missing.
  environment location: /home/yu/anaconda3/envs/en1
  registry file: /home/yu/.conda/environments.txt
done
#
# To activate this environment, use
#
#     $ conda activate en1
#
# To deactivate an active environment, use
#
#     $ conda deactivate

激活虚拟环境
 

conda activate 虚拟环境名
结果
yu@yulinux:~$ conda activate en1
(en1) yu@yulinux:~$

安装该环境需要的包

设置虚拟环境后,指定该环境需要的包,如果这个包已经存在于anaconda自带的包中,或者其他环境中,就不需要下载了,直接拉取过来,这样就方便很多了,anaconda只会把不存在于所有虚拟环境和自己包目录下的包下载下来。

conda install -n 环境名 包名

conda install -n en1 request

退出虚拟环境

conda deactivate

(en1) yu@yulinux:~$ conda deactivate
yu@yulinux:~$

查看所有的虚拟环境

conda info --envs

yu@yulinux:~$ conda info --envs
# conda environments:
#
base                  *  /home/yu/anaconda3
en1                      /home/yu/anaconda3/envs/en1

注: 虚拟环境对应的目录是在安装目录的envs目录下

删除虚拟环境中某个包

conda remove --name 虚拟环境名 包名  (会把该包及其依赖包删除掉)

yu@yulinux:~$ conda remove --name en1 scipy
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/yu/anaconda3/envs/en1

  removed specs:
    - scipy


The following packages will be REMOVED:

  blas-1.0-mkl
  libgfortran-3.0.0-1
  mkl-2017.0.3-0
  numpy-1.13.1-py27_0
  scipy-0.19.1-np113py27_0


Proceed ([y]/n)? 

Preparing transaction: done
Verifying transaction: | WARNING conda.core.path_actions:verify(962): Unable to create environments file. Path not writable.
  environment location: /home/yu/.conda/environments.txt

done
Executing transaction: - WARNING conda.core.envs_manager:register_env(50): Unable to register environment. Path not writable or missing.
  environment location: /home/yu/anaconda3/envs/en1
  registry file: /home/yu/.conda/environments.txt
done

删除虚拟环境

conda remove -n 虚拟环境名 --all   (把该环境及其下所有的东西删除)

yu@yulinux:~$ conda remove -n en1 --all

Remove all packages in environment /home/yu/anaconda3/envs/en1:


## Package Plan ##

  environment location: /home/yu/anaconda3/envs/en1


The following packages will be REMOVED:

  certifi-2016.2.28-py27_0
  openssl-1.0.2l-0
  pip-9.0.1-py27_1
  python-2.7.13-0
  readline-6.2-2
  setuptools-36.4.0-py27_1
  sqlite-3.13.0-0
  tk-8.5.18-0
  wheel-0.29.0-py27_0
  zlib-1.2.11-0


Proceed ([y]/n)? 

Preparing transaction: done
Verifying transaction: / WARNING conda.core.path_actions:verify(962): Unable to create environments file. Path not writable.
  environment location: /home/yu/.conda/environments.txt

done
Executing transaction: \ WARNING conda.core.envs_manager:register_env(50): Unable to register environment. Path not writable or missing.
  environment location: /home/yu/anaconda3/envs/en1
  registry file: /home/yu/.conda/environments.txt
done

 

 

2 java

oracle官网下载压缩包

解压到 usr/local/java 其中java文件夹需要自己创建

设置环境变量 配置到/etc/profile中

sudo gedit /etc/profile

在这个文件中添加

#set Java environment
export JAVA_HOME=/usr/local/java/jdk1.8.0_271
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

需要注意的是 JAVA_HOME对应的目录应该是jdk解压后的目录

刷新

source /etc/profile

测试

java -version
yu@yulinux:~$ java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)

 

pycharm (linux下安装pycharm不需要先安装java环境)

下载社区版,官网下载即可

pycharm-community-2020.2.3.tar.gz

进入目录解压缩

tar zxf pychrm-community-2020.2.3.tar.gz       ##解压

进入到解压后的目录下的bin文件夹下(解压的目录随意)

运行.sh文件即可

cd /usr/local/pycharm/pycharm-community/bin # 这里把pycharm-community-2020.2.3文件夹重命名了,。。。

pycharm.sh

安装完成后默认不带桌面图标,需要手动生成

sudo gedit /usr/share/applications/Pycharm.desktop

编辑文件,添加内容

[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm3
Comment=Pycharm3:The Python IDE
Exec=sh /usr/local/pycharm/pycharm-community/bin/pycharm.sh
Icon=/usr/local/pycharm/pycharm-community/bin/pycharm.png
Terminal=pycharm
Categories=Pycharm;

然后去搜索里找Pycharm,固定到任务栏即可。

安装专业版的步骤是一样的,激活的时候先进入应用代码界面,再把jar包拖进窗口,会自动安装插件,然后重启应用就可以了。