Ubuntu 配置Python环境(包括Tensorflow)

目录

1,安装miniconda

2,安装Spyder 

3,为什么要创建conda的虚拟环境

创建python任意版本虚拟环境:

4,pip 和 conda 包管理器

5,升级更新python版本

6,利用conda查找可安装的包版本

7,TensorFlow 安装与环境配置


1,安装miniconda

https://gist.github.com/arose13/fcc1d2d5ad67503ba9842ea64f6bac35

How to Install miniconda on linux (from the command line only)

# Setup Ubuntu
sudo apt update --yes
sudo apt upgrade --yes

# Get Miniconda and make it the main Python interpreter
#-O:下载并以指定的文件名保存
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh 
bash ~/miniconda.sh -b -u -p ~/miniconda
rm ~/miniconda.sh

export PATH=~/miniconda/bin:$PATH

#
#The miniconda.sh script comes with a few basic options. 
#Most notably we used -b to be able to run unattended, which means that all of the agreements are automatically accepted without user prompt.
# -u updates any existing installation in the directory of install if there is one.
# -p is the directory to install into and defaults to /root/miniconda3 .

usage: /root/miniconda3/miniconda.sh [options]

Installs Miniconda3 4.6.14

-b           run install in batch mode (without manual intervention),
             it is expected the license terms are agreed upon
-f           no error if install prefix already exists
-h           print this help message and exit
-p PREFIX    install prefix, defaults to /root/miniconda3, must not contain spaces.
-s           skip running pre/post-link/install scripts
-u           update an existing installation
-t           run package tests after installation (may install conda-build)

或者: 从官方网站Miniconda — Conda documentation下载相应的 Miniconda sh 文件,然后使用 sh  -b 从命令行执行安装

cd Downloads/
sh Miniconda3-py39_4.10.3-Linux-x86_64 -b  
#-b          run install in batch mode (without manual intervention),
#             it is expected the license terms are agreed upon
export PATH=/home/kevalen/miniconda3/bin:$PATH
################################################
For best results, please verify that your PYTHONPATH only points to
    directories of packages that are compatible with the Python interpreter
    in Miniconda3: /home/kevalen/miniconda3

检查是否安装成功:

输入$ conda,如果报错conda: command not found

原因是因为~/.bashrc文件没有配置好

vim ~/.bashrc
在.bashrc最后一行加上 export PATH=/home/kevalen/miniconda3/bin:$PATH
或者 export PATH=/home/lei/miniconda/bin:$PATH
然后保存更改,运行
source ~/.bashrc

打开终端报错:bash: /某路径/bashrc: No such file or directory

造成这样的原因,一般是 bashrc 文件里的环境变量配置出了问题。只要删除对应“某路径”的source那一行即可解决,比如

bash: workspace_dir: No such file or directory

删除 source workspace_dir/devel/setup.bash这一行就可以啦

查看conda环境:

conda info --env
conda env list

2,安装Spyder 

Installation Guide — Spyder 5 documentation

ubuntu 20 安装 spyder3_ycs_0405的专栏-CSDN博客

1、先安装cython:   

python -m pip install cython
2、安装spyder3  

sudo apt install spyder3
或者用下面的命令安装:

sudo apt install spyder
3、启动spyder3  

    终端输入:

spyder
或

spyder3

########################################
如果安装了miniconda,则可以直接通过 conda包管理器 安装:
conda install spyder

移除一个包
例如:移除 spyder

conda remove spyder

更新一个包
例如:更新 spyder

conda update spyder

查看安装是否成功:
$ spyder

####################################也可以使用 Python 包管理器 pip 安装
pip install spyder

#更新
pip install --upgrade spyder

#pip卸载包
命令:pip uninstall packagename

#pip查看已安装的包
#功能:查看指定的安装包信息
命令:pip show packagename

#功能:列出所有的安装包
命令:pip list 


卸载Spyder:

https://www.thelinuxfaq.com/ubuntu/ubuntu-17-04-zesty-zapus/spyder?type=uninstall

#Only uninstall or removes an installed spyder package itself
sudo apt-get remove spyder 
#Uninstall spyder including dependent package
sudo apt-get remove --auto-remove spyder 
#If you use purge options along with auto remove, will be removed everything
#regarding the package, It's really useful when you want to reinstall again.
sudo apt-get purge --auto-remove spyder

解决Spyder不能使用plot_model 

你可能感兴趣的:(机器学习入门,ubuntu,python,linux,1024程序员节)