一、基本介绍
在介绍Anaconda之前,我们使用python常见使用的IDE是pyCharm,而安装第三方包或python库而两种形式:
1.使用命令
pip install 包名
2.IDE内安装
Anaconda是一款可以获取包及对包进行管理、环境统一管理的软件。其中包含conda、Python在内的超过180个科学包及其依赖项。
二、环境搭建(pyCharm+Anaconda)
1、安装pyCharm
2、安装Anaconda
三、基础命令
新增虚拟环境
(base) faria-2:anaconda3$ sudo conda create --name pymysql
Password:
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /Users/xxx/anaconda3/envs/pymysql
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate pymysql
#
# To deactivate an active environment, use
#
# $ conda deactivate
删除keyconda config --remove-key channels
查看已有配置
(base) faria-2:anaconda3$ conda config --show
add_anaconda_token: True
add_pip_as_python_dependency: True
aggressive_update_packages:
- ca-certificates
- certifi
- openssl
allow_conda_downgrades: False
allow_cycles: True
allow_non_channel_urls: False
allow_softlinks: False
always_copy: False
always_softlink: False
always_yes: None
anaconda_upload: None
auto_activate_base: True
auto_stack: 0
auto_update_conda: True
bld_path:
changeps1: True
channel_alias: https://conda.anaconda.org
channel_priority: flexible
channels:
- defaults
client_ssl_cert: None
client_ssl_cert_key: None
clobber: False
conda_build: {}
create_default_packages: []
croot: /Users/xxx/anaconda3/conda-bld
custom_channels:
pkgs/main: https://repo.anaconda.com
pkgs/r: https://repo.anaconda.com
pkgs/pro: https://repo.anaconda.com
custom_multichannels:
defaults:
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r
新增镜像(清华镜像用http)
(base) faria-2:anaconda3$ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/osx-64/
查看虚拟环境(现有的虚拟环境*)
(pymysql) faria-2:~$ conda env list
# conda environments:
#
base /Users/xxx/anaconda3
pymysql * /Users/xxx/anaconda3/envs/pymysql
切换虚拟环境
conda activate 环境名称
激活镜像
(base) faria-2:anaconda$ source activate pymysql
常见问题
1、使用的镜像(清华)用了https协议
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/osx-64/repodata.json>
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/main/osx-64'
解决思路:重新添加镜像为http
2、新增虚拟环境报错
CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/osx-64/repodata.json>
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.
If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.
'https://repo.anaconda.com/pkgs/main/osx-64'
解决步骤:
(base) faria-2:anaconda3$ conda config --set ssl_verify no
(base) faria-2:anaconda3$ conda config --set ssl_verify false
(base) faria-2:anaconda3$ vim ~/.condarc
(base) faria-2:anaconda3$ sudo conda create --name pymysql
3、无法安装镜像
(base) faria-2:anaconda3 xxx$ sudo conda install -c anaconda redis
Password:
Collecting package metadata (repodata.json): failed
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/exceptions.py", line 1080, in __call__
return func(*args, **kwargs)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/cli/main.py", line 84, in _main
exit_code = do_call(args, p)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/cli/conda_argparse.py", line 83, in do_call
return getattr(module, func_name)(args, parser)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/cli/main_install.py", line 20, in execute
install(args, parser, 'install')
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/cli/install.py", line 263, in install
should_retry_solve=(_should_retry_unfrozen or repodata_fn != repodata_fns[-1]),
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/solve.py", line 117, in solve_for_transaction
should_retry_solve)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/solve.py", line 158, in solve_for_diff
force_remove, should_retry_solve)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/solve.py", line 262, in solve_final_state
ssc = self._collect_all_metadata(ssc)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/common/io.py", line 88, in decorated
return f(*args, **kwds)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/solve.py", line 425, in _collect_all_metadata
index, r = self._prepare(prepared_specs)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/solve.py", line 1021, in _prepare
self.subdirs, prepared_specs, self._repodata_fn)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/index.py", line 289, in get_reduced_index
repodata_fn=repodata_fn)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 140, in query_all
result = tuple(concat(executor.map(subdir_query, channel_urls)))
File "/Users/xxx/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 586, in result_iterator
yield fs.pop().result()
File "/Users/xxx/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
File "/Users/xxx/anaconda3/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/Users/xxx/anaconda3/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 133, in <lambda>
package_ref_or_match_spec))
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 145, in query
self.load()
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 210, in load
_internal_state = self._load()
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 394, in _load
mod_etag_headers.get('_mod'))
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 442, in _read_local_repdata
_internal_state = self._process_raw_repodata_str(raw_repodata_str)
File "/Users/xxx/anaconda3/lib/python3.7/site-packages/conda/core/subdir_data.py", line 480, in _process_raw_repodata_str
json_obj = json.loads(raw_repodata_str or '{}')
File "/Users/xxx/anaconda3/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/Users/xxx/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/xxx/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 291378 column 33 (char 8808000)
`$ /Users/xxx/anaconda3/bin/conda install -c anaconda redis`
environment variables:
CIO_TEST=<not set>
CONDA_ROOT=/Users/xxx/anaconda3
CURL_CA_BUNDLE=<not set>
PATH=/usr/local/bin:/usr/local/sbin:/Users/xxx/anaconda3/bin:/Users/c
henfenyu/anaconda3/condabin:/Library/Java/JavaVirtualMachines/jdk1.8.0
_181.jdk/Contents/Home/bin:/usr/local/anaconda3/bin:/usr/local/bin:/us
r/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/usr/local/bin/ChromeDriv
er:/usr/local/mysql/bin:.:/Users/xxx/Work/apache-jmeter-5.4.1/bi
n:/usr/local/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbi
n:/usr/local/go/bin:/usr/local/bin/ChromeDriver:/usr/local/mysql/bin
REQUESTS_CA_BUNDLE=<not set>
SSL_CERT_FILE=<not set>
SUDO_COMMAND=/Users/xxx/anaconda3/bin/conda install -c anaconda redis
SUDO_GID=20
SUDO_UID=501
SUDO_USER=xxx
active environment : None
user config file : /Users/xxx/.condarc
populated config files : /Users/xxx/.condarc
conda version : 4.11.0
conda-build version : 3.17.6
python version : 3.7.1.final.0
virtual packages : __osx=10.16=0
__unix=0=0
__archspec=1=x86_64
base environment : /Users/xxx/anaconda3 (writable)
conda av data dir : /Users/xxx/anaconda3/etc/conda
conda av metadata url : None
channel URLs : https://conda.anaconda.org/anaconda/osx-64
https://conda.anaconda.org/anaconda/noarch
http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/osx-64
http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/osx-64
http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
package cache : /Users/xxx/anaconda3/pkgs
/Users/xxx/.conda/pkgs
envs directories : /Users/xxx/anaconda3/envs
/Users/xxx/.conda/envs
platform : osx-64
user-agent : conda/4.11.0 requests/2.21.0 CPython/3.7.1 Darwin/20.6.0 OSX/10.16
UID:GID : 0:0
netrc file : None
offline mode : False
An unexpected error has occurred. Conda has prepared the above report.
Upload successful.
解决思路:
(base) faria-2:~ xxx$ cd ~
(base) faria-2:~ xxx$ rm .condarc
举例:pyautogui配合anaconda的安装
方式1-虚拟环境:sudo conda install -c anaconda redis (指定版本https://anaconda.org/search?q=redis 可查询)
方式2-虚拟环境离线包:conda install --use-local gdal-2.3.0-py36h04863e7_1.tar.bz2
方式2-本机环境:
pip install /路径/cacheout-0.14.1-py3-none-any.whl(https://pypi.org/project/cacheout/#files whl文件)
python (解压后路径)setup.py install (https://pypi.org/project/cacheout/#files tar.gz文件)