概述
Python学习笔记之(一)——环境建设
更新日期:2018年2月7日
python已经成为了非常流行而且高适用的一款软件,在数值处理和模式识别机器学习等领域越来越被广泛使用。万变不离其宗,无论何时官网总能给我们最权威最详尽的解答。
python官网
python文档
所需的python2.7、3.6甚至最新的3.7都可以从上面下载。
1. python软件环境
先解决这两个疑问:选哪个环境?为什么选这个环境?
使用Anaconda,里面预装了conda、python和众多package,科学计算工具等等,是python的一种发行版,解决多版本python共存和第三方包的安装问题。
从百度里面查询:
“
anaconda 是一个python的发行版,包括了python和很多常见的软件库, 和一个包管理器conda。常见的科学计算类的库都包含在里面了,使得安装比常规python安装要容易。
装了anaconda就不需要装python了。
”
Anaconda 解决了官方 Python 的两大痛点。
第一:提供了包管理功能,Windows 平台安装第三方包经常失败的场景得以解决,
第二:提供环境管理的功能,功能类似 Virtualenv,解决了多版本Python并存、切换的问题。 熟悉使用 Anaconda 只需花10分钟就能掌握。
1.1 初学python者自学anaconda的正确姿势是什么??
1.1.1 下载anaconda
anaconda官网下载地址:
直达Anaconda3.5-64 下载链接
直达Anaconda3.5-32 下载链接
直接在官网下载安装包,选择Python3.6+的安装包进行下载,下载完成后直接安装,安装过程选择默认配置即可,大约需要1.8G的磁盘空间,下载得到文件:Anaconda3-5.0.1-Linux-x86_64.sh。
如果在windows环境下,则可以下载windows版本,Anaconda3-2020.02-Windows-x86_64.exe,然后安装就可以了。
1.1.2 安装
安装参考链接
运行:
chmod +x Anaconda3-2020.02-Linux-x86_64.sh
./Anaconda3-2020.02-Linux-x86_64.sh
会提示安装路径,选择默认就行了(在ubuntu/lucky/anaconda3下).
1.1.3 修改镜像地址
安装完成之后运行
source ~/.bashrc 然后再运行下面的语句,否则很可能会显示“conda:未找到命令”。
接下来修改安装镜像地址,否则如果直接进行create环境创建的话,会从国际地址下载相关的软件,非常慢。
1.1.4 配置Anaconda环境
Anaconda安装完成之后,如果你不激活环境,那么虽然之前安装的Anaconda里面包罗万象,但是你就算是想用python都得重新安装,会跳出提示:
lucky@lucky-ubuntu-Pc:~/.pip$ python
Command ‘python’ not found, but can be installed with:
sudo apt install python3 # version 3.7.5-1, or sudo apt
install python # version 2.7.17-1 sudo apt install
python-minimal # version 2.7.17-1You also have python3 installed, you can run ‘python3’ instead.
如果再"sudo apt install python3 "装一个python真是有点亏。那么如果想用conda的软件包,那么首先就要激活conda环境。激活很简单:
conda activate
然后再调用python就会显示:
lucky@lucky-ubuntu-Pc:~/.pip$ conda activate
(base) lucky@lucky-ubuntu-Pc:~/.pip$ python
Python 3.7.6 (default, Jan 8 2020, 19:59:22)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type “help”, “copyright”, “credits” or “license” for more information.
说明环境已经ok了。那么到底这conda里面有啥东西?输入conda看一看:
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda
usage: conda [-h] [-V] command ...
conda is a tool for managing and deploying applications, environments and packages.
Options:
positional arguments:
command
clean Remove unused packages and caches.
config Modify configuration values in .condarc. This is modeled
after the git config command. Writes to the user .condarc
file (/home/lucky/.condarc) by default.
create Create a new conda environment from a list of specified
packages.
help Displays a list of available conda commands and their help
strings.
info Display information about current conda install.
init Initialize conda for shell interaction. [Experimental]
install Installs a list of packages into a specified conda
environment.
list List linked packages in a conda environment.
package Low-level conda package utility. (EXPERIMENTAL)
remove Remove a list of packages from a specified conda environment.
uninstall Alias for conda remove.
run Run an executable in a conda environment. [Experimental]
search Search for packages and display associated information. The
input is a MatchSpec, a query language for conda packages.
See examples below.
update Updates conda packages to the latest compatible version.
upgrade Alias for conda update.
optional arguments:
-h, --help Show this help message and exit.
-V, --version Show the conda version number and exit.
conda commands available from other packages:
build
convert
debug
develop
env
index
inspect
metapackage
render
server
skeleton
verify
可以看到,里面内容很多,其中config部分大家看着很熟悉吧?不熟悉就看下面:
下载更新环境设置
Anaconda 的镜像地址默认在国外,用 conda 安装包的时候会很慢,目前可用的国内镜像源地址有清华大学的。
修改 ~/.condarc (Linux/Mac) 或 C:Users当前用户名.condarc (Windows) 配置:
如果没有这个文件,那就新建文件,然后进行编辑,将下面的内容拷贝进去
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
show_channel_urls: true
也可以直接用命令来添加:
参考:Windows下Anaconda安装、换源与更新
windows下打开anaconda prompt ,linux下打开终端,在当前用户目录下输入:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
conda额外库:
# pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# 安装时PyTorch,官网给的安装命令需要去掉最后的-c pytorch,才能使用清华源
# conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
# menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes
额外库都是第三方提供的,非anaconda官方的,建议没有特殊需要直接使用稳定的官方库。
中科大anaconda镜像:
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
国内源也是会挂的,之前清华就挂过,后来又活了,腾讯挂了就直接死了,一旦出现一直连接失败问题就可以换回来了
2021年1月5日更新开始
在windows下用上述源更新(conda update anaconda)出错,于是换了如下源文件:
channels:
- conda-forge
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
show_channel_urls: true
再更新就好了,过程如下图:
2021年1月5日更新结束
conda config --remove-key channels
如果使用conda安装包的时候还是很慢,那么可以考虑使用pip来安装,同样把 pip 的镜像源地址也改成国内的,豆瓣源速度比较快。修改 ~/.pip/pip.conf (Linux/Mac) 或 C:Users当前用户名pippip.conf(Windows) 配置:
[global]
trusted
-host = pypi.douban.com index
-url = http://pypi.douban.com/simple
好啦,下载快了更新快了事倍功半嘛!
更新anaconda
# conda
conda update conda
# anaconda(升级anaconda前需要先升级conda)
conda update anaconda
# anaconda-navigator
conda update anaconda-navigator
# spyder
conda update spyder
# 所有包
conda update --all
# 尽量避免使用conda update --all命令,可能会出现部分包降级的问题
继续说conda。
我的理解conda就是一个“虚拟机”,类似“Virtualenv”,你可以建立一个独立的软件环境,在此环境里面你可以安装、卸载、更新升级需要的软件支撑包,当这个环境用完之后你可以把他给去激活,这个自定义的环境不会影响其他的定义环境。conda相当于给列了一个库(list),你建立的环境想要什么包,可以从里面去选择,可以为这个环境命名。如下,就是新建了一个名称为“mypython36”的环境,这个环境调用了conda当中的python包,这个python的版本是3.6的
conda create -n mypython36 python=3.6
如果不知道python的版本,我觉得干脆别用这个版本号,直接:
conda create -n mypython36 python
不过这样也会有麻烦,比如有的代码需要python2有的需要3,那么具体问题具体分析吧,反正你知道这里可以选择你要的包,至于这个包是python2还是3,根据情况决定。
当然你也有权去了解这个conda里面有啥包,上面对conda的解释中说了,就是用list来查看:
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda list
# packages in environment at /home/lucky/anaconda3:
#
# Name Version Build Channel_ipyw_jlab_nb_ext_conf 0.1.0 py37_0 defaults
_libgcc_mutex 0.1 main defaults
alabaster 0.7.12 py37_0 defaults
anaconda 2020.02 py37_0 defaults
anaconda-client 1.7.2 py37_0 defaults
anaconda-navigator 1.9.12 py37_0 defaults
anaconda-project 0.8.4 py_0 defaults
argh 0.26.2 py37_0 defaults
asn1crypto 1.3.0 py37_0 defaults
astroid 2.3.3 py37_0 defaults
astropy 4.0 py37h7b6447c_0 defaults
atomicwrites 1.3.0 py37_1 defaults
attrs 19.3.0 py_0 defaults
autopep8 1.4.4 py_0 defaults
babel 2.8.0 py_0 defaults
backcall 0.1.0 py37_0 defaults
backports 1.0 py_2 defaults
backports.functools_lru_cache 1.6.1 py_0 defaults
backports.shutil_get_terminal_size 1.0.0 py37_2 defaults
backports.tempfile 1.0 py_1 defaults
backports.weakref 1.0.post1 py_1 defaults
beautifulsoup4 4.8.2 py37_0 defaults
bitarray 1.2.1 py37h7b6447c_0 defaults
bkcharts 0.2 py37_0 defaults
blas 1.0 mkl defaults
bleach 3.1.0 py37_0 defaults
blosc 1.16.3 hd408876_0 defaults
bokeh 1.4.0 py37_0 defaults
boto 2.49.0 py37_0 defaults
bottleneck 1.3.2 py37heb32a55_0 defaults
bzip2 1.0.8 h7b6447c_0 defaults
ca-certificates 2020.1.1 0 defaults
cairo 1.14.12 h8948797_3 defaults
certifi 2019.11.28 py37_0 defaults
cffi 1.14.0 py37h2e261b9_0 defaults
chardet 3.0.4 py37_1003 defaults
click 7.0 py37_0 defaults
cloudpickle 1.3.0 py_0 defaults
clyent 1.2.2 py37_1 defaults
colorama 0.4.3 py_0 defaults
conda 4.8.2 py37_0 defaults
conda-build 3.18.11 py37_0 defaults
conda-env 2.6.0 1 defaults
conda-package-handling 1.6.0 py37h7b6447c_0 defaults
conda-verify 3.4.2 py_1 defaults
contextlib2 0.6.0.post1 py_0 defaults
cryptography 2.8 py37h1ba5d50_0 defaults
curl 7.68.0 hbc83047_0 defaults
cycler 0.10.0 py37_0 defaults
cython 0.29.15 py37he6710b0_0 defaults
cytoolz 0.10.1 py37h7b6447c_0 defaults
dask 2.11.0 py_0 defaults
dask-core 2.11.0 py_0 defaults
dbus 1.13.12 h746ee38_0 defaults
decorator 4.4.1 py_0 defaults
defusedxml 0.6.0 py_0 defaults
diff-match-patch 20181111 py_0 defaults
distributed 2.11.0 py37_0 defaults
docutils 0.16 py37_0 defaults
entrypoints 0.3 py37_0 defaults
et_xmlfile 1.0.1 py37_0 defaults
expat 2.2.6 he6710b0_0 defaults
fastcache 1.1.0 py37h7b6447c_0 defaults
filelock 3.0.12 py_0 defaults
flake8 3.7.9 py37_0 defaults
flask 1.1.1 py_0 defaults
fontconfig 2.13.0 h9420a91_0 defaults
freetype 2.9.1 h8a8886c_1 defaults
fribidi 1.0.5 h7b6447c_0 defaults
fsspec 0.6.2 py_0 defaults
future 0.18.2 py37_0 defaults
get_terminal_size 1.0.0 haa9412d_0 defaults
gevent 1.4.0 py37h7b6447c_0 defaults
glib 2.63.1 h5a9c865_0 defaults
glob2 0.7 py_0 defaults
gmp 6.1.2 h6c8ec71_1 defaults
gmpy2 2.0.8 py37h10f8cd9_2 defaults
graphite2 1.3.13 h23475e2_0 defaults
greenlet 0.4.15 py37h7b6447c_0 defaults
gst-plugins-base 1.14.0 hbbd80ab_1 defaults
gstreamer 1.14.0 hb453b48_1 defaults
h5py 2.10.0 py37h7918eee_0 defaults
harfbuzz 1.8.8 hffaf4a1_0 defaults
hdf5 1.10.4 hb1b8bf9_0 defaults
heapdict 1.0.1 py_0 defaults
html5lib 1.0.1 py37_0 defaults
hypothesis 5.5.4 py_0 defaults
icu 58.2 h9c2bf20_1 defaults
idna 2.8 py37_0 defaults
imageio 2.6.1 py37_0 defaults
imagesize 1.2.0 py_0 defaults
importlib_metadata 1.5.0 py37_0 defaults
intel-openmp 2020.0 166 defaults
intervaltree 3.0.2 py_0 defaults
ipykernel 5.1.4 py37h39e3cac_0 defaults
ipython 7.12.0 py37h5ca1d4c_0 defaults
ipython_genutils 0.2.0 py37_0 defaults
ipywidgets 7.5.1 py_0 defaults
isort 4.3.21 py37_0 defaults
itsdangerous 1.1.0 py37_0 defaults
jbig 2.1 hdba287a_0 defaults
jdcal 1.4.1 py_0 defaults
jedi 0.14.1 py37_0 defaults
jeepney 0.4.2 py_0 defaults
jinja2 2.11.1 py_0 defaults
joblib 0.14.1 py_0 defaults
jpeg 9b h024ee3a_2 defaults
json5 0.9.1 py_0 defaults
jsonschema 3.2.0 py37_0 defaults
jupyter 1.0.0 py37_7 defaults
jupyter_client 5.3.4 py37_0 defaults
jupyter_console 6.1.0 py_0 defaults
jupyter_core 4.6.1 py37_0 defaults
jupyterlab 1.2.6 pyhf63ae98_0 defaults
jupyterlab_server 1.0.6 py_0 defaults
keyring 21.1.0 py37_0 defaults
kiwisolver 1.1.0 py37he6710b0_0 defaults
krb5 1.17.1 h173b8e3_0 defaults
lazy-object-proxy 1.4.3 py37h7b6447c_0 defaults
ld_impl_linux-64 2.33.1 h53a641e_7 defaults
libarchive 3.3.3 h5d8350f_5 defaults
libcurl 7.68.0 h20c2e04_0 defaults
libedit 3.1.20181209 hc058e9b_0 defaults
libffi 3.2.1 hd88cf55_4 defaults
libgcc-ng 9.1.0 hdf63c60_0 defaults
libgfortran-ng 7.3.0 hdf63c60_0 defaults
liblief 0.9.0 h7725739_2 defaults
libpng 1.6.37 hbc83047_0 defaults
libsodium 1.0.16 h1bed415_0 defaults
libspatialindex 1.9.3 he6710b0_0 defaults
libssh2 1.8.2 h1ba5d50_0 defaults
libstdcxx-ng 9.1.0 hdf63c60_0 defaults
libtiff 4.1.0 h2733197_0 defaults
libtool 2.4.6 h7b6447c_5 defaults
libuuid 1.0.3 h1bed415_2 defaults
libxcb 1.13 h1bed415_1 defaults
libxml2 2.9.9 hea5a465_1 defaults
libxslt 1.1.33 h7d1a2b0_0 defaults
llvmlite 0.31.0 py37hd408876_0 defaults
locket 0.2.0 py37_1 defaults
lxml 4.5.0 py37hefd8a0e_0 defaults
lz4-c 1.8.1.2 h14c3975_0 defaults
lzo 2.10 h49e0be7_2 defaults
markupsafe 1.1.1 py37h7b6447c_0 defaults
matplotlib 3.1.3 py37_0 defaults
matplotlib-base 3.1.3 py37hef1b27d_0 defaults
mccabe 0.6.1 py37_1 defaults
mistune 0.8.4 py37h7b6447c_0 defaults
mkl 2020.0 166 defaults
mkl-service 2.3.0 py37he904b0f_0 defaults
mkl_fft 1.0.15 py37ha843d7b_0 defaults
mkl_random 1.1.0 py37hd6b4f25_0 defaults
mock 4.0.1 py_0 defaults
more-itertools 8.2.0 py_0 defaults
mpc 1.1.0 h10f8cd9_1 defaults
mpfr 4.0.1 hdf1c602_3 defaults
mpmath 1.1.0 py37_0 defaults
msgpack-python 0.6.1 py37hfd86e86_1 defaults
multipledispatch 0.6.0 py37_0 defaults
navigator-updater 0.2.1 py37_0 defaults
nbconvert 5.6.1 py37_0 defaults
nbformat 5.0.4 py_0 defaults
ncurses 6.2 he6710b0_0 defaults
networkx 2.4 py_0 defaults
nltk 3.4.5 py37_0 defaults
nose 1.3.7 py37_2 defaults
notebook 6.0.3 py37_0 defaults
numba 0.48.0 py37h0573a6f_0 defaults
numexpr 2.7.1 py37h423224d_0 defaults
numpy 1.18.1 py37h4f9e942_0 defaults
numpy-base 1.18.1 py37hde5b4d6_1 defaults
numpydoc 0.9.2 py_0 defaults
olefile 0.46 py37_0 defaults
openpyxl 3.0.3 py_0 defaults
openssl 1.1.1d h7b6447c_4 defaults
packaging 20.1 py_0 defaults
pandas 1.0.1 py37h0573a6f_0 defaults
pandoc 2.2.3.2 0 defaults
pandocfilters 1.4.2 py37_1 defaults
pango 1.42.4 h049681c_0 defaults
parso 0.5.2 py_0 defaults
partd 1.1.0 py_0 defaults
patchelf 0.10 he6710b0_0 defaults
path 13.1.0 py37_0 defaults
path.py 12.4.0 0 defaults
pathlib2 2.3.5 py37_0 defaults
pathtools 0.1.2 py_1 defaults
patsy 0.5.1 py37_0 defaults
pcre 8.43 he6710b0_0 defaults
pep8 1.7.1 py37_0 defaults
pexpect 4.8.0 py37_0 defaults
pickleshare 0.7.5 py37_0 defaults
pillow 7.0.0 py37hb39fc2d_0 defaults
pip 20.0.2 py37_1 defaults
pixman 0.38.0 h7b6447c_0 defaults
pkginfo 1.5.0.1 py37_0 defaults
pluggy 0.13.1 py37_0 defaults
ply 3.11 py37_0 defaults
prometheus_client 0.7.1 py_0 defaults
prompt_toolkit 3.0.3 py_0 defaults
psutil 5.6.7 py37h7b6447c_0 defaults
ptyprocess 0.6.0 py37_0 defaults
py 1.8.1 py_0 defaults
py-lief 0.9.0 py37h7725739_2 defaults
pycodestyle 2.5.0 py37_0 defaults
pycosat 0.6.3 py37h7b6447c_0 defaults
pycparser 2.19 py37_0 defaults
pycrypto 2.6.1 py37h14c3975_9 defaults
pycurl 7.43.0.5 py37h1ba5d50_0 defaults
pydocstyle 4.0.1 py_0 defaults
pyflakes 2.1.1 py37_0 defaults
pygments 2.5.2 py_0 defaults
pylint 2.4.4 py37_0 defaults
pyodbc 4.0.30 py37he6710b0_0 defaults
pyopenssl 19.1.0 py37_0 defaults
pyparsing 2.4.6 py_0 defaults
pyqt 5.9.2 py37h05f1152_2 defaults
pyrsistent 0.15.7 py37h7b6447c_0 defaults
pysocks 1.7.1 py37_0 defaults
pytables 3.6.1 py37h71ec239_0 defaults
pytest 5.3.5 py37_0 defaults
pytest-arraydiff 0.3 py37h39e3cac_0 defaults
pytest-astropy 0.8.0 py_0 defaults
pytest-astropy-header 0.1.2 py_0 defaults
pytest-doctestplus 0.5.0 py_0 defaults
pytest-openfiles 0.4.0 py_0 defaults
pytest-remotedata 0.3.2 py37_0 defaults
python 3.7.6 h0371630_2 defaults
python-dateutil 2.8.1 py_0 defaults
python-jsonrpc-server 0.3.4 py_0 defaults
python-language-server 0.31.7 py37_0 defaults
python-libarchive-c 2.8 py37_13 defaults
pytz 2019.3 py_0 defaults
pywavelets 1.1.1 py37h7b6447c_0 defaults
pyxdg 0.26 py_0 defaults
pyyaml 5.3 py37h7b6447c_0 defaults
pyzmq 18.1.1 py37he6710b0_0 defaults
qdarkstyle 2.8 py_0 defaults
qt 5.9.7 h5867ecd_1 defaults
qtawesome 0.6.1 py_0 defaults
qtconsole 4.6.0 py_1 defaults
qtpy 1.9.0 py_0 defaults
readline 7.0 h7b6447c_5 defaults
requests 2.22.0 py37_1 defaults
ripgrep 11.0.2 he32d670_0 defaults
rope 0.16.0 py_0 defaults
rtree 0.9.3 py37_0 defaults
ruamel_yaml 0.15.87 py37h7b6447c_0 defaults
scikit-image 0.16.2 py37h0573a6f_0 defaults
scikit-learn 0.22.1 py37hd81dba3_0 defaults
scipy 1.4.1 py37h0b6359f_0 defaults
seaborn 0.10.0 py_0 defaults
secretstorage 3.1.2 py37_0 defaults
send2trash 1.5.0 py37_0 defaults
setuptools 45.2.0 py37_0 defaults
simplegeneric 0.8.1 py37_2 defaults
singledispatch 3.4.0.3 py37_0 defaults
sip 4.19.8 py37hf484d3e_0 defaults
six 1.14.0 py37_0 defaults
snappy 1.1.7 hbae5bb6_3 defaults
snowballstemmer 2.0.0 py_0 defaults
sortedcollections 1.1.2 py37_0 defaults
sortedcontainers 2.1.0 py37_0 defaults
soupsieve 1.9.5 py37_0 defaults
sphinx 2.4.0 py_0 defaults
sphinxcontrib 1.0 py37_1 defaults
sphinxcontrib-applehelp 1.0.1 py_0 defaults
sphinxcontrib-devhelp 1.0.1 py_0 defaults
sphinxcontrib-htmlhelp 1.0.2 py_0 defaults
sphinxcontrib-jsmath 1.0.1 py_0 defaults
sphinxcontrib-qthelp 1.0.2 py_0 defaults
sphinxcontrib-serializinghtml 1.1.3 py_0 defaults
sphinxcontrib-websupport 1.2.0 py_0 defaults
spyder 4.0.1 py37_0 defaults
spyder-kernels 1.8.1 py37_0 defaults
sqlalchemy 1.3.13 py37h7b6447c_0 defaults
sqlite 3.31.1 h7b6447c_0 defaults
statsmodels 0.11.0 py37h7b6447c_0 defaults
sympy 1.5.1 py37_0 defaults
tbb 2020.0 hfd86e86_0 defaults
tblib 1.6.0 py_0 defaults
terminado 0.8.3 py37_0 defaults
testpath 0.4.4 py_0 defaults
tk 8.6.8 hbc83047_0 defaults
toolz 0.10.0 py_0 defaults
tornado 6.0.3 py37h7b6447c_3 defaults
tqdm 4.42.1 py_0 defaults
traitlets 4.3.3 py37_0 defaults
ujson 1.35 py37h14c3975_0 defaults
unicodecsv 0.14.1 py37_0 defaults
unixodbc 2.3.7 h14c3975_0 defaults
urllib3 1.25.8 py37_0 defaults
watchdog 0.10.2 py37_0 defaults
wcwidth 0.1.8 py_0 defaults
webencodings 0.5.1 py37_1 defaults
werkzeug 1.0.0 py_0 defaults
wheel 0.34.2 py37_0 defaults
widgetsnbextension 3.5.1 py37_0 defaults
wrapt 1.11.2 py37h7b6447c_0 defaults
wurlitzer 2.0.0 py37_0 defaults
xlrd 1.2.0 py37_0 defaults
xlsxwriter 1.2.7 py_0 defaults
xlwt 1.3.0 py37_0 defaults
xmltodict 0.12.0 py_0 defaults
xz 5.2.4 h14c3975_4 defaults
yaml 0.1.7 had09818_2 defaults
yapf 0.28.0 py_0 defaults
zeromq 4.3.1 he6710b0_3 defaults
zict 1.0.0 py_0 defaults
zipp 2.2.0 py_0 defaults
zlib 1.2.11 h7b6447c_3 defaults
zstd 1.3.7 h0b5b093_0 defaults
大家自己查查就是了。里面有python,用-V查版本:
(base) lucky@lucky-ubuntu-Pc:~/.pip$ python -V
Python 3.7.6
刚才自己建立了一个名为“mypython36”的环境,接下来要激活此环境。
例如我先新建
conda create -n mypython36 python
结果会提示我已经有这样的一个环境了,是否需要移除?
lucky@lucky-ubuntu-Pc:~/.pip$ conda create -n mypython36 python
WARNING: A conda environment already exists at '/home/lucky/anaconda3/envs/mypython36'
Remove existing environment (y/[n])?
为了说明更全面,我选择y,就是移除并重建:
lucky@lucky-ubuntu-Pc:~/.pip$ conda create -n mypython36 python
WARNING: A conda environment already exists at '/home/lucky/anaconda3/envs/mypython36'
Remove existing environment (y/[n])? y
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.8.2
latest version: 4.8.3
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: /home/lucky/anaconda3/envs/mypython36
added / updated specs:
- python
The following NEW packages will be INSTALLED:
certifi anaconda/pkgs/free/linux-64::certifi-2016.2.28-py36_0
openssl anaconda/pkgs/free/linux-64::openssl-1.0.2l-0
pip anaconda/pkgs/free/linux-64::pip-9.0.1-py36_1
python anaconda/pkgs/free/linux-64::python-3.6.2-0
readline anaconda/pkgs/free/linux-64::readline-6.2-2
setuptools anaconda/pkgs/free/linux-64::setuptools-36.4.0-py36_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-py36_0
xz anaconda/pkgs/free/linux-64::xz-5.2.3-0
zlib anaconda/pkgs/free/linux-64::zlib-1.2.11-0
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate mypython36
#
# To deactivate an active environment, use
#
# $ conda deactivate
lucky@lucky-ubuntu-Pc:~/.pip$ source activate mypython36
bash: activate: 没有那个文件或目录
lucky@lucky-ubuntu-Pc:~/.pip$ conda activate mypython36
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$
这里有几个注意的提示:
- 有新的conda可以更新,并给出了更新的命令:
==> WARNING: A newer version of conda exists. <==
current version: 4.8.2
latest version: 4.8.3
Please update conda by running
$ conda update -n base -c defaults conda
2.激活和去激活这个环境方法
# To activate this environment, use
#
# $ conda activate mypython36
#
# To deactivate an active environment, use
#
# $ conda deactivate
就是用“conda activate+ 环境名”来激活用“conda deactivate”来去激活。
前两年我记得还是用source来激活的现在就不一样了?试一试的结果也再上面有了:
lucky@lucky-ubuntu-Pc:~/.pip$ source activate mypython36
bash: activate: 没有那个文件或目录
lucky@lucky-ubuntu-Pc:~/.pip$ conda activate mypython36
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$
问:去激活怎么没有“环境名”?我认为是同时虽然能激活多个环境,但是环境之间是按照压栈方法来管理的,就是说,先进来的后出去,后进来的认为是当前的焦点,所以对激活的环境,那么就默认了去激活也是对最后进入的这个激活的环境操作了。注意看看上面最后一行那个小括号:“(mypython36) ”和前面不指定环境直接用conda activate不带环境名激活的“(base)”的不同。看看下面的例子体会一下。
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$ conda deactivate
lucky@lucky-ubuntu-Pc:~/.pip$ conda activate
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda activate mypython36
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$ conda deactivate
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda deactivate
lucky@lucky-ubuntu-Pc:~/.pip$ conda activate mypython36
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$ conda activate
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda deactivate
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$ conda deactivate
lucky@lucky-ubuntu-Pc:~/.pip$
如果不使用了,则删除环境:
conda remove -n mypython36 –-all
但是要注意,需要从这个待移除的环境当中退出来才可以删除这个环境。
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$ conda remove -n mypython36 --all
CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again
(mypython36) lucky@lucky-ubuntu-Pc:~/.pip$ conda deactivate
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda remove -n mypython36 --all
Remove all packages in environment /home/lucky/anaconda3/envs/mypython36:
## Package Plan ##
environment location: /home/lucky/anaconda3/envs/mypython36
The following packages will be REMOVED:
certifi-2016.2.28-py36_0
openssl-1.0.2l-0
pip-9.0.1-py36_1
python-3.6.2-0
readline-6.2-2
setuptools-36.4.0-py36_1
sqlite-3.13.0-0
tk-8.5.18-0
wheel-0.29.0-py36_0
xz-5.2.3-0
zlib-1.2.11-0
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(base) lucky@lucky-ubuntu-Pc:~/.pip$
1.1.5 包安装
以matplotlib为例:
conda install matplotlib#安装包
# 查看已安装的包
conda list
# 包更新
conda update matplotlib
# 删除包
conda remove matplotlib
另外对于环境的更新:
# 更新conda本身
conda update conda
# 更新anaconda 应用
conda update anaconda
# 更新python,假设当前python环境是3.6.1,而最新版本是3.6.2,那么就会升级到3.6.2
conda update python
环境搭建好之后就可以开始愉快地玩数据分析了。
要注意的是,镜像源地址的版本一般都会比默认源的旧,如果不能保证版本一致,可能会有不一致导致的故障发生。由于无论conda的共享库还是某个特定加载的Anaconda环境,都会从配置地址( ~/.condarc)当中读取源库列表,那么在安装和更新库的时候就要注意一下版本。比如我要安装matplotlib的时候,就要先检查一下本地共享库当中的版本是否更新,如果已经有且更新,那就没有必要进行update,否则会因为更新源的版本较低而拉低本地的版本,或者让特定Anaconda环境中的库和本地共享库的版本不一致。
(2017年11月30日)关于这点还要说明一下:
在家里安装了同样的环境之后发现,比如对于tensorflow在没有激活任何Anaconda环境的时候,安装:conda install tensorflow,然后使用jupyter notebook无论是否进入环境都可以执行tensorflow的例子程序“./helloTensorflow.py ”,但是,在终端下运行要“python ./helloTensorflow.py ”才正确运行(以往只要“./helloTensorflow.py”则可),否则会报错:“ImportError: No module named tensorflow”。可是在新建的mypython36和mypython27两个环境当中,终端直接运行都是不可以的,只有激活环境之后(source avtivate XXX)使用终端也安装了“conda install tensorflow”才可以运行.但是jupyter notebook只要在系统中安装了tensorflow就可以运行。是不是在new新文件的时候环境选择有问题?这个不太好测试,因为我在mypython2.7和3.6当中都安装了tensorflow了。
2020年06月21日更新:
再说说这个更新源的事情,今天尝试下载了一下opencv发现根本解析不过去,一直处于:
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda install -c conda-forge opencv
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
CondaError: KeyboardInterrupt
于是CTR+C中断了。
查看了文章:
conda channel的镜像设置
首先,conda config --show能够显示出所有conda的config信息。
如果我们只想看channels的信息,输入conda config --show channels即可,如下:
输入了一下看看结果:
(base) lucky@lucky-ubuntu-Pc:~/.pip$ conda config --show channels
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- defaults
(base) lucky@lucky-ubuntu-Pc:~/.pip$
看来,我们更改更新源是对的,那么问题就应该是镜像源出问题了,过期了。
于是更换镜像源:
到这里找清华的更新源
清华更新源
由于之前是用超级用户自己新建的condarc文件,这样用户权限就是root的,所以现在进去删除“sudo rm .condarc"然后再运行
conda config --set show_channel_urls yes
就可以生成当前用户的的.condarc文件了,然后按照清华更新源说的更改。然后发现opencv的更新还是很慢,但是python的下载就很快,这个只能说明这个更新源里面没有opencv。
可是通过
conda search opencv
查看,发现到处都有opencv
(base) lucky@lucky-ubuntu-Pc:~$ conda search opencv
Loading channels: done
# Name Version Build Channel
opencv 2.4.2 np15py26_0 pkgs/free
opencv 2.4.2 np15py26_1 pkgs/free
opencv 2.4.2 np15py27_0 pkgs/free
opencv 2.4.2 np15py27_1 pkgs/free
opencv 2.4.2 np16py26_0 pkgs/free
opencv 2.4.2 np16py26_1 pkgs/free
opencv 2.4.2 np16py27_0 pkgs/free
opencv 2.4.2 np16py27_1 pkgs/free
opencv 2.4.2 np17py26_0 pkgs/free
opencv 2.4.2 np17py26_1 pkgs/free
opencv 2.4.2 np17py27_0 pkgs/free
opencv 2.4.2 np17py27_1 pkgs/free
opencv 2.4.6 np16py26_0 pkgs/free
opencv 2.4.6 np16py27_0 pkgs/free
opencv 2.4.6 np17py26_0 pkgs/free
opencv 2.4.6 np17py27_0 pkgs/free
opencv 2.4.6 np18py26_0 pkgs/free
opencv 2.4.6 np18py27_0 pkgs/free
opencv 2.4.9 np18py27_0 pkgs/free
opencv 2.4.10 np110py27_1 pkgs/free
opencv 2.4.10 np19py26_0 pkgs/free
opencv 2.4.10 np19py26_1 pkgs/free
opencv 2.4.10 np19py27_0 pkgs/free
opencv 2.4.10 np19py27_1 pkgs/free
opencv 3.1.0 np111py27_1 pkgs/free
opencv 3.1.0 np111py34_1 pkgs/free
opencv 3.1.0 np111py35_1 pkgs/free
opencv 3.1.0 np112py27_1 pkgs/free
opencv 3.1.0 np112py35_1 pkgs/free
opencv 3.1.0 np112py36_1 pkgs/free
opencv 3.3.1 py27h17fce66_0 pkgs/main
opencv 3.3.1 py27h61133dd_2 pkgs/main
opencv 3.3.1 py27h6cbbc71_1 pkgs/main
opencv 3.3.1 py27h9248ab4_2 pkgs/main
opencv 3.3.1 py27h9bb06ff_1 pkgs/main
opencv 3.3.1 py27hdcf4849_0 pkgs/main
opencv 3.3.1 py35h0b7da17_0 pkgs/main
opencv 3.3.1 py35h61133dd_2 pkgs/main
opencv 3.3.1 py35h6cbbc71_1 pkgs/main
opencv 3.3.1 py35h9248ab4_2 pkgs/main
opencv 3.3.1 py35h9bb06ff_1 pkgs/main
opencv 3.3.1 py35hb7523de_0 pkgs/main
opencv 3.3.1 py36h0a11808_0 pkgs/main
opencv 3.3.1 py36h0f6f1c3_0 pkgs/main
opencv 3.3.1 py36h61133dd_2 pkgs/main
opencv 3.3.1 py36h6cbbc71_1 pkgs/main
opencv 3.3.1 py36h9248ab4_2 pkgs/main
opencv 3.3.1 py36h9bb06ff_1 pkgs/main
opencv 3.4.1 py27h40b0b35_1 pkgs/main
opencv 3.4.1 py27h40b0b35_2 pkgs/main
opencv 3.4.1 py27h40b0b35_3 pkgs/main
opencv 3.4.1 py27h6fd60c2_1 pkgs/main
opencv 3.4.1 py27h6fd60c2_2 pkgs/main
opencv 3.4.1 py27h6fd60c2_3 pkgs/main
opencv 3.4.1 py35h40b0b35_1 pkgs/main
opencv 3.4.1 py35h40b0b35_2 pkgs/main
opencv 3.4.1 py35h6fd60c2_1 pkgs/main
opencv 3.4.1 py35h6fd60c2_2 pkgs/main
opencv 3.4.1 py36h40b0b35_1 pkgs/main
opencv 3.4.1 py36h40b0b35_2 pkgs/main
opencv 3.4.1 py36h40b0b35_3 pkgs/main
opencv 3.4.1 py36h6fd60c2_1 pkgs/main
opencv 3.4.1 py36h6fd60c2_2 pkgs/main
opencv 3.4.1 py36h6fd60c2_3 pkgs/main
opencv 3.4.1 py37h40b0b35_3 pkgs/main
opencv 3.4.1 py37h6fd60c2_3 pkgs/main
opencv 3.4.2 py27h40b0b35_0 pkgs/main
opencv 3.4.2 py27h40b0b35_1 pkgs/main
opencv 3.4.2 py27h6fd60c2_0 pkgs/main
opencv 3.4.2 py27h6fd60c2_1 pkgs/main
opencv 3.4.2 py35h40b0b35_0 pkgs/main
opencv 3.4.2 py35h40b0b35_1 pkgs/main
opencv 3.4.2 py35h6fd60c2_0 pkgs/main
opencv 3.4.2 py35h6fd60c2_1 pkgs/main
opencv 3.4.2 py36h40b0b35_0 pkgs/main
opencv 3.4.2 py36h40b0b35_1 pkgs/main
opencv 3.4.2 py36h6fd60c2_0 pkgs/main
opencv 3.4.2 py36h6fd60c2_1 pkgs/main
opencv 3.4.2 py37h40b0b35_0 pkgs/main
opencv 3.4.2 py37h40b0b35_1 pkgs/main
opencv 3.4.2 py37h6fd60c2_0 pkgs/main
opencv 3.4.2 py37h6fd60c2_1 pkgs/main
那怎么下载那么费劲?
想了想,python刚才是怎么虚拟的环境?
conda create -n mypython python
那么我们是不是可以用这种方法建立opencv?
照猫画虎:
conda create -n myopencv opencv
试一试:
(base) lucky@lucky-ubuntu-Pc:~$ conda create -n myopencv opencv
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/lucky/anaconda3/envs/myopencv
added / updated specs:
- opencv
The following NEW packages will be INSTALLED:
_libgcc_mutex pkgs/main/linux-64::_libgcc_mutex-0.1-main
blas pkgs/main/linux-64::blas-1.0-mkl
bzip2 pkgs/main/linux-64::bzip2-1.0.8-h7b6447c_0
ca-certificates pkgs/main/linux-64::ca-certificates-2020.1.1-0
cairo pkgs/main/linux-64::cairo-1.14.12-h8948797_3
certifi pkgs/main/linux-64::certifi-2020.4.5.2-py37_0
ffmpeg pkgs/main/linux-64::ffmpeg-4.0-hcdf2ecd_0
fontconfig pkgs/main/linux-64::fontconfig-2.13.0-h9420a91_0
freeglut pkgs/main/linux-64::freeglut-3.0.0-hf484d3e_5
freetype pkgs/main/linux-64::freetype-2.10.2-h5ab3b9f_0
glib pkgs/main/linux-64::glib-2.63.1-h3eb4bd4_1
graphite2 pkgs/main/linux-64::graphite2-1.3.13-h23475e2_0
harfbuzz pkgs/main/linux-64::harfbuzz-1.8.8-hffaf4a1_0
hdf5 pkgs/main/linux-64::hdf5-1.10.2-hba1933b_1
icu pkgs/main/linux-64::icu-58.2-he6710b0_3
intel-openmp pkgs/main/linux-64::intel-openmp-2020.1-217
jasper pkgs/main/linux-64::jasper-2.0.14-h07fcdf6_1
jpeg pkgs/main/linux-64::jpeg-9b-h024ee3a_2
ld_impl_linux-64 pkgs/main/linux-64::ld_impl_linux-64-2.33.1-h53a641e_7
libedit pkgs/main/linux-64::libedit-3.1.20191231-h7b6447c_0
libffi pkgs/main/linux-64::libffi-3.3-he6710b0_1
libgcc-ng pkgs/main/linux-64::libgcc-ng-9.1.0-hdf63c60_0
libgfortran-ng pkgs/main/linux-64::libgfortran-ng-7.3.0-hdf63c60_0
libglu pkgs/main/linux-64::libglu-9.0.0-hf484d3e_1
libopencv pkgs/main/linux-64::libopencv-3.4.2-hb342d67_1
libopus pkgs/main/linux-64::libopus-1.3.1-h7b6447c_0
libpng pkgs/main/linux-64::libpng-1.6.37-hbc83047_0
libstdcxx-ng pkgs/main/linux-64::libstdcxx-ng-9.1.0-hdf63c60_0
libtiff pkgs/main/linux-64::libtiff-4.1.0-h2733197_1
libuuid pkgs/main/linux-64::libuuid-1.0.3-h1bed415_2
libvpx pkgs/main/linux-64::libvpx-1.7.0-h439df22_0
libxcb pkgs/main/linux-64::libxcb-1.13-h1bed415_1
libxml2 pkgs/main/linux-64::libxml2-2.9.10-he19cac6_1
lz4-c pkgs/main/linux-64::lz4-c-1.9.2-he6710b0_0
mkl pkgs/main/linux-64::mkl-2020.1-217
mkl-service pkgs/main/linux-64::mkl-service-2.3.0-py37he904b0f_0
mkl_fft pkgs/main/linux-64::mkl_fft-1.1.0-py37h23d657b_0
mkl_random pkgs/main/linux-64::mkl_random-1.1.1-py37h0573a6f_0
ncurses pkgs/main/linux-64::ncurses-6.2-he6710b0_1
numpy pkgs/main/linux-64::numpy-1.18.1-py37h4f9e942_0
numpy-base pkgs/main/linux-64::numpy-base-1.18.1-py37hde5b4d6_1
opencv pkgs/main/linux-64::opencv-3.4.2-py37h6fd60c2_1
openssl pkgs/main/linux-64::openssl-1.1.1g-h7b6447c_0
pcre pkgs/main/linux-64::pcre-8.43-he6710b0_0
pip pkgs/main/linux-64::pip-20.1.1-py37_1
pixman pkgs/main/linux-64::pixman-0.38.0-h7b6447c_0
py-opencv pkgs/main/linux-64::py-opencv-3.4.2-py37hb342d67_1
python pkgs/main/linux-64::python-3.7.7-hcff3b4d_5
readline pkgs/main/linux-64::readline-8.0-h7b6447c_0
setuptools pkgs/main/linux-64::setuptools-47.3.0-py37_0
six pkgs/main/noarch::six-1.15.0-py_0
sqlite pkgs/main/linux-64::sqlite-3.32.2-h62c20be_0
tk pkgs/main/linux-64::tk-8.6.10-hbc83047_0
wheel pkgs/main/linux-64::wheel-0.34.2-py37_0
xz pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
zlib pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3
zstd pkgs/main/linux-64::zstd-1.4.4-h0b5b093_3
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate myopencv
#
# To deactivate an active environment, use
#
# $ conda deactivate
看来成功了,里面有opencv也有py-opencv,测试一下是不是可以。
先载入环境,然后打开python,然后调用cv2:
(base) lucky@lucky-ubuntu-Pc:~$ conda activate myopencv
(myopencv) lucky@lucky-ubuntu-Pc:~$ python
Python 3.7.7 (default, May 7 2020, 21:25:33)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
看来很ok。
2021年1月5日 更新开始
用这段代码更新就是了
pip install opencv-python
2021年1月5日更新结束
上述操作参考文档链接:opencv安装
看看这个环境里面安装了什么软件:
(myopencv) lucky@lucky-ubuntu-Pc:~$ conda list
# packages in environment at /home/lucky/anaconda3/envs/myopencv:
#
# Name Version Build Channel
_libgcc_mutex 0.1 main defaults
blas 1.0 mkl defaults
bzip2 1.0.8 h7b6447c_0 defaults
ca-certificates 2020.1.1 0 defaults
cairo 1.14.12 h8948797_3 defaults
certifi 2020.4.5.2 py37_0 defaults
ffmpeg 4.0 hcdf2ecd_0 defaults
fontconfig 2.13.0 h9420a91_0 defaults
freeglut 3.0.0 hf484d3e_5 defaults
freetype 2.10.2 h5ab3b9f_0 defaults
glib 2.63.1 h3eb4bd4_1 defaults
graphite2 1.3.13 h23475e2_0 defaults
harfbuzz 1.8.8 hffaf4a1_0 defaults
hdf5 1.10.2 hba1933b_1 defaults
icu 58.2 he6710b0_3 defaults
intel-openmp 2020.1 217 defaults
jasper 2.0.14 h07fcdf6_1 defaults
jpeg 9b h024ee3a_2 defaults
ld_impl_linux-64 2.33.1 h53a641e_7 defaults
libedit 3.1.20191231 h7b6447c_0 defaults
libffi 3.3 he6710b0_1 defaults
libgcc-ng 9.1.0 hdf63c60_0 defaults
libgfortran-ng 7.3.0 hdf63c60_0 defaults
libglu 9.0.0 hf484d3e_1 defaults
libopencv 3.4.2 hb342d67_1 defaults
libopus 1.3.1 h7b6447c_0 defaults
libpng 1.6.37 hbc83047_0 defaults
libstdcxx-ng 9.1.0 hdf63c60_0 defaults
libtiff 4.1.0 h2733197_1 defaults
libuuid 1.0.3 h1bed415_2 defaults
libvpx 1.7.0 h439df22_0 defaults
libxcb 1.13 h1bed415_1 defaults
libxml2 2.9.10 he19cac6_1 defaults
lz4-c 1.9.2 he6710b0_0 defaults
mkl 2020.1 217 defaults
mkl-service 2.3.0 py37he904b0f_0 defaults
mkl_fft 1.1.0 py37h23d657b_0 defaults
mkl_random 1.1.1 py37h0573a6f_0 defaults
ncurses 6.2 he6710b0_1 defaults
numpy 1.18.1 py37h4f9e942_0 defaults
numpy-base 1.18.1 py37hde5b4d6_1 defaults
opencv 3.4.2 py37h6fd60c2_1 defaults
openssl 1.1.1g h7b6447c_0 defaults
pcre 8.43 he6710b0_0 defaults
pip 20.1.1 py37_1 defaults
pixman 0.38.0 h7b6447c_0 defaults
py-opencv 3.4.2 py37hb342d67_1 defaults
python 3.7.7 hcff3b4d_5 defaults
readline 8.0 h7b6447c_0 defaults
setuptools 47.3.0 py37_0 defaults
six 1.15.0 py_0 defaults
sqlite 3.32.2 h62c20be_0 defaults
tk 8.6.10 hbc83047_0 defaults
wheel 0.34.2 py37_0 defaults
xz 5.2.5 h7b6447c_0 defaults
zlib 1.2.11 h7b6447c_3 defaults
zstd 1.4.4 h0b5b093_3 defaults
很好,可以看到
opencv 3.4.2 py37h6fd60c2_1 defaults
python 3.7.7 hcff3b4d_5 defaults
都在,如果想要新增其他的包,那么就自己安装就是了:
比如里面没有jupyter notebook,那么就安装:
conda install jupyter notebook
(myopencv) lucky@lucky-ubuntu-Pc:~$ conda install jupyter notebook
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/lucky/anaconda3/envs/myopencv
added / updated specs:
- jupyter
- notebook
The following packages will be downloaded:
package | build
---------------------------|-----------------
attrs-19.3.0 | py_0 40 KB defaults
backcall-0.2.0 | py_0 15 KB defaults
bleach-3.1.5 | py_0 116 KB defaults
dbus-1.13.14 | hb2f20db_0 504 KB defaults
decorator-4.4.2 | py_0 14 KB defaults
defusedxml-0.6.0 | py_0 23 KB defaults
gstreamer-1.14.0 | hb31296c_0 3.1 MB defaults
importlib-metadata-1.6.1 | py37_0 51 KB defaults
importlib_metadata-1.6.1 | 0 10 KB defaults
ipykernel-5.3.0 | py37h5ca1d4c_0 177 KB defaults
ipython-7.15.0 | py37_0 981 KB defaults
ipywidgets-7.5.1 | py_0 104 KB defaults
jedi-0.17.0 | py37_0 775 KB defaults
jinja2-2.11.2 | py_0 103 KB defaults
jupyter_client-6.1.3 | py_0 82 KB defaults
jupyter_core-4.6.3 | py37_0 71 KB defaults
nbformat-5.0.7 | py_0 89 KB defaults
packaging-20.4 | py_0 36 KB defaults
parso-0.7.0 | py_0 72 KB defaults
prometheus_client-0.8.0 | py_0 47 KB defaults
prompt-toolkit-3.0.5 | py_0 245 KB defaults
prompt_toolkit-3.0.5 | 0 11 KB defaults
pygments-2.6.1 | py_0 654 KB defaults
pyparsing-2.4.7 | py_0 65 KB defaults
pyrsistent-0.16.0 | py37h7b6447c_0 94 KB defaults
python-dateutil-2.8.1 | py_0 215 KB defaults
qtconsole-4.7.4 | py_0 95 KB defaults
qtpy-1.9.0 | py_0 38 KB defaults
testpath-0.4.4 | py_0 82 KB defaults
tornado-6.0.4 | py37h7b6447c_1 611 KB defaults
wcwidth-0.2.4 | py_0 29 KB defaults
zipp-3.1.0 | py_0 13 KB defaults
------------------------------------------------------------
Total: 8.4 MB
The following NEW packages will be INSTALLED:
attrs pkgs/main/noarch::attrs-19.3.0-py_0
backcall pkgs/main/noarch::backcall-0.2.0-py_0
bleach pkgs/main/noarch::bleach-3.1.5-py_0
dbus pkgs/main/linux-64::dbus-1.13.14-hb2f20db_0
decorator pkgs/main/noarch::decorator-4.4.2-py_0
defusedxml pkgs/main/noarch::defusedxml-0.6.0-py_0
entrypoints pkgs/main/linux-64::entrypoints-0.3-py37_0
expat pkgs/main/linux-64::expat-2.2.6-he6710b0_0
gmp pkgs/main/linux-64::gmp-6.1.2-h6c8ec71_1
gst-plugins-base pkgs/main/linux-64::gst-plugins-base-1.14.0-hbbd80ab_1
gstreamer pkgs/main/linux-64::gstreamer-1.14.0-hb31296c_0
importlib-metadata pkgs/main/linux-64::importlib-metadata-1.6.1-py37_0
importlib_metadata pkgs/main/noarch::importlib_metadata-1.6.1-0
ipykernel pkgs/main/linux-64::ipykernel-5.3.0-py37h5ca1d4c_0
ipython pkgs/main/linux-64::ipython-7.15.0-py37_0
ipython_genutils pkgs/main/linux-64::ipython_genutils-0.2.0-py37_0
ipywidgets pkgs/main/noarch::ipywidgets-7.5.1-py_0
jedi pkgs/main/linux-64::jedi-0.17.0-py37_0
jinja2 pkgs/main/noarch::jinja2-2.11.2-py_0
jsonschema pkgs/main/linux-64::jsonschema-3.2.0-py37_0
jupyter pkgs/main/linux-64::jupyter-1.0.0-py37_7
jupyter_client pkgs/main/noarch::jupyter_client-6.1.3-py_0
jupyter_console pkgs/main/noarch::jupyter_console-6.1.0-py_0
jupyter_core pkgs/main/linux-64::jupyter_core-4.6.3-py37_0
libsodium pkgs/main/linux-64::libsodium-1.0.16-h1bed415_0
markupsafe pkgs/main/linux-64::markupsafe-1.1.1-py37h7b6447c_0
mistune pkgs/main/linux-64::mistune-0.8.4-py37h7b6447c_0
nbconvert pkgs/main/linux-64::nbconvert-5.6.1-py37_0
nbformat pkgs/main/noarch::nbformat-5.0.7-py_0
notebook pkgs/main/linux-64::notebook-6.0.3-py37_0
packaging pkgs/main/noarch::packaging-20.4-py_0
pandoc pkgs/main/linux-64::pandoc-2.2.3.2-0
pandocfilters pkgs/main/linux-64::pandocfilters-1.4.2-py37_1
parso pkgs/main/noarch::parso-0.7.0-py_0
pexpect pkgs/main/linux-64::pexpect-4.8.0-py37_0
pickleshare pkgs/main/linux-64::pickleshare-0.7.5-py37_0
prometheus_client pkgs/main/noarch::prometheus_client-0.8.0-py_0
prompt-toolkit pkgs/main/noarch::prompt-toolkit-3.0.5-py_0
prompt_toolkit pkgs/main/noarch::prompt_toolkit-3.0.5-0
ptyprocess pkgs/main/linux-64::ptyprocess-0.6.0-py37_0
pygments pkgs/main/noarch::pygments-2.6.1-py_0
pyparsing pkgs/main/noarch::pyparsing-2.4.7-py_0
pyqt pkgs/main/linux-64::pyqt-5.9.2-py37h05f1152_2
pyrsistent pkgs/main/linux-64::pyrsistent-0.16.0-py37h7b6447c_0
python-dateutil pkgs/main/noarch::python-dateutil-2.8.1-py_0
pyzmq pkgs/main/linux-64::pyzmq-18.1.1-py37he6710b0_0
qt pkgs/main/linux-64::qt-5.9.7-h5867ecd_1
qtconsole pkgs/main/noarch::qtconsole-4.7.4-py_0
qtpy pkgs/main/noarch::qtpy-1.9.0-py_0
send2trash pkgs/main/linux-64::send2trash-1.5.0-py37_0
sip pkgs/main/linux-64::sip-4.19.8-py37hf484d3e_0
terminado pkgs/main/linux-64::terminado-0.8.3-py37_0
testpath pkgs/main/noarch::testpath-0.4.4-py_0
tornado pkgs/main/linux-64::tornado-6.0.4-py37h7b6447c_1
traitlets pkgs/main/linux-64::traitlets-4.3.3-py37_0
wcwidth pkgs/main/noarch::wcwidth-0.2.4-py_0
webencodings pkgs/main/linux-64::webencodings-0.5.1-py37_1
widgetsnbextension pkgs/main/linux-64::widgetsnbextension-3.5.1-py37_0
zeromq pkgs/main/linux-64::zeromq-4.3.1-he6710b0_3
zipp pkgs/main/noarch::zipp-3.1.0-py_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
dbus-1.13.14 | 504 KB | ##################################### | 100%
prompt_toolkit-3.0.5 | 11 KB | ##################################### | 100%
jupyter_client-6.1.3 | 82 KB | ##################################### | 100%
jupyter_core-4.6.3 | 71 KB | ##################################### | 100%
defusedxml-0.6.0 | 23 KB | ##################################### | 100%
prompt-toolkit-3.0.5 | 245 KB | ##################################### | 100%
attrs-19.3.0 | 40 KB | ##################################### | 100%
tornado-6.0.4 | 611 KB | ##################################### | 100%
wcwidth-0.2.4 | 29 KB | ##################################### | 100%
nbformat-5.0.7 | 89 KB | ##################################### | 100%
jedi-0.17.0 | 775 KB | ##################################### | 100%
jinja2-2.11.2 | 103 KB | ##################################### | 100%
gstreamer-1.14.0 | 3.1 MB | ##################################### | 100%
pyparsing-2.4.7 | 65 KB | ##################################### | 100%
parso-0.7.0 | 72 KB | ##################################### | 100%
qtconsole-4.7.4 | 95 KB | ##################################### | 100%
packaging-20.4 | 36 KB | ##################################### | 100%
python-dateutil-2.8. | 215 KB | ##################################### | 100%
pygments-2.6.1 | 654 KB | ##################################### | 100%
importlib-metadata-1 | 51 KB | ##################################### | 100%
decorator-4.4.2 | 14 KB | ##################################### | 100%
importlib_metadata-1 | 10 KB | ##################################### | 100%
ipython-7.15.0 | 981 KB | ##################################### | 100%
prometheus_client-0. | 47 KB | ##################################### | 100%
ipywidgets-7.5.1 | 104 KB | ##################################### | 100%
bleach-3.1.5 | 116 KB | ##################################### | 100%
ipykernel-5.3.0 | 177 KB | ##################################### | 100%
pyrsistent-0.16.0 | 94 KB | ##################################### | 100%
zipp-3.1.0 | 13 KB | ##################################### | 100%
qtpy-1.9.0 | 38 KB | ##################################### | 100%
backcall-0.2.0 | 15 KB | ##################################### | 100%
testpath-0.4.4 | 82 KB | ##################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
还算挺快。
1.2 jupyter notebook 可以做哪些事情?
参考链接:
1.2.1 安装jupyter
同上
1.2.2 运行
打开终端运行
jupyter notebook
但是如果是在windows当中用Anaconda prompt运行就会发现很多麻烦,因为为了让Anaconda prompt执行能够具有管理员权限,所以需要以管理员身份运行Anaconda prompt,但是这样一来,默认的路径就会到了c:windowssystem32下了,这里如果直接运行jupyter notebook就会因为路径当中有太多的文件导致运行十分低效,刷新很慢。而且因为是在非常重要的文件夹下,进行文件调试和生成也诸多不安全。于是可以用如下命令让当前环境转到D:盘下去:
(base) C:Windowssystem32>d:
(base) D:>cd D:workprogramStudyAIFarm
(base) D:workprogramStudyAIFarm>
1.2.3 使用step by step
1. 环境自动关联:
conda install nb_conda,该包可以将conda中创建的环境自动关联到你的notebook中。
先CTR+C退出jupyter 服务,然后运行"conda install nb_conda"
(myopencv) lucky@lucky-ubuntu-Pc:~$ conda install nb_conda
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/lucky/anaconda3/envs/myopencv
added / updated specs:
- nb_conda
The following packages will be downloaded:
package | build
---------------------------|-----------------
nb_conda-2.2.1 | py37_0 32 KB defaults
nb_conda_kernels-2.2.3 | py37_0 39 KB defaults
------------------------------------------------------------
Total: 71 KB
The following NEW packages will be INSTALLED:
nb_conda pkgs/main/linux-64::nb_conda-2.2.1-py37_0
nb_conda_kernels pkgs/main/linux-64::nb_conda_kernels-2.2.3-py37_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
nb_conda-2.2.1 | 32 KB | ##################################### | 100%
nb_conda_kernels-2.2 | 39 KB | ##################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: b'Enabling nb_conda_kernels...nStatus: enabledn'
| b'Enabling notebook extension nb_conda/main...n - Validating: x1b[32mOKx1b[0mnEnabling tree extension nb_conda/tree...n - Validating: x1b[32mOKx1b[0mnEnabling: nb_condan- Writing config: /home/lucky/anaconda3/envs/myopencv/etc/jupytern - Validating...n nb_conda 2.2.1 x1b[32mOKx1b[0mn'
done
再打开jupyter notebook
未关联之前是这样的:
关联之后是这样的:
用ART+ printscr键截图
局部截图怎么做?
Shift+printscr
要查看Anaconda有几个环境,运行:
conda env list
得到结果:
(myopencv) lucky@lucky-ubuntu-Pc:~$ conda env list
# conda environments:
#
base /home/lucky/anaconda3
myopencv * /home/lucky/anaconda3/envs/myopencv
mypython /home/lucky/anaconda3/envs/mypython
这就是刚才我们建立的几个环境。
有人问,上图jupyter界面新建环境当中怎么没有mypython?当然,我们是再myopencv当中安装的jupyter notebook所以,jupyter notebook没有mypython是对的。
2. 在Anaconda终端运行代码自动补全命令:
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install --user jupyter_nbextensions_configurator
jupyter contrib nbextension install --user --skip-running-check
上述的pip命令用之前的代码是会出问题的:
(myopencv) lucky@lucky-ubuntu-Pc:~$ pip install jupyter_contrib_nbextensions
Configuration file could not be loaded.
Source contains parsing errors: '/home/lucky/.pip/pip.conf'
[line 2]: 'trustedn'
那个’/home/lucky/.pip/pip.conf’是豆瓣的源,现在用阿里云的源就好了。
进入当前用户的.pip文件夹查看pip.conf文件:
(myopencv) lucky@lucky-ubuntu-Pc:~$ cd .pip
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ gedit .condarc
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ gedit pip.conf
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ ls
pip.conf
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ ls -all
总用量 12
drwxr-xr-x 2 lucky lucky 4096 6月 21 09:51 .
drwxr-xr-x 25 lucky lucky 4096 6月 21 12:39 ..
-rw-r--r-- 1 root root 87 6月 21 07:43 pip.conf
发现这个pip.conf居然是root权限的,于是删除重新建当前用户权限的文件:
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ sudo rm pip.conf
[sudo] lucky 的密码:
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ gedit pip.conf
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ ls -all
总用量 12
drwxr-xr-x 2 lucky lucky 4096 6月 21 12:59 .
drwxr-xr-x 25 lucky lucky 4096 6月 21 12:39 ..
-rw-r--r-- 1 lucky lucky 105 6月 21 12:59 pip.conf
现在这个pip.conf是当前用户权限了,于是接着写入以下内容:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
存盘,再进行测试pip:
(myopencv) lucky@lucky-ubuntu-Pc:~/.pip$ conda install pip
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
说明pip已经有了,而且表现很正常。
此时再运行前面的那四句安装代码
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install --user jupyter_nbextensions_configurator
jupyter contrib nbextension install --user --skip-running-check
将上述步骤执行完之后一切正常,而且速度挺快的。
这时按参考材料所述“这个时候就出现了Nbextensions,勾选Hinterland。有需要其他扩展的根据需要进行勾选”,但是没有见到勾选,都是叉叉,还选不了。于是到处找资料都没有看到结果,都是说按照上述安装好就可以了,勾选Hinterland就搞定了。于是去国外搜了搜,果然有说明,还是stack overflow厉害,啥都有解说:
针对问题:
All jupyter contrib nbextensions are marked as possibly incompatible
解答说:
很简答,就是把这个适应性勾选项去掉就好了。
然后就一切正常了
其实就是插件相对于jupyter notebook版本滞后了。
查了查现在的版本:
(myopencv) lucky@lucky-ubuntu-Pc:~$ jupyter --version
jupyter core : 4.6.3
jupyter-notebook : 6.0.3
qtconsole : 4.7.4
ipython : 7.15.0
ipykernel : 5.3.0
jupyter client : 6.1.3
jupyter lab : not installed
nbconvert : 5.6.1
ipywidgets : 7.5.1
nbformat : 5.0.7
traitlets : 4.3.3
看到jupyter版本是4.6.3,jupyter notebook版本是6.0.3。
上述插件支持版本:
Hinterland
Enable code autocompletion menu for every keypress in a code cell, instead of only enabling it with tab
section: notebook
require path: hinterland/hinterland
compatibility: 4.x, 5.x
支持4.X、5.X 版本,看来是这原因,不过能用就好了。
在windows当中用Anaconda prompt运行上述pip的安装的时候会报错
EnvironmentNotWritableError: The current user does not have write permissions to the target environm…
可以看到是说没有权限在相应的文件夹进行操作,解决方法:
使用管理员权限运行Anaconda prompt。
2021年1月5日09:19:08 更新开始
今天重新在windows10上安装anaconda,又温习了一遍本篇教程,发现新问题,于是记录。
问题:新建了myopencv环境,也按照上述方法进行了jupyter和插件的安装,但是运行jupyter notebook的时候就是没有看到 Nbextensions的设置栏出来。用了哪种教程都没有解决此问题。于是就出来看看其他的环境,于是退出myopencv,在base环境下进行上述插件安装,然后运行jupyter notebook,居然有Nbextensions的设置栏了,那说明还是环境设置问题。又测试了一下我新建的Python3.7的环境(用conda create -n mypython3.7 python=3.7建立),发现的确有差异。
(mypython37) PS D:conda> conda list
# packages in environment at C:ProgramDataAnaconda3envsmypython37:
#
# Name Version Build Channel
absl-py 0.9.0 py37hc8dfbb8_1 conda-forge
astor 0.8.1 pyh9f0ad1d_0 conda-forge
attrs 19.3.0 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
backcall 0.2.0 pyh9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
blas 1.0 mkl https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
bleach 3.1.0 py37_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
blosc 1.19.0 ha925a31_0 conda-forge
brotli 1.0.7 ha925a31_1004 conda-forge
bzip2 1.0.8 hfa6e2cd_2 conda-forge
ca-certificates 2020.6.20 hecda079_0 conda-forge
certifi 2020.6.20 py37hc8dfbb8_0 conda-forge
chardet 3.0.4 pypi_0 pypi
charls 2.1.0 h33f27b4_2 conda-forge
click 7.1.2 pypi_0 pypi
cloudpickle 1.5.0 py_0 conda-forge
colorama 0.4.3 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
cycler 0.10.0 py_2 conda-forge
cytoolz 0.10.1 py37hfa6e2cd_0 conda-forge
dask-core 2.20.0 py_0 conda-forge
decorator 4.4.2 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
defusedxml 0.6.0 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
entrypoints 0.3 py37hc8dfbb8_1001 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
freetype 2.10.2 hd328e21_0 conda-forge
funcsigs 1.0.2 pypi_0 pypi
gast 0.3.3 py_0 conda-forge
giflib 5.2.1 h2fa13f4_2 conda-forge
google-pasta 0.2.0 pyh8c360ce_0 conda-forge
grpcio 1.30.0 py37h554427f_0 conda-forge
h5py 2.10.0 nompi_py37hde23a51_103 conda-forge
hdf5 1.10.6 nompi_ha405e13_100 conda-forge
icc_rt 2019.0.0 h0cc432a_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
icu 64.2 he025d50_1 conda-forge
idna 2.10 pypi_0 pypi
imagecodecs 2020.5.30 py37h92c78e3_2 conda-forge
imageio 2.9.0 py_0 conda-forge
importlib-metadata 1.7.0 py37hc8dfbb8_0 conda-forge
importlib_metadata 1.7.0 0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
intel-openmp 2020.1 216 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
ipykernel 5.3.2 py37h5ca1d4c_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ipython 7.16.1 py37h43977f1_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ipython_genutils 0.2.0 py_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ipywidgets 7.5.1 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jedi 0.17.1 py37hc8dfbb8_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jinja2 2.11.2 pyh9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
joblib 0.16.0 pypi_0 pypi
jpeg 9d he774522_0 conda-forge
jsonschema 3.2.0 py37hc8dfbb8_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jupyter 1.0.0 py_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jupyter-contrib-core 0.3.3 pypi_0 pypi
jupyter-contrib-nbextensions 0.5.1 pypi_0 pypi
jupyter-highlight-selected-word 0.2.0 pypi_0 pypi
jupyter-latex-envs 1.4.6 pypi_0 pypi
jupyter-nbextensions-configurator 0.4.1 pypi_0 pypi
jupyter_client 5.3.3 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jupyter_console 6.1.0 py_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jupyter_core 4.5.0 py_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jxrlib 1.1 hfa6e2cd_2 conda-forge
keras 2.3.1 py37h21ff451_0 conda-forge
再和myopencv的比较一下:
(myopencv) PS D:conda> conda list
# packages in environment at C:ProgramDataAnaconda3envsmyopencv:
#
# Name Version Build Channel
argon2-cffi 20.1.0 py39hb82d6ee_2 conda-forge
async_generator 1.10 py_0 conda-forge
attrs 20.3.0 pyhd3deb0d_0 conda-forge
backcall 0.2.0 pyh9f0ad1d_0 conda-forge
backports 1.0 py_2 conda-forge
backports.functools_lru_cache 1.6.1 py_0 conda-forge
bleach 3.2.1 pyh9f0ad1d_0 conda-forge
ca-certificates 2020.12.5 h5b45459_0 conda-forge
certifi 2020.12.5 py39hcbf5309_0 conda-forge
cffi 1.14.4 py39h0878f49_1 conda-forge
colorama 0.4.4 pyh9f0ad1d_0 conda-forge
decorator 4.4.2 py_0 conda-forge
defusedxml 0.6.0 py_0 conda-forge
entrypoints 0.3 pyhd8ed1ab_1003 conda-forge
freeglut 3.2.1 h0e60522_0 conda-forge
freetype 2.10.4 h546665d_0 conda-forge
icu 68.1 h0e60522_0 conda-forge
importlib-metadata 3.3.0 py39hcbf5309_2 conda-forge
importlib_metadata 3.3.0 hd8ed1ab_2 conda-forge
intel-openmp 2020.3 h57928b3_311 conda-forge
ipykernel 5.4.2 py39he1a07ef_0 conda-forge
ipython 7.19.0 py39h832f523_0 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
ipywidgets 7.6.2 pyhd3deb0d_1 conda-forge
jasper 2.0.14 h77af90b_2 conda-forge
jedi 0.18.0 py39hcbf5309_1 conda-forge
jinja2 2.11.2 pyh9f0ad1d_0 conda-forge
jpeg 9d h8ffe710_0 conda-forge
jsonschema 3.2.0 py_2 conda-forge
jupyter 1.0.0 py_2 conda-forge
jupyter-contrib-core 0.3.3 pypi_0 pypi
jupyter-contrib-nbextensions 0.5.1 pypi_0 pypi
jupyter-highlight-selected-word 0.2.0 pypi_0 pypi
jupyter-latex-envs 1.4.6 pypi_0 pypi
jupyter-nbextensions-configurator 0.4.1 pypi_0 pypi
jupyter_client 6.1.7 py_0 conda-forge
jupyter_console 6.2.0 py_0 conda-forge
jupyter_core 4.7.0 py39hcbf5309_0 conda-forge
jupyterlab_pygments 0.1.2 pyh9f0ad1d_0 conda-forge
jupyterlab_widgets 1.0.0 pyhd8ed1ab_1 conda-forge
libblas 3.9.0 6_mkl conda-forge
发现数据的“channel”都是conda-forge,不知道是不是这个源导致的。于是先移除myopencv,修改源出处。现在的源文件.condarc是这样的:
channels:
- conda-forge
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
show_channel_urls: true
把第一个源“ - conda-forge”挪到最后面,重新保存
channels:
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- conda-forge
show_channel_urls: true
删除myopencv:
(myopencv) PS D:conda> conda deactivate
(base) PS D:conda> conda remove -n myopencv --all
Remove all packages in environment C:ProgramDataAnaconda3envsmyopencv:
## Package Plan ##
environment location: C:ProgramDataAnaconda3envsmyopencv
The following packages will be REMOVED:
argon2-cffi-20.1.0-py39hb82d6ee_2
async_generator-1.10-py_0
attrs-20.3.0-pyhd3deb0d_0
backcall-0.2.0-pyh9f0ad1d_0
...
重新建myopencv
(base) PS D:conda> conda create -n myopencv opencv python=3.7
WARNING: A directory already exists at the target location 'C:ProgramDataAnaconda3envsmyopencv'
but it is not a conda environment.
Continue creating environment (y/[n])? y
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:ProgramDataAnaconda3envsmyopencv
added / updated specs:
- opencv
- python=3.7
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2020.12.5 | h5b45459_0 173 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
certifi-2020.12.5 | py37h03978a9_0 143 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
freeglut-3.2.1 | h0e60522_0 576 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
freetype-2.10.4 | h546665d_0 493 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
icu-68.1 | h0e60522_0 16.3 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
intel-openmp-2020.3 | h57928b3_311 2.0 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jasper-2.0.14 | h77af90b_1 667 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
jpeg-9d | h8ffe710_0 366 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libblas-3.9.0 | 4_mkl 3.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libcblas-3.9.0 | 4_mkl 3.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libclang-11.0.0 |default_h5c34c98_2 20.8 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
liblapack-3.9.0 | 4_mkl 3.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
liblapacke-3.9.0 | 4_mkl 3.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libopencv-4.5.0 | py37_4 46.8 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libpng-1.6.37 | h1d00b33_2 724 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libtiff-4.2.0 | hc10be44_0 1.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libwebp-base-1.1.0 | h8ffe710_3 366 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
lz4-c-1.9.3 | h8ffe710_0 134 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
mkl-2020.4 | hb70f87d_311 172.4 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
numpy-1.19.4 | py37hd20adf4_1 4.8 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
opencv-4.5.0 | py37_4 23 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
openssl-1.1.1i | h8ffe710_0 5.8 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pip-20.3.3 | pyhd8ed1ab_0 1.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
py-opencv-4.5.0 | py37heaed05f_4 24 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python-3.7.9 |h7840368_0_cpython 17.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
qt-5.12.9 | h5909a2a_2 106.1 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
setuptools-49.6.0 | py37hf50a25e_2 919 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
sqlite-3.34.0 | h8ffe710_0 1.2 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
vc-14.2 | hb210afc_2 12 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
vs2015_runtime-14.28.29325 | h5e1d092_0 1.4 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wheel-0.36.2 | pyhd3deb0d_0 31 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wincertstore-0.2 |py37hc8dfbb8_1005 15 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
xz-5.2.5 | h62dcd97_1 211 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
zlib-1.2.11 | h62dcd97_1010 126 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
zstd-1.4.8 | h4e2f164_1 902 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
------------------------------------------------------------
Total: 418.9 MB
The following NEW packages will be INSTALLED:
ca-certificates anaconda/cloud/conda-forge/win-64::ca-certificates-2020.12.5-h5b45459_0
certifi anaconda/cloud/conda-forge/win-64::certifi-2020.12.5-py37h03978a9_0
freeglut anaconda/cloud/conda-forge/win-64::freeglut-3.2.1-h0e60522_0
freetype anaconda/cloud/conda-forge/win-64::freetype-2.10.4-h546665d_0
icu anaconda/cloud/conda-forge/win-64::icu-68.1-h0e60522_0
intel-openmp anaconda/cloud/conda-forge/win-64::intel-openmp-2020.3-h57928b3_311
jasper anaconda/cloud/conda-forge/win-64::jasper-2.0.14-h77af90b_1
jpeg anaconda/cloud/conda-forge/win-64::jpeg-9d-h8ffe710_0
libblas anaconda/cloud/conda-forge/win-64::libblas-3.9.0-4_mkl
libcblas anaconda/cloud/conda-forge/win-64::libcblas-3.9.0-4_mkl
libclang anaconda/cloud/conda-forge/win-64::libclang-11.0.0-default_h5c34c98_2
liblapack anaconda/cloud/conda-forge/win-64::liblapack-3.9.0-4_mkl
liblapacke anaconda/cloud/conda-forge/win-64::liblapacke-3.9.0-4_mkl
libopencv anaconda/cloud/conda-forge/win-64::libopencv-4.5.0-py37_4
...
重新运行安装jupyter插件,一切就都顺利了。
2021年1月5日09:19:24 更新结束
2021年1月5日21:21:53 开始
进入发现都设置好了,但是自动提示还是没有出现。发现在base环境下的就可以有自动提示,不管是从base环境输入jupyter notebook进入网页,然后新建一个root模式的
2021年1月5日21:22:04 结束
- 执行命令
键盘上同时按住ctrl+enter键,当然也可以用鼠标在界面上指指点点。 - 输出
点击File->Download as,你可以选择多种格式下载你的notebook。一般我都会根据下面的用途来选择不同的下载格式:
1)如果我想和客户分享我的数据分析成果,我会选择将notebook下载为HTML文件。
2)如果我希望将自己的数据分析成果和代码嵌入到项目中,比如为药店管理系统做个数据分析子模块,我就会选择Python(.py)模块,这可以将我的代码融入项目中,成为子模块,方便和其他开发人员共同完成任务。
3)如果要在博客或文档中使用 notebook,我就选择Markdown格式。
好了,你会使用notebook了。
1.2.4 关于快捷键:
27 个Jupyter Notebook的小提示与技巧
Jupyter在顶部的菜单里保留了许多快捷键:Help > keyboard Shortcuts(快捷键’h’直达). 每次更新Jupyter时,都值得再次进行查看,因为新的快捷键总是不断被添加进来。
另一个查看快捷键的方式是使用命令面板: Ctrl + Shift + P。这个对话框将会帮助你通过名称运行任何命令 – 这非常有用,尤其当你不知道一个命令的快捷键或者你想要执行的命令没有快捷键时。
1.3 jupyter 使用技巧积累
Jupyter Notebook的27个秘诀,技巧和快捷键
27 个Jupyter Notebook的小提示与技巧
有链接看就行了,具体的这里不再赘述了。
接下来就是一下几个内容:
- 关于jupyter的使用举例
- 强大的数组、矩阵计算——numpy
- 强大的数组、矩阵计算——panda
如何优雅的使用jupyter
最后
以上就是愉快早晨为你收集整理的Python学习笔记之(一)——环境建设1. python软件环境的全部内容,希望文章能够帮你解决Python学习笔记之(一)——环境建设1. python软件环境所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复