惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
博客园_首页
T
Tailwind CSS Blog
美团技术团队
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog

博客园 - Hopesun

一个贴布产品(虎标镇痛贴布-RD(温感型)),新加坡企业生产 小初高中教材电子版本(PDF)下载地址 视频生成(开源框架、商业化产品) 股票软件及指标公式学习网站 anaconda 中安装的包用Pip升级高版本的方法 钉钉组件的属性分类设置 冬季皮肤干燥,洗澡用沐浴油、沐浴露 强力漱囗液~西吡氯铵含漱液 Qlib 学习资料收集1 DeepWiki vs. Zread 对决,AI 代码文档解析 有限免费使用的 AI 大模型,收集。 获取 AKshare 的数据,为 VectorBt、Pybroker等框架提供数据 Anaconda 安装后,手动安装 JupyterNotebook、JupyterLab Vscode 开发 Python 的一些基础设置 VectorBT Backtrader Zipline 比较 回测 —Zipline 已死?还是只需重启 Zipline-Reloaded? Backtesting – Is Zipline Dead? Or does it just need a reload? 时间序列预测与股票分析框架 prophet、NeuralProphet、FinRL等 Python可视化开发工具,类似VB、Delphi Hyper3d rodin AccuRIG AI 创作 3D Poly Haven 高质量 3D 资源的网站 PhET模拟实验----仿真程序(初等教育) https://jiucai.fun/ 一个人网站
python 安装目录、运行环境、venv与包管理、PyCharm配置、Ana...
Hopesun · 2025-04-11 · via 博客园 - Hopesun

一、python 运行环境、虚拟环境与包管理

1、Python 独立安装(不使用开发工具自动安装,如PyCharm、Anaconda)

      1)安装位置目录,设置于 环境变量Path” 中,方便命令行使用;

      2)安装内容解释:

            Scripts 目录: 一些执行文件,比如 pip.exe。可以用 pip 安装其它包管理工具,如 virtualenv.exe、uv.exe、poetry.exe。

            Lib 文件夹:通常包含的是 Python 标准库 和 一些第三方库的源代码。这些库在 Python 解释器运行时被加载和使用。

              Lib \site-packages 目录:  通过所属Python的 pip 安装的第三方库,存方的位置。如果虚拟环境激活,则安装在相应的虚拟环境对应目录下。

            libs 目录:主要包含的是与 Python 解释器自身运行相关的动态链接库(.lib 文件)。include目录:包含头文件(XXX.h)。 

            DLLs目录 :包含 .dll文件、.pyd 文件。tcl 目录:Tcl/Tk GUI 工具包。

      3)  可为Python 设置一个环境变量:“PYTHONPATH”。在所有环境(含虚拟)中都可用‌,用于指定额外的搜索路径,以便Python解释器可以找到要导入的模块和包。

      4)  pip 的包源设置:   使用  pip config --user [或--global] debug  进行查询 global(全局)/site(虚拟环境)/user(用户) 级配置文件 pip.ini 是否存在。

            首先检测一下pip 版本, pip -V ( 或 --version )  ,   然后升级一下:  pip install --upgrade (或-U) pip 

           一般手动设置一个用户级配置就OK了,位置  C:\Users\UserNameXXX\pip\pip.ini ,可用命令: pip config --user set xxx 进行设置,使用国内镜像时确保添加 trusted-host,避免 SSL 错误。     一般源设置为(清华,网上推荐):

           [global]
                index-url = https://pypi.tuna.tsinghua.edu.cn/simple                 //清华 , 已试过,比官方默认快很多!  官方网:https://mirrors.tuna.tsinghua.edu.cn/
                extra-index-url =
                        https://mirrors.aliyun.com/pypi/simple            //阿里?

           https://mirrors.cloud.tencent.com/pypi/simple

                trusted-host =

                      pypi.tuna.tsinghua.edu.cn

                      mirrors.aliyun.com

        mirrors.cloud.tencent.com

       腾讯云镜像源

  • index-url = https://mirrors.cloud.tencent.com/pypi/simple
    trusted-host = mirrors.cloud.tencent.com
  • 华为云镜像源

    index-url = https://mirrors.huaweicloud.com/repository/pypi/simple
    trusted-host = mirrors.huaweicloud.com

2、Anaconda 安装并创建 虚拟环境

     1)安装位置目录,可设置于 环境变量 Path 中,但官方不建议这样做; 安装目录 属于 base environment 。

     2)设置 虚拟环境目录 env_dirs这样可以保证在使用 Anaconda Navigator 创建 Anaconda虚拟环境时,直接放置在设置的位置。 

          默认另一个位置是:C:\Users\\UserNameXXX\.conda\envs,使用 conda info 命令可以查看到(envs directories)。

          当 PyCharm 用 Conda 选择虚拟环境时。建议!:不用 PyCharm 在 Anaconda 的 envs 中创建虚拟环境。

          A、修改User用户级 或Site级配置文件 .condarc,增加:

               envs_dirs:
                    - X:\XXXX\miniconda3安装目录\envs

           B、使用命令增加 :   conda config --add envs_dirs  X:\XXXX\Anaconda3\envs

     3) 使用 命令:conda info   检查是否安装、配置成功。

     4) C:\Users\UserNameXXX下的: .condarc 是conda 的用户级配置文件(user config file),配置下载包的源头,配置选项会覆盖conda的默认行为。

           anaconda 应用安装目录下也用一个(Site级,优先级最高) .condarc  (populated config files)。

           A、可用 conda config 命令配置,或直接修改。  

             示例 :  conda config --add channels  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

                           conda config --add channels  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/

            B、或者 通过 Anaconda Navigator 的  Channels 功能 Add...(增加)。用户级 channel 放后面。前面内容是Anaconda 安装目录下 .condarc的 channel 内容。

             主要配置选项如下:

            channels:

        - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
        - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
        - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
    show_channel_urls: true

            channel_priority:  strict (默认) 或 flexible 或 disabled

             envs_dirs:

                 - /path/to/envs

                 - /another/path/to/envs

             pkgs_dirs:                                默认为: 安装目录  X:\xxx\anaconda3\pkgs  或   C:\Users\UserNameXXX\.conda\pkgs 

                 - /path/to/pkgs

                 - /another/path/to/pkgs

3、uv、poetry 等 虚拟环境与包管理工具,建议!:直接安装在 特定 Python 安装下的 Scripts 目录,这必须用特定于 当前 Python 带的 pip 工具。

      如果不指定,通常安装于用户工作目录。

4、PyCharm配置

     1)PyCharm 安装中有一个选择项,Add launchers dir to the PATH,(PyCharm = X:\PyCharmXXXX\bin)方便在控制台中命令行启动。其实我们一般都是用 “桌面图标icon” 或启动菜单。

     2)关键是 Python Interpreter(解释器)配置,在 File\Settings\Project:XXXX 处设置。

          支持多种 虚拟环境创建工具:Uv、Poetry、Virtualenv、Pipenv、Conda。  本人仅考虑使用VirtualenvUv网上说最快)总产生格式不对的错误,Poetry 也没用对。

           在选择 Python Interpreter 的下拉框的最下面,有一个 Show All... 可以清理一些 历史记录