anaconda技巧 安装(各种历史版本)+使用一段时间进行清理+pytorch+环境迁移(pip freeze等方法 )+jupyter的使用

anaconda常用命令+注意

vpn 用户注意:pip install error: check_hostname requires server_hostname

说明命令
安装了哪些包?conda list
环境列表conda env list
创建环境conda create -n env_name python=3.7
conda create -n new --clone old
删除环境conda remove -n env_name --all
环境列表conda info --envs
激活环境conda activate env_name
conda activate base
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate’.conda init
复制环境conda create -n New --clone Old
python 版本python -V
注意python -v会进入一种特殊的python模式,使用exit()退出

anaconda 清理环境

说明命令
关闭虚拟环境source deactivate
清理环境conda clean -a
未清理之前:
在这里插入图片描述
在这里插入图片描述
查看环境列表的返回结果中,带有星号的为当前的环境:
pytorch1.1-python3.7  *  /data/apps/anaconda/anaconda3/envs/pytorch1.1-python3.7
pytorch1.7-python3.8     /data/apps/anaconda/anaconda3/envs/pytorch1.7-python3.8

参考pip install 和conda install有什么区别吗?:

conda install xxx这种方式安装的库都会放在anaconda3/pkgs目录下另一个环境中还需要这个库时,就可以直接从pkgs目录下将该库复制至新环境而不用重复下载
pip install xxxconda环境的python是conda安装的安装到anaconda3/envs/current_env/lib/python3.x/site-packages
pip install xxx当前conda环境用的是系统的python安装到~/.local/lib/python3.x/site-packages
文中同时提到了python -m site命令可以用于查看全局包目录的位置答主同时说sys.path的显示顺序即为包查找的先后顺序,有人提出了异议,运行命令后第一个条目是当前目录,我尝试运行也时同样的当前目录
可以使用 import sitepritnt(site.getsitepackages())更多详见官网

anaconda安装

官方下载链接,官网一般是最新的python

历史版本,Anaconda3-2.0.0-Windows-x86_64.exe为3.4;3.8的
在这里插入图片描述

勾选“Add Anaconda to my PATH environment variable.”可用于兼容多个版本的Anaconda或者多个版本的Python,在此勾选“Register Anaconda as my default Python 3.”。

在这里插入图片描述

在这里插入图片描述
跳过vscode的安装
在这里插入图片描述
在这里插入图片描述

使用语句“conda create -n 容器的名称 python=3.7”创建容器使得可在一台电脑上安装多个版本的pytorch

conda create -n xxx python=yyy


在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

如果报错
Solving environment: failed

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/main/win-64/repodata.json.bz2>
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.

ConnectionError(ReadTimeoutError("HTTPSConnectionPool(host='repo.anaconda.com', port=443): Read timed out."))

解决办法
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
base为当前所在的环境,“conda activate 名称”为新环境的激活方式

anaconda一直initializing
D:\anaconda3\Lib\site-packages\anaconda_navigator\utils\attribution 
24行requests.get(url),改成requests.get(url,timeout(0.01,0.1))

在这里插入图片描述

anaconda一直loading application

在这里插入图片描述

安装pytorch

https://pytorch.org/get-started/locally/
在这里插入图片描述
在这里插入图片描述

进入容器,运行代码,pip list查看
在这里插入图片描述

环境迁移

conda env export方法

导出当前环境:(此方法只能迁移所有conda安装的包)
conda env export > environment.yaml
报错:
CondaError: Expected exactly one `egg-info` directory in '/***/mmcv', via egg-link 'lib/python3.6/site-packages/mmcv.egg-link'. Instead found: ('mmcv.egg-info', 'mmcv_full.egg-info').  These are often left over from legacy operations that did not clean up correctly.  Please remove all but one of these.
# 创建环境
conda env create -f environment.yaml

pip freeze方法

conda create -n yournev  python=3.8
conda activate yourenv
# 报错Your shell has not been properly configured to use 'conda activate'.
# 报错解决
source activate 
# 如果报这个错就换一下:DeprecationWarning: 'source deactivate' is deprecated. Use 'conda deactivate'.
# 然后继续执行
conda activate yournev

pip freeze > yournevrequirements.txt
pip install -r yournevrequirements.txt

如果报错,参考https://blog.csdn.net/weixin_44786530/article/details/121452907使用命令:
cat requirements.txt | xargs -n 1 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/

