python conda创建虚拟环境报错SpecNotFound: Invalid name, try the format: user/package

介绍

环境版本

os: macos
python:3.6
conda:4.8.3

官网文档

$ conda env create -h
usage: conda-env create [-h] [-f FILE] [-n ENVIRONMENT | -p PATH] [-C] [-k]
[–offline] [–force] [–json] [-v] [-q]
[remote_definition]
Create an environment based on an environment file
Options:
positional arguments:
remote_definition remote environment definition / IPython notebook
optional arguments:
-h, --help Show this help message and exit.
-f FILE, --file FILE environment definition file (default: environment.yml)
–force force creation of environment (removing a previously
existing environment of the same name).
Target Environment Specification:
-n ENVIRONMENT, --name ENVIRONMENT
Name of environment.
-p PATH, --prefix PATH
Full path to environment location (i.e. prefix).
Networking Options:
-C, --use-index-cache
Use cache of channel index files, even if it has
expired.
-k, --insecure Allow conda to perform “insecure” SSL connections and
transfers. Equivalent to setting ‘ssl_verify’ to
‘false’.
–offline Offline mode. Don’t connect to the Internet.
Output, Prompt, and Flow Control Options:
–json Report all output as json. Suitable for using conda
programmatically.
-v, --verbose Use once for info, twice for debug, three times for
trace.
-q, --quiet Do not display progress bar.
examples:
conda env create
conda env create -n name
conda env create vader/deathstar
conda env create -f=/path/to/environment.yml
conda env create -f=/path/to/requirements.txt -n deathstar
conda env create -f=/path/to/requirements.txt -p /home/user/software/deathstar

问题介绍

python使用conda创建虚拟环境时报错SpecNotFound: Invalid name, try the format: user/package,详细如下:

$ conda env create -n deepleran
SpecNotFound: Invalid name, try the format: user/package

报此错误,通常是由于新版的conda在创建虚拟环境时,需要指定environment.yaml或requirements.txt,在未指定的情况下会在当前目录下找着2个文件,若无,则会报错。
要解决此问题,可在当前目录下创建environment.yaml和requirements.txt。

解决方案

通过实现指定克隆版本,创建environment.yaml,requirements.txt来创建虚拟环境:

方案一、通过environment.yaml创建虚拟环境

配置environment.yaml文件

name: deepleran
channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
dependencies:
  - pip==20.0.2

python使用conda指定environment.yaml创建虚拟环境

# 列出虚拟环境清单
conda env list

# 创建虚拟环境
conda-env create -f=environment.yaml python==3.7

# 列出虚拟环境清单
conda env list

# 克隆虚拟环境配置
conda env export > environment.yaml

# 导出软件版本号
pip freeze > requirements.txt

# 退出虚拟环境
conda deactivate

## 删除虚拟环境
#conda env remove -n deepleran

tips:若不想安装任何软件,则做一个只包含name的environment.yaml文件即可。

方案二、创建requirements.txt文件创建虚拟环境

创建requirements.txt文件

pip==10.0.1
numpy==1.15.4
pandas==0.23.4
matplotlib==2.2.3

python使用cona创建虚拟环境

# 列出虚拟环境清单
conda env list

# 创建虚拟环境
conda env create -f=requirements.txt -n deepleran  python==3.7

# 列出虚拟环境清单
conda env list

# 进入虚拟环境 或者 conda activate deepleran
source activate deepleran

# 退出虚拟环境
conda deactivate

## 删除虚拟环境
# conda env remove -n deepleran


tips:若不想安装任何软件,则做一个空的requirements.txt文件即可。

祝大家愉快的玩耍python,有任何问题,欢迎随时在评论区留言。

猜你喜欢

转载自blog.csdn.net/myhes/article/details/106591618
今日推荐