python虚拟环境应用

1、虚拟环境

1.1、基本概念

Venv:虚拟环境,是Python用来创建和管理虚拟环境的模块,该模块供你用来存放你的Python脚本以及安装各种Python第三方模块,模块里的环境和本机是完全分开的,

也就是说你在venv下通过pip安装的Python第三方模块是不会存在于你本机的环境下的。

1.2、作用

Python的虚拟环境可以使一个Python程序拥有独立的库library和解释器interpreter,而不用与其他Python程序共享统一个library和interpreter。

虚拟环境的好处是避免了不同Python程序间的互相影响(共同使用global library 和 interpreter)

2、pip+virtualenv

2.1、安装virtualenv

python 复制代码
pip install virtualenv

2.2、创建虚拟环境

1、命令行(cmd)进入当需要创建虚拟环境的目录下

2、创建虚拟环境env_demo

python 复制代码
virtualenv env_demo

创建虚拟环境env_demo指定目录

python 复制代码
virtualenv  D:\python_virtualenv\env_demo

2.3、激活虚拟环境

1、进入到当前创建虚拟目录的\env_demo\Scripts下

python 复制代码
cd  D:\python_virtualenv\langchaindemo
python 复制代码
cd Scripts

2、执行命令激活虚拟环境

python 复制代码
activate

Conda安装

创建新环境

python 复制代码
conda create -n env-tests python=3.10
conda activate env-test

列出所有环境

python 复制代码
#列出所有环境
conda env list

删除环境

python 复制代码
conda env remove -n your_env_name

PyCharm 设置虚拟环境

证明用的是虚拟环境

相关推荐
金銀銅鐵14 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup1119 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0021 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵1 天前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf1 天前
Agent 流程编排
后端·python·agent
copyer_xyf1 天前
Agent RAG
后端·python·agent
copyer_xyf1 天前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf1 天前
Agent 记忆管理
后端·python·agent
星云穿梭2 天前
用Python写一个带图形界面的学生管理系统——完整教程
python