absl-py==1.0.0
argon2-cffi @ file:///C:/ci/argon2-cffi_1613038019788/work
astor==0.8.1
astunparse==1.6.3
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
beautifulsoup4 @ file:///tmp/build/80754af9/beautifulsoup4_1631874778482/work
bleach @ file:///opt/conda/conda-bld/bleach_1641577558959/work
boto3==1.22.9
botocore==1.25.9
Bottleneck==1.3.2
cached-property==1.5.2
cachetools==5.0.0
certifi==2021.10.8
cffi @ file:///C:/ci_310/cffi_1642682485096/work
charset-normalizer==2.0.12
cloudpickle @ file:///tmp/build/80754af9/cloudpickle_1632508026186/work
colorama @ file:///tmp/build/80754af9/colorama_1607707115595/work
cycler==0.10.0
cytoolz==0.11.0
dask==2021.10.0
debugpy @ file:///C:/ci/debugpy_1637091911212/work
decorator @ file:///opt/conda/conda-bld/decorator_1643638310831/work
defusedxml @ file:///tmp/build/80754af9/defusedxml_1615228127516/work
Deprecated==1.2.13
eagerpy==0.30.0
efficientnet-pytorch==0.7.1
einops==0.4.1
entrypoints==0.3
fastjsonschema @ file:///tmp/build/80754af9/python-fastjsonschema_1620414857593/work/dist
filelock==3.6.0
flatbuffers==2.0
fonttools==4.25.0
foolbox==2.3.0
fsspec @ file:///opt/conda/conda-bld/fsspec_1642510437511/work
gast==0.2.2
gitdb==4.0.9
GitPython==3.1.27
google-auth==2.6.5
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.44.0
h5py==3.6.0
idna==3.3
imagecodecs @ file:///C:/ci/imagecodecs_1635529223557/work
imageio @ file:///tmp/build/80754af9/imageio_1617700267927/work
importlib-metadata @ file:///C:/ci/importlib-metadata_1648562631189/work
ipykernel @ file:///C:/ci/ipykernel_1647000985174/work/dist/ipykernel-6.9.1-py3-none-any.whl
ipython @ file:///C:/ci/ipython_1643800131373/work
ipython-genutils @ file:///tmp/build/80754af9/ipython_genutils_1606773439826/work
ipywidgets @ file:///tmp/build/80754af9/ipywidgets_1634143127070/work
jedi @ file:///C:/ci/jedi_1644297241925/work
Jinja2 @ file:///opt/conda/conda-bld/jinja2_1647436528585/work
jmespath==1.0.0
joblib @ file:///tmp/build/80754af9/joblib_1635411271373/work
jsonschema @ file:///Users/ktietz/demo/mc3/conda-bld/jsonschema_1630511932244/work
jupyter==1.0.0
jupyter-client @ file:///opt/conda/conda-bld/jupyter_client_1643638337975/work
jupyter-console @ file:///opt/conda/conda-bld/jupyter_console_1647002188872/work
jupyter-core @ file:///C:/ci/jupyter_core_1646976467633/work
jupyterlab-pygments @ file:///tmp/build/80754af9/jupyterlab_pygments_1601490720602/work
jupyterlab-widgets @ file:///tmp/build/80754af9/jupyterlab_widgets_1609884341231/work
keras==2.8.0
Keras-Applications==1.0.8
Keras-Preprocessing==1.1.2
kiwisolver @ file:///C:/ci/kiwisolver_1612282618948/work
libclang==14.0.1
locket==0.2.1
Markdown==3.3.6
MarkupSafe @ file:///C:/ci/markupsafe_1621528383308/work
matplotlib @ file:///C:/ci/matplotlib-suite_1634667159685/work
matplotlib-inline @ file:///tmp/build/80754af9/matplotlib-inline_1628242447089/work
MegEngine==1.9.0
megfile==0.1.2
mistune @ file:///C:/ci/mistune_1594373272338/work
mkl-fft==1.3.1
mkl-random @ file:///C:/ci/mkl_random_1626186163140/work
mkl-service==2.4.0
mprop==0.16.0
munkres==1.1.4
nbclient @ file:///tmp/build/80754af9/nbclient_1645431659072/work
nbconvert @ file:///C:/ci/nbconvert_1649759177374/work
nbformat @ file:///C:/ci/nbformat_1649845122517/work
nest-asyncio @ file:///C:/ci/nest-asyncio_1649848126026/work
networkx @ file:///tmp/build/80754af9/networkx_1633639043937/work
notebook @ file:///C:/ci/notebook_1645002740769/work
numexpr @ file:///C:/ci/numexpr_1640704420125/work
numpy==1.18.0
oauthlib==3.2.0
olefile==0.46
opencv-python==4.5.5.64
opt-einsum==3.3.0
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pandas @ file:///C:/ci/pandas_1641461312795/work
pandocfilters @ file:///opt/conda/conda-bld/pandocfilters_1643405455980/work
parso @ file:///opt/conda/conda-bld/parso_1641458642106/work
partd @ file:///tmp/build/80754af9/partd_1618000087440/work
pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work
Pillow==8.4.0
positional-encodings==5.0.0
prometheus-client @ file:///opt/conda/conda-bld/prometheus_client_1643788673601/work
prompt-toolkit @ file:///tmp/build/80754af9/prompt-toolkit_1633440160888/work
protobuf==3.19.1
pyarrow==8.0.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work
Pygments @ file:///opt/conda/conda-bld/pygments_1644249106324/work
pymanopt==0.2.5
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
PyQt5==5.15.4
pyqt5-plugins==5.15.4.2.2
pyqt5-tools==5.15.4.3.2
pyrsistent @ file:///C:/ci/pyrsistent_1636093257833/work
python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work
python-dotenv==0.19.2
pytz==2021.3
PyWavelets @ file:///C:/ci/pywavelets_1601658407053/work
pywin32==302
pywinpty @ file:///C:/ci_310/pywinpty_1644230983541/work/target/wheels/pywinpty-2.0.2-cp37-none-win_amd64.whl
PyYAML==6.0
pyzmq @ file:///C:/ci/pyzmq_1638435182681/work
qtconsole @ file:///opt/conda/conda-bld/qtconsole_1649078897110/work
QtPy @ file:///opt/conda/conda-bld/qtpy_1649073884068/work
requests==2.27.1
requests-oauthlib==1.3.1
rsa==4.8
s3transfer==0.5.2
scikit-image==0.18.3
scikit-learn @ file:///C:/ci/scikit-learn_1635187438800/work
scipy==1.7.2
seaborn @ file:///tmp/build/80754af9/seaborn_1629307859561/work
Send2Trash @ file:///tmp/build/80754af9/send2trash_1632406701022/work
six @ file:///tmp/build/80754af9/six_1623709665295/work
smart-open==6.0.0
smmap==5.0.0
soupsieve @ file:///tmp/build/80754af9/soupsieve_1636706018808/work
tabulate==0.8.9
tensorboard==1.15.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorboardX @ file:///tmp/build/80754af9/tensorboardx_1621440489103/work
tensorflow==1.15.0
tensorflow-estimator==1.15.1
tensorflow-io-gcs-filesystem==0.25.0
termcolor==1.1.0
terminado @ file:///C:/ci/terminado_1644322782754/work
testpath @ file:///tmp/build/80754af9/testpath_1624638946665/work
tf-estimator-nightly==2.8.0.dev2021122109
threadpoolctl @ file:///Users/ktietz/demo/mc3/conda-bld/threadpoolctl_1629802263681/work
tifffile @ file:///tmp/build/80754af9/tifffile_1627275862826/work
timm==0.5.4
toolz @ file:///tmp/build/80754af9/toolz_1636545406491/work
torch==1.10.0
torchaudio==0.10.0
torchinfo==1.6.5
torchvision==0.11.1
tornado @ file:///C:/ci/tornado_1606935947090/work
tqdm @ file:///tmp/build/80754af9/tqdm_1635330843403/work
traitlets @ file:///tmp/build/80754af9/traitlets_1636710298902/work
typing-extensions @ file:///tmp/build/80754af9/typing_extensions_1631814937681/work
urllib3==1.26.9
wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work
webencodings==0.5.1
Werkzeug==2.1.1
widgetsnbextension @ file:///C:/ci/widgetsnbextension_1645009553925/work
wincertstore==0.2
wrapt==1.14.1
zipp @ file:///opt/conda/conda-bld/zipp_1641824620731/work

环境迁移
迁移相关

报错内容:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

[将命令加入到~/.bashrc文件中,每次自动执行](https://blog.csdn.net/chenjadeli/article/details/122726378)

conda pack 方法

conda install -c conda-forge conda-pack

conda pack -n 环境名称 -o 环境名称.tar.gz

其他:jupyter安装与使用

注:可在jupyter启动环境
conda env list 
但是 conda activate env_name 可能不行
import os
os.system("conda activate env_name")可以执行
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值