anaconda3之基本使用、更换国内镜像、安装python虚拟器、第三方库安装及问题解决

软件环境:anaconda3+pycharm
系统:win10
python版本:3.7
anaconda基本使用

  • anaconda主要是一个虚拟环境管理器,还是一个安装包管理器
  • conda list:显示anaconda安装的包
  • conda env list:显示anaconda的虚拟环境列表
  • conda create -n xxx python=3.7:创建python版本为3.7的虚拟环境(我这里使用的是3.7的版本),名称为xxx
更换国内镜像:
本来用的国外原本的镜像,结果在建立python虚拟器时连接不上,我就切换了国内的镜像,下面以增加清华镜像为例:
在命令行输入如下:
C:\Users\lenovo>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free C:\Users\lenovo>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main C:\Users\lenovo>conda config --set show_channel_urls yes

运行成功后,会在C:\Users\lenovo下建立一个.condarc的文件,.condarc这个文件默认是没有的,添加镜像时自动建立的,在更换镜像之前记得删掉原有的或者直接在原先的.condarc文件中改也行,此次测试自动建的文件内容如下:
show_channel_urls: truechannels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free- defaults

网上有的人说添加完channels之后要把.condarc里的-defaults删掉,有的人没删,我都试了试,感觉没什么区别,这次测试我没删,到此为止镜像已经配好了,可以装个库试一下(下面以wordcloud库为例):
在终端(cmd)输入命令如下:
C:\Users\lenovo>conda install wordcloud

一般情况下,应该是成功了,成功的小伙伴祝贺各位!/(ㄒoㄒ)/~~可是我没有,哭死,又出现了以下问题:
PackagesNotFoundError: The following packages are not available from current channels
PackagesNotFoundError: The following packages are not available from current channels:- wordcloud Current channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch To search for alternate channels that may provide the conda package you'relooking for, navigate tohttps://anaconda.org and use the search bar at the top of the page.

这个问题是说此包无法从当前取得让换一个渠道,想解决这个问题的话,我们可以换一个命令或者用pip试一下:
C:\Users\lenovo>conda install -c conda-forge wordcloud

成功找到环境了,呱唧呱唧~但是有一个警告,提醒我有新的conda版本了,让我更新并且在下面已经给出了更新的命令,照着敲就好了:
Solving environment: done ==> WARNING: A newer version of conda exists. <==current version: 4.5.12latest version: 4.6.8 Please update conda by running$ conda update -n base -c defaults conda ## Package Plan ##environment location: D:\anaconda_locationadded / updated specs:- wordcloud The following packages will be downloaded:package|build---------------------------|-----------------ca-certificates-2018.03.07 |0155 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/maincertifi-2018.11.29|py37_0146 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainwordcloud-1.5.0|py37hfa6e2cd_1000185 KBconda-forgeconda-4.6.8|py37_0897 KBconda-forgeopenssl-1.1.1a|he774522_05.7 MBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main------------------------------------------------------------Total:7.1 MBThe following NEW packages will be INSTALLED:wordcloud:1.5.0-py37hfa6e2cd_1000 conda-forgeThe following packages will be UPDATED:ca-certificates: 2018.03.07-0defaults--> 2018.03.07-0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/maincertifi:2018.11.29-py37_0defaults--> 2018.11.29-py37_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainconda:4.5.12-py37_0defaults--> 4.6.8-py37_0conda-forgeopenssl:1.1.1a-he774522_0defaults--> 1.1.1a-he774522_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainProceed ([y]/n)? yDownloading and Extracting Packagesca-certificates-2018 | 155 KB| ############################################################################ | 100%certifi-2018.11.29| 146 KB| ############################################################################ | 100%wordcloud-1.5.0| 185 KB| ############################################################################ | 100%conda-4.6.8| 897 KB| ############################################################################ | 100%openssl-1.1.1a| 5.7 MB| ############################################################################ | 100%Preparing transaction: doneVerifying transaction: doneExecuting transaction: done

输入conda更新命令:conda update -n base -c defaults conda
会像上面一样列出很多包什么的,如果是你需要的,在Proceed ([y]/n)? 输入y即可(其实不选y也不行啊,不同意就不能继续安装了),这样就更新成功了!
然后我又试着装了wordcloud,scrapy等库都成功了,但是还是有很多不行。接下来让我们看一下——
第三方库安装及问题解决
这时候可以在命令行输入:
anaconda search -t conda packbgename例如:anaconda search -t conda turtle

然后按照提示找能用的镜像路径或者直接上网搜,实际应用anaconda的过程中,发现有很多库并不存在,常用的安装方法都有哪些?
1、打开anaconda的命令行“Anaconda Prompt”或者windows终端(cmd),在命令行中输入conda install 任意包/库名;
2、打开anaconda的命令行“Anaconda Prompt”或者windows终端(cmd),在命令行中输入pip install 任意包/库名;
3、下载whl文件---打开anaconda的命令行“Anaconda Prompt”---pip install 路径+whl文件名;
还不行的话,具体问题具体分析吧,每次电脑装东西的时候都有各种问题真是好崩溃啊,之前直接用的Python软件,虽然没有anaconda功能强大,但是装库的时候也没有那麽多事情,也没有说镜像连不上或者库找不到合适镜像的问题,有点想换回去/(ㄒoㄒ)/~如果哪位大佬对anaconda有更好的镜像或者安装第三方库有更好的方法欢迎留言指教,灰常感谢
附:换回默认源
conda config --remove-key channels

在pycharm中安装python虚拟器及具体使用操作
接着让我们回到在pycharm中安装python虚拟机,文章有点长啊~但是也不想分开写了,这都是在我想装虚拟器时中途遇到的
一些问题,一块解决了吧~
打开pycharm的终端,输入如下:
D:\Python37\cources\01day>conda create -n oop python=3.7

成功运行,提示Proceed ([y]/n)?,输入y,按回车。下面是运行过程和结果,可不看,最后几句给了激活环境的提示命令
Collecting package metadata: doneSolving environment: done ## Package Plan ##environment location: D:\anaconda_location\envs\oopadded / updated specs:- python=3.7 The following packages will be downloaded:package|build---------------------------|-----------------ca-certificates-2019.1.23|0158 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/maincertifi-2019.3.9|py37_0155 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainopenssl-1.1.1b|he774522_15.7 MBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainpip-19.0.3|py37_01.8 MBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainpython-3.7.2|h8c8aaf0_1017.7 MBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainsetuptools-40.8.0|py37_0663 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainsqlite-3.27.2|he774522_0941 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainvc-14.1|h0510ff6_46 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainvs2015_runtime-14.15.26706 |h3a45250_02.2 MBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainwheel-0.33.1|py37_057 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainwincertstore-0.2|py37_013 KBhttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main------------------------------------------------------------Total:29.4 MBThe following NEW packages will be INSTALLED:ca-certificatesanaconda/pkgs/main/win-64::ca-certificates-2019.1.23-0certifianaconda/pkgs/main/win-64::certifi-2019.3.9-py37_0opensslanaconda/pkgs/main/win-64::openssl-1.1.1b-he774522_1pipanaconda/pkgs/main/win-64::pip-19.0.3-py37_0pythonanaconda/pkgs/main/win-64::python-3.7.2-h8c8aaf0_10setuptoolsanaconda/pkgs/main/win-64::setuptools-40.8.0-py37_0sqliteanaconda/pkgs/main/win-64::sqlite-3.27.2-he774522_0vcanaconda/pkgs/main/win-64::vc-14.1-h0510ff6_4vs2015_runtimeanaconda/pkgs/main/win-64::vs2015_runtime-14.15.26706-h3a45250_0wheelanaconda/pkgs/main/win-64::wheel-0.33.1-py37_0wincertstoreanaconda/pkgs/main/win-64::wincertstore-0.2-py37_0 Proceed ([y]/n)? y Downloading and Extracting Packagessqlite-3.27.2| 941 KB| ################################################## | 100%vs2015_runtime-14.15 | 2.2 MB| ################################################## | 100%certifi-2019.3.9| 155 KB| ################################################## | 100%setuptools-40.8.0| 663 KB| ################################################## | 100%python-3.7.2| 17.7 MB| ################################################## | 100%pip-19.0.3| 1.8 MB| ################################################## | 100%ca-certificates-2019 | 158 KB| ################################################## | 100%openssl-1.1.1b| 5.7 MB| ################################################## | 100%vc-14.1| 6 KB| ################################################## | 100%wheel-0.33.1| 57 KB| ################################################## | 100%wincertstore-0.2| 13 KB| ################################################## | 100%Preparing transaction: doneVerifying transaction: doneExecuting transaction: done## To activate this environment, use:# > activate oop## To deactivate an active environment, use:# > deactivate## * for power-users using bash, you must source#

根据最后几句给出的激活命令,输入如下进行激活:
D:\Python37\cources\01day>activate oop

运行结果如下,我们可以看到前面多了个(oop),说明此时我们已经在建立好的虚拟器中。
(oop) D:\Python37\cources\01day>

这是我们再使用conda list查看在这个虚拟器下自带已经安装好的包,这些是我们直接可以使用不用再安装的
(oop) D:\Python37\cources\01day>conda list# packages in environment at D:\anaconda_location\envs\oop:## NameVersionBuildChannelca-certificates2019.1.230https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/maincertifi2019.3.9py37_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainopenssl1.1.1bhe774522_1https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainpip19.0.3py37_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainpython3.7.2h8c8aaf0_10https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainsetuptools40.8.0py37_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainsqlite3.27.2he774522_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainvc14.1h0510ff6_4https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainvs2015_runtime14.15.26706h3a45250_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainwheel0.33.1py37_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/mainwincertstore0.2py37_0https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main

如何使用我们这个虚拟器呢?
在pycharm中,打开settings—>Project Interpreter
anaconda3之基本使用、更换国内镜像、安装python虚拟器、第三方库安装及问题解决
文章图片
image 我们可以看到当前的Project Interpreter中还是原来的环境,我们可以点击下拉框进行选择,如果没有,点击右边的小齿轮,接着点击add进行添加,接着我们进入了以下界面。conda Env是Virtualenv的升级版,此时我们选择已存在的环境,添加我们刚刚创建好的名为oop的虚拟器,我的安装路径如下,找自己的anaconda安装路径下的envs和后面的文件直到python.exe,有的是在oop的bin文件下,我的没有,里面有很多python3.exe或者其他的可执行版本,选一个就行,不必纠结。
anaconda3之基本使用、更换国内镜像、安装python虚拟器、第三方库安装及问题解决
文章图片
image 【anaconda3之基本使用、更换国内镜像、安装python虚拟器、第三方库安装及问题解决】接下来我们就可以到新建的虚拟器中了,我们可以看到这个虚拟机中已有的东西,点击ok就行了,接下来就和往常操作一样可以运行了,赶紧试试吧~
anaconda3之基本使用、更换国内镜像、安装python虚拟器、第三方库安装及问题解决
文章图片
image 有什么建议或者方法欢迎留言告知~

    推荐阅读