$ py --version # 当前默认python版本
Python 3.7.1
$ conda create --name testpy2 python=2.7 pandas # 创建名为testpy2的运行环境,并安装pandas包及其依赖包
Solving environment: done
## Package Plan ##
environment location: D:\DownLoadFiles\anaconda3\envs\testpy2 # 创建的运行环境的所在目录
added / updated specs: # conda仅安装pandas和python2.7相关的必须项(pandas的依赖项,python2.7, pip等)
- pandas
- python=2.7
The following packages will be downloaded: # 将要下载当前没有的安装包
package | build
---------------------------|-----------------
vc-9 | h7299396_1 3 KB
python-dateutil-2.7.5 | py27_0 275 KB
pandas-0.23.4 | py27h39f3610_0 8.8 MB
pytz-2018.7 | py27_0 250 KB
certifi-2018.10.15 | py27_0 139 KB
setuptools-40.5.0 | py27_0 653 KB
numpy-base-1.15.4 | py27h2753ae9_0 3.8 MB
pip-18.1 | py27_0 1.8 MB
vs2008_runtime-9.00.30729.1| hfaea7d5_1 1017 KB
wincertstore-0.2 | py27hf04cefb_0 13 KB
python-2.7.15 | h2880e7c_3 20.3 MB
six-1.11.0 | py27_1 21 KB
numpy-1.15.4 | py27hbe4291b_0 36 KB
mkl_fft-1.0.6 | py27hac4a418_0 120 KB
wheel-0.32.2 | py27_0 52 KB
------------------------------------------------------------
Total: 37.1 MB
The following NEW packages will be INSTALLED: # 将要安装的包
blas: 1.0-mkl
certifi: 2018.10.15-py27_0
icc_rt: 2017.0.4-h97af966_0
intel-openmp: 2019.0-118
mkl: 2019.0-118
mkl_fft: 1.0.6-py27hac4a418_0
numpy: 1.15.4-py27hbe4291b_0
numpy-base: 1.15.4-py27h2753ae9_0
pandas: 0.23.4-py27h39f3610_0
pip: 18.1-py27_0
python: 2.7.15-h2880e7c_3
python-dateutil: 2.7.5-py27_0
pytz: 2018.7-py27_0
setuptools: 40.5.0-py27_0
six: 1.11.0-py27_1
vc: 9-h7299396_1
vs2008_runtime: 9.00.30729.1-hfaea7d5_1
wheel: 0.32.2-py27_0
wincertstore: 0.2-py27hf04cefb_0
Proceed ([y]/n)? y
Downloading and Extracting Packages
vc-9 | 3 KB | ######################################################################## | 100%
python-dateutil-2.7. | 275 KB | ######################################################################## | 100%
pandas-0.23.4 | 8.8 MB | ######################################################################## | 100%
pytz-2018.7 | 250 KB | ######################################################################## | 100%
certifi-2018.10.15 | 139 KB | ######################################################################## | 100%
setuptools-40.5.0 | 653 KB | ######################################################################## | 100%
numpy-base-1.15.4 | 3.8 MB | ######################################################################## | 100%
pip-18.1 | 1.8 MB | ######################################################################## | 100%
vs2008_runtime-9.00. | 1017 KB | ######################################################################## | 100%
wincertstore-0.2 | 13 KB | ######################################################################## | 100%
python-2.7.15 | 20.3 MB | ######################################################################## | 100%
six-1.11.0 | 21 KB | ######################################################################## | 100%
numpy-1.15.4 | 36 KB | ######################################################################## | 100%
mkl_fft-1.0.6 | 120 KB | ######################################################################## | 100%
wheel-0.32.2 | 52 KB | ######################################################################## | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > activate testpy2
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
$ conda env list # 显示所有运行环境
# conda environments:
#
base * D:\DownLoadFiles\anaconda3 # 星号表示是当前运行环境
testpy2 D:\DownLoadFiles\anaconda3\envs\testpy2
$ source activate testpy2 # 进入testpy2运行环境
(testpy2)
$ conda env list
# conda environments:
#
base D:\DownLoadFiles\anaconda3
testpy2 * D:\DownLoadFiles\anaconda3\envs\testpy2 # 星号表示是当前运行环境
(testpy2)
$ py --version
Python 3.7.1
(testpy2) # 括号中显示当前的运行环境
$ conda info # 显示conda信息
active environment : testpy2
active env location : D:\DownLoadFiles\anaconda3\envs\testpy2
shell level : 1
user config file : C:\Users\guowli\.condarc
populated config files : C:\Users\guowli\.condarc
conda version : 4.5.11
conda-build version : 3.16.2
python version : 3.7.1.final.0
base environment : D:\DownLoadFiles\anaconda3 (writable)
channel URLs : https://repo.anaconda.com/pkgs/main/win-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/win-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/win-64
https://repo.anaconda.com/pkgs/r/noarch
https://repo.anaconda.com/pkgs/pro/win-64
https://repo.anaconda.com/pkgs/pro/noarch
https://repo.anaconda.com/pkgs/msys2/win-64
https://repo.anaconda.com/pkgs/msys2/noarch
package cache : D:\DownLoadFiles\anaconda3\pkgs
C:\Users\guowli\AppData\Local\conda\conda\pkgs
envs directories : D:\DownLoadFiles\anaconda3\envs
C:\Users\guowli\AppData\Local\conda\conda\envs
C:\Users\guowli\.conda\envs
platform : win-64
user-agent : conda/4.5.11 requests/2.20.0 CPython/3.7.1 Windows/7 Windows/6.1.7601
administrator : False
netrc file : None
offline mode : False
(testpy2)
$ source deactivate # 退出当前运行环境
$ conda env list
# conda environments:
#
base * D:\DownLoadFiles\anaconda3 # 星号表示是当前运行环境
testpy2 D:\DownLoadFiles\anaconda3\envs\testpy2
$ conda env remove --name testpy2 # 删除运行环境
Remove all packages in environment D:\DownLoadFiles\anaconda3\envs\testpy2:
## Package Plan ##
environment location: D:\DownLoadFiles\anaconda3\envs\testpy2
The following packages will be REMOVED:
blas: 1.0-mkl
certifi: 2018.10.15-py27_0
icc_rt: 2017.0.4-h97af966_0
intel-openmp: 2019.0-118
mkl: 2019.0-118
mkl_fft: 1.0.6-py27hac4a418_0
numpy: 1.15.4-py27hbe4291b_0
numpy-base: 1.15.4-py27h2753ae9_0
pandas: 0.23.4-py27h39f3610_0
pip: 18.1-py27_0
python: 2.7.15-h2880e7c_3
python-dateutil: 2.7.5-py27_0
pytz: 2018.7-py27_0
setuptools: 40.5.0-py27_0
six: 1.11.0-py27_1
vc: 9-h7299396_1
vs2008_runtime: 9.00.30729.1-hfaea7d5_1
wheel: 0.32.2-py27_0
wincertstore: 0.2-py27hf04cefb_0
Proceed ([y]/n)? y
$ conda env list
# conda environments:
#
base * D:\DownLoadFiles\anaconda3
$
5- 在PyCharm中使用Anaconda创建的环境
5.1 查看Conda环境信息
在Anaconda Prompt中通过“conda env list”查看所有环境信息,确认环境所在目录;
注意:通过Conda创建的虚拟环境默认放置envs目录中,例如:“D:\DownLoadFiles\anaconda3\envs\mlcc”
5.2 更改PyCharm的编译器选项
打开Pycharm,然后依次点击File---》Settings---》Project:xxxxx---》Project Interperter---》“齿轮”按钮---》“Add Local...”
在出现页面中,添加Conda环境信息并保存
此时,依次点击File---》Settings---》Project:xxxxx---》Project Interperter---》“齿轮”按钮---》“Show All...”
依次点击File---》Settings---》Project:xxxxx---》Project Interperter,选择相应的环境。
6- 参考信息
7- 问题处理
7.1“WARNING: The conda.compat module is deprecated and will be removed in a future release.”
问题现象:
安装Anaconda3后,在Anaconda Prompt执行conda命令, 例如“conda env list”,提示告警信息“WARNING: The conda.compat module is deprecated and will be removed in a future release.”
问题原因:
问题处理方法:
升级conda版本。
(base) C:\Users\guowli>conda update conda
WARNING: The conda.compat module is deprecated and will be removedina future release.
Collecting package metadata:doneSolving environment:done## Package Plan ##
environment location: C:\Office-Tools\Anaconda3
added/updated specs:-conda
The following packages will be downloaded:
package|build---------------------------|-----------------conda-4.6.14 | py37_0 2.1MB defaults------------------------------------------------------------Total:2.1MB
The following packages will be UPDATED:
conda4.6.11-py37_0 --> 4.6.14-py37_0
Proceed ([y]/n)?y
Downloading and Extracting Packages
conda-4.6.14 | 2.1 MB | ############################################################################ | 100%Preparing transaction:doneVerifying transaction:doneExecuting transaction:done(base) C:\Users\guowli>ET _sysp=%~dpA'ET'is not recognized as an internal or external command,
operable program or batchfile.
(base) C:\Users\guowli>IF NOT EXIST "!_sysp!\Scripts\conda.exe"Collecting package metadata:doneSolving environment:done# All requested packages already installed.
(base) C:\Users\guowli>conda --version
conda4.6.14(base) C:\Users\guowli>conda envlist
# conda environments:
#
base* C:\Office-Tools\Anaconda3
(base) C:\Users\guowli>
7.2 “CondaHTTPError: HTTP 000 CONNECTION FAILED for url”
问题现象
λ conda installjenkinsapi
Collecting package metadata (current_repodata.json): failed
CondaHTTPError: HTTP000 CONNECTION FAILED for url
Elapsed: -An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.'https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64'
处理方法
1. 通过“conda search ”命令确认要安装的包是否存在,如果包名称不一致,将报错
2. 修改镜像源的配置, 将用户目录下的.condarc文件中的所有https换成http
如果Windows用户无法直接创建名为.condarc的文件,可先执行“conda config --set show_channel_urls yes”生成该文件之后再修改。
λ cat ~/.condarc
channels:- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
- http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
ssl_verify: falseshow_channel_urls:true
然后运行`conda clean -i`清除索引缓存,保证用的是镜像站提供的索引,重新安装库时会重新下载repo信息。
7.3 在Anaconda的环境下,使用pip安装库报错“SSL: CERTIFICATE_VERIFY_FAILED”
问题现象
λ pip installjenkinsapi
Collecting jenkinsapi
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /packages/e2/76/c7ceb2fac632e2772d38ffcf446b4432582ddc6d6ea2d19155e06011d1d4/jenkinsapi-0.3.11-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /packages/e2/76/c7ceb2fac632e2772d38ffcf446b4432582ddc6d6ea2d19155e06011d1d4/jenkinsapi-0.3.11-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /packages/e2/76/c7ceb2fac632e2772d38ffcf446b4432582ddc6d6ea2d19155e06011d1d4/jenkinsapi-0.3.11-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /packages/e2/76/c7ceb2fac632e2772d38ffcf446b4432582ddc6d6ea2d19155e06011d1d4/jenkinsapi-0.3.11-py2.py3-none-any.whl
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1,'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))': /packages/e2/76/c7ceb2fac632e2772d38ffcf446b4432582ddc6d6ea2d19155e06011d1d4/jenkinsapi-0.3.11-py2.py3-none-any.whl
ERROR: Could notinstall packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/e2/76/c7ceb2fac632e2772d38ffcf446b4432582ddc6d6ea2d19155e06011d1d4/jenkinsapi-0.3.11-py2.py3-none-any.whl (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))
处理方法
国内防火墙的限制,自当镜像源或者`--trusted-host`即可解决。
1. 指定可用的镜像源
”pip install -i “
2. 指定`--trusted-host`
“pip install jenkinsapi --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org”