包管理 pip ,conda;pycharm中使用conda 创建的虚拟环境

conda :

创建虚拟环境

直接创建

创建一个名字为 myenv 的虚拟环境【python 版本号是默认的版本号】

复制代码
conda create -n myenv 

默认python 版本可以使用下面的命令在配置文件中查看:

复制代码
conda config --show | grep default_python
指定python版本
复制代码
conda create -n myenv python=3.9
指定虚拟环境目录 -- (-p) 后面激活之后,终端中显示在路径前面的就是这个路径了
  • 注意 -n 和 -p 这两个参数不可以同时使用【互斥】

  • 如果说是在pycahrm 中,则给这个对应的文件夹添加到项目配置的解释器的位置,就可以直接在pycharm 中使用这个虚拟环境跑项目了:【如何在pycharm 中配置请看文章最后一个小结】

    conda create -p ./.venv python=3.9

激活虚拟环境

复制代码
conda activate ./.venv 

验证虚拟环境

  • 看看是不是自己安装的对应的py 版本

    python -V

安装包

直接安装包
复制代码
conda install tqdm
指定channel 安装包
复制代码
conda install tqdm  -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

补充几个 chaanel:

text 复制代码
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/
- https://mirrors.bfsu.edu.cn/anaconda/pkgs/free/
- https://mirrors.bfsu.edu.cn/anaconda/pkgs/main/
- https://mirrors.bfsu.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
- https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
- https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
- https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
- https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
- https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/

卸载包

复制代码
conda uninstall tqdm

查看包的版本号

查看使用 conda 下载的所有的包的版本号 --- 对应 pip list`

复制代码
conda list

查看使用 conda 下载的指定的包的版本号 (以 tqdm 为例) -- 对应 pip show tqdm

复制代码
conda list tqdm 

关闭虚拟环境

复制代码
conda deactivate

pip

直接在pycharm 中 创建项目的时候选择对应的python编译器即可

验证虚拟环境

  • 看看是不是自己安装的对应的py 版本

    python -V

安装包

直接安装包
复制代码
pip install tqdm
指定channel 安装包
复制代码
pip install tqdm  -i https://mirrors.aliyun.com/pypi/simple/

补充几个 pip 下载源:

text 复制代码
https://mirrors.aliyun.com/pypi/simple/
https://mirrors.tencent.com/pypi/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
https://pypi.mirrors.ustc.edu.cn/simple/
https://pypi.doubanio.com/simple/

卸载包

复制代码
pip uninstall tqdm

查看包的版本号

查看使用 pip 下载的所有的包的版本号

复制代码
pip list

查看使用 pip 下载的指定的包的版本号 (以 tqdm 为例)

复制代码
pip show tqdm 

在 PyCharm 中配置虚拟环境 -- conda 创建的虚拟环境

  1. 打开 PyCharm ==> 打开项目设置
    • 在 PyCharm 的菜单栏中,选择 File > Settings(Windows/Linux)或 PyCharm > Preferences(macOS)。
  2. 进入项目解释器设置
    • 在设置窗口中,选择 Project: <你的项目名称> > Python Interpreter
  3. 添加新的解释器
    • 点击右上角的齿轮图标,选择 Add Interpreter ==> Add Local Interpreter
  4. 选择 Conda 环境
    • 在弹出的窗口中进行如下选择:
    • Environment ===> Select existing
    • Type ===> conda
    • Path to conda 这个字段不变
    • Environment ===> 选中自己创建的虚拟环境的文件夹的路径 【比如上面的./.venv
    • 点击 OK 完成配置。
相关推荐
hui函数4 小时前
如何解决 pip install 编译报错 ‘cl.exe’ not found(缺少 VS C++ 工具集)问题
开发语言·c++·pip
hui函数6 小时前
Python系列Bug修复|如何解决 pip install 安装报错 invalid command ‘bdist_wheel’(缺少 wheel)问题
python·bug·pip
hui函数6 小时前
Python系列Bug修复|如何解决 pip install -r requirements.txt 私有索引未设为 trusted-host 导致拒绝 问题
python·bug·pip
hui函数7 小时前
Python系列Bug修复|如何解决 pip install 安装报错 Backend ‘setuptools.build_meta’ 不可用 问题
python·bug·pip
hui函数8 小时前
Python系列Bug修复|如何解决 pip install -r requirements.txt 私有仓库认证失败 401 Unauthorized 问题
python·bug·pip
hui函数8 小时前
Python系列Bug修复|如何解决 pip install -r requirements.txt 子目录可编辑安装缺少 pyproject.toml 问题
python·bug·pip
hui函数1 天前
如何解决 pip install 编译报错 g++: command not found(缺少 C++ 编译器)问题
开发语言·c++·pip
缘友一世1 天前
PyCharm连接autodl平台服务(python解释器&jupyter lab)
python·jupyter·pycharm
hui函数1 天前
Python系列Bug修复|如何解决 pip install -e . 安装报错 “后端不支持可编辑安装(PEP 660)” 问题
python·bug·pip
hui函数1 天前
如何解决 pip install 网络报错 403 Forbidden(访问被阻止)问题
网络·pip