conda 设置python运行 虚拟环境

本文介绍了如何使用conda创建、切换和管理Python虚拟环境,包括安装特定版本的Python、安装包、生成环境依赖文件、激活与停用环境、复制环境、删除环境,以及在Jupyter Notebook中使用本地虚拟环境的方法。同时,提到了处理环境中遇到的模块导入错误和安装特定包的技巧。
部署运行你感兴趣的模型镜像

删除 ENV 目录下的 python 环境

rm -rf ENV

创建新 python 环境 在 目录 ENV下

conda create -p ENV python=3.6

在ENV 目录 环境下安装 指定软件

./ENV/bin/pip install numpy

查找python 项目依赖并生成到 requirements.txt
./ENV/bin/pip freeze >requirements.txt

conda 设置虚拟环境
在机器上可以设置多套 虚拟 python 运行环境,在不同的运行环境安装不同版本,或者不同的依赖包。

查看已经创建好的环境

conda info --envs

创建虚拟环境

conda create --name bf-predict-env python=3.6.3

复制虚拟环境

conda create -n snows --clone env

切换新环境

切换到新环境

linux/Mac下需要使用

source activate env_name
source full/path/to/env

Windows 下需要使用

activate env_name
#退出环境,也可以使用activate root切回root环境
deactivate env_name

Note:这步很关键,清华镜像上默认的pystan=2.14.0.0, 安装上去,调用 fit 的时候回报错,需要更新到最新版本

conda create --name bf-predict-env pystan=2.18.0.0

选定环境

source activate bf-predict-env

在当前选定的环境上安装包

source activate bf-predict-env
conda install --name bf-predict-env fbprophet

停用环境

source deactivate

删除 环境

conda remove --name bf-predict-env --all

查看安装的包

conda list

如何在 notebook 上激活本地虚拟环境,部署完成后可以选择本地的虚拟环境conda

首先激活对应的conda环境

source activate bf-predict-env

安装 ipykernel

conda install --name bf-predict-env ipykernel

将环境写入notebook的kernel中

(bf-predict-env) localhost:prophet-master user$ python -m ipykernel install --user --name bf-predict-env --display-name ‘Python bf-predict-env’

上述操作完成后会报错, ImportError: No Module Named ‘pysqlite2’,执行

conda install --name bf-predict-env sqlite
conda install --name bf-predict-env python=3.6

启动notebook 即可

jupyter notebook

localhost 未发送任何数据。

断开网络加速,不能翻墙,否则浏览器页面会报此错误

install fastai (包含 pytorch)

conda install -c pytorch -c fastai fastai pytorch

在conda 环境,可以切换成 pip 安装源码包,

pip install -e .

安装sklearn

conda install scikit-learn

安装 bert-serving 服务
https://pypi.org/project/bert-serving-server/

conda install tensorflow
pip install bert-serving-server # server
pip install bert-serving-client # client, independent of bert-serving-server

启动 jupyter notebook 时报错, ImportError: cannot import name ‘ensure_dir_exists’. You need to update jupyter_core, and jupyter_client

conda update jupyter_core jupyter_client

To install tensorflow-hub package with conda run one of the following:

conda install -c conda-forge tensorflow-hub
conda install -c conda-forge/label/gcc7 tensorflow-hub
conda install -c conda-forge/label/cf201901 tensorflow-hub

在 notebook 中安装 包,报错 PermissionError, 后面加 --user jupyter
pip install --user jupyter works like a charm. Thanks.

!pip install bert-tensorflow --user jupyter

您可能感兴趣的与本文相关的镜像

Python3.8

Python3.8

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值