工欲善其事,必先利其器
Python 是一种解释型高级编程语言,由 Guido van Rossum 于 1991 年发布。它以简洁的语法、强大的功能库和跨平台特性著称,广泛应用于 Web 开发、数据分析、人工智能、自动化脚本等领域。
PyCharm 是由 JetBrains 公司开发的 Python 集成开发环境(IDE),专为 Python 语言设计,支持代码编写、调试、项目管理、版本控制等功能,适用于专业开发者和初学者。其核心目标是提升 Python 开发效率,尤其适合 Web 开发、数据分析、机器学习等领域。
Anaconda 是一个开源的 Python 科学计算发行版,专为数据科学、机器学习及大规模数据处理设计,集成了 Python 解释器、包管理器(Conda)以及 180+ 预装科学计算库(如 NumPy、Pandas、Matplotlib 等),支持 Windows、Linux、macOS 系统。在数据分析中,你会用的很多数据包,Anaconda可以很好地帮助你在计算机上管理这些包,包括安装、更新和卸载包。另外,作为环境管理器,Anaconda还可以为不同版本的Python提供合适的工作环境,避免因为不同的项目要求使用不同版本的Pyhon而导致混乱和错误。
Jupyter Notebook 是一个基于 Web 的 交互式编程工具,它有一个 Python 所没有的功能,能让用户将说明文本、数学方程、代码和可视化内容全部组合嵌入到一个易于分享的文档中,支持编写代码、实时运行、展示可视化结果。其名称源自 Julia + Python + R,最初专注于科学计算,现已支持 40+ 编程语言(如 Python、R、Scala)。没有Jupyter notebook 之前,人们只能来回将代码粘贴到文档中,在文档中进行说明,很繁琐也很容易出错。
Python、Anaconda、Pycharm的正确使用姿势
大部分人学习Python的过程,可能都是先安装的Python,之后学了一段时间开始的Anaconda。(安装Python的过程就不详述了,因为后边安装的Anaconda包含Python,安装了Anaconda就不用单独安装Python了。)
刚接触学习Python,本机仅安装Python
仅安装Python后,cmd的运行效果如下,
安装Python后,需配置python.exe所在的路径和同级目录scripts到环境变量。
开始使用Anaconda
为什么要用Anaconda
1. 管理多版本的Python环境,对不同的项目选用不同的环境,把开发好的程序所需要的环境(就是第三方包)独立的打包起来,这样再在另一台电脑上跑该程序时就不用再单独下载包了。
2. 科学计算一般都是探索性的学习,即每执行一步看一下结果,这样用Jupyter Notebook显然更方便。此外处理大量数据、一些运算类型等等也是更占优势。
3. 要学Numpy、Pandas、Matplotlib等的科学计算库,当然这些东西Python一样可以运行。你可以在终端中输入pip install numpy直接用,或者用PyCharm打开个文件,里面写上import numpy,它会飘红,因为你没下载过,你鼠标放上去提示你pip下载你点击后一样会自动下载,然后就能用了。(pip下载的东西都在~\python_dir\Lib\site-packages里)
Python和Anaconda比较
Python | Anaconda | |
包管理工具 | Python在安装之后会默认的自带一个包管理工具pip,可以使用它去下载安装Python的第三方库。 | Anaconda自带的包管理功能是conda,除了可以去下载安装包之外还可以去更新和升级指定版本的包,而且Anaconda上还可以使用pip。 |
默认环境 | Python在安装之后会默认的自带一个命令行环境叫做python.exe,在这个环境里面可以去执行Python的代码。 | Anaconda安装后会有一个Anaconda prompt的程序,这个程序打开之后会进入一个类似于命令行的界面,但是它只能执行conda包管理工具的命令。 |
自带的库 | Python在安装之后除了标准库之外不会有任何一个第三方库会下载安装好,想要使用它则需要自己去手动的通过命令或者是压缩包的形式去安装。 | Anaconda则自带了大约180个左右numpy、matplotlib、scipy、scikit-learn这种用来进行科学计算的包,在包管理方面效率较高。 |
默认编辑器 | Python安装之后的默认编辑器是IDLE,一个可以用来创建Python文件并且编写执行Python代码的编辑器。 | Anaconda默认的编辑器则是Jupyter notebook,一个基于浏览器去运行的编辑器。 |
Anaconda Navigtor | 用于管理工具包和环境的图形用户界面,后续涉及的众多管理命令也可以在 Navigator 中手工实现。 |
Jupyter notebook | 基于web的交互式计算环境,可以编辑易于人们阅读的文档,用于展示数据分析的过程。 |
qtconsole | 一个可执行 IPython 的仿终端图形界面程序,相比 Python Shell 界面,qtconsole 可以直接显示代码生成的图形,实现多行代码输入执行,以及内置许多有用的功能和函数。 |
spyder | 一个使用Python语言、跨平台的、科学运算集成开发环境。 |
下载、安装Anaconda3(Windows)
当下载安装Anaconda时放心安装,虽然Anaconda里一样有python,但都没关系。但不要轻易尝试把你以前安装用过的Python添加到Anaconda你新创建的环境!!!没什么意义也不差那点内存。
官方下载地址:Download Now | Anaconda
安装完成后,打开Anaconda Navigator,
运行cmd -> conda,发现识别不了,说明需要配置环境变量。
添加Anaconda到环境变量中
在下载安装Anaconda时,也会配置环境变量,这个随便,如果你配置的在你之前配置的Python下面,那么你cmd使用的时候会和以前一样,虽然有两个Python,但是它会从上到下寻找,找到第一个就行了。
PS C:\Users\xxx> python --version
Python 3.13.2
说明,
D:\tools\anaconda3(主目录)
D:\tools\anaconda3\Scripts(scripts目录)
D:\tools\anaconda3\Library(链接库目录)
如果你使用的是Anaconda Prompt,那么它已经自动配置了conda的环境变量,无需进行上述步骤也可以在Anaconda Prompt中使用conda命令。但是,如果希望在普通的命令提示符或PowerShell窗口中使用conda命令,那么就需要按照上述步骤将conda添加到PATH环境变量中。
如果已经打开了命令提示符窗口,需要关闭并重新打开它,以便新的环境变量设置生效。
查看、启动conda环境管理列表
PS C:\Users\xxx> conda env list
# conda environments:
#
base D:\tools\anaconda3
PS C:\Users\xxx> conda activate base
CondaError: Run 'conda init' before 'conda activate'
启动报错,先初始化
执行 conda init 初始化环境,将 conda 的启动脚本添加到系统 Shell(如 PowerShell、CMD、bash)的配置文件中,确保每次打开终端时自动启动 conda 环境变量。
PS C:\Users\xxx> conda init
no change D:\tools\anaconda3\Scripts\conda.exe
no change D:\tools\anaconda3\Scripts\conda-env.exe
no change D:\tools\anaconda3\Scripts\conda-script.py
no change D:\tools\anaconda3\Scripts\conda-env-script.py
no change D:\tools\anaconda3\condabin\conda.bat
no change D:\tools\anaconda3\Library\bin\conda.bat
no change D:\tools\anaconda3\condabin\_conda_activate.bat
no change D:\tools\anaconda3\condabin\rename_tmp.bat
no change D:\tools\anaconda3\condabin\conda_auto_activate.bat
no change D:\tools\anaconda3\condabin\conda_hook.bat
no change D:\tools\anaconda3\Scripts\activate.bat
no change D:\tools\anaconda3\condabin\activate.bat
no change D:\tools\anaconda3\condabin\deactivate.bat
modified D:\tools\anaconda3\Scripts\activate
modified D:\tools\anaconda3\Scripts\deactivate
modified D:\tools\anaconda3\etc\profile.d\conda.sh
modified D:\tools\anaconda3\etc\fish\conf.d\conda.fish
no change D:\tools\anaconda3\shell\condabin\Conda.psm1
modified D:\tools\anaconda3\shell\condabin\conda-hook.ps1
no change D:\tools\anaconda3\Lib\site-packages\xontrib\conda.xsh
modified D:\tools\anaconda3\etc\profile.d\conda.csh
modified C:\Users\xxx\Documents\WindowsPowerShell\profile.ps1
modified HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
==> For changes to take effect, close and re-open your current shell. <==
cmd正常启动
问题现象
执行conda init后,启动PowerShell报错
Windows PowerShell 版权所有 (C) Microsoft Corporation。保留所有权利。 尝试新的跨平台 PowerShell https://aka.ms/pscore6 . : 无法加载文件 C:\Users\xxx\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息 ,请参阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。 所在位置 行:1 字符: 3 + . 'C:\Users\xxx\Documents\WindowsPowerShell\profile.ps1' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [],PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess PS C:\Users\xxx> conda activate base CondaError: Run 'conda init' before 'conda activate'
问题原因
此错误由 PowerShell 执行策略限制导致。Windows 默认执行策略为
Restricted
(禁止运行任何脚本),阻止加载用户配置文件(如profile.ps1
),以防止恶意脚本执行。解决方案
1. 以管理员身份运行 PowerShell
右键点击 PowerShell 图标 → 选择 “以管理员身份运行”,获取权限13。
2. 修改执行策略
在管理员 PowerShell 中输入以下命令,将执行策略调整为允许本地脚本运行,
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
- RemoteSigned:允许运行本地脚本和受信任的远程脚本(推荐安全策略)13。
- -Scope CurrentUser:仅对当前用户生效,避免全局修改风险8。
输入命令后按
Y
确认更改。3. 验证配置
重新打开 PowerShell,输入以下命令检查策略是否生效:
Get-ExecutionPolicy
若输出
RemoteSigned
或Unrestricted
,表示配置成功。
补充说明
安全风险提示:
Unrestricted
策略允许运行所有脚本,存在安全隐患,建议优先选择RemoteSigned
。- 若需恢复默认策略,执行
Set-ExecutionPolicy Restricted
。文件路径检查:
- 确保
C:\Users\xxx\Documents\WindowsPowerShell\profile.ps1
文件存在且命名正确。
其他场景适配
- PyCharm 终端报错:若在 PyCharm 终端遇到此问题,可通过 File → Settings → Tools → Terminal,将默认终端改为
cmd
临时规避。
通过上述操作可解除脚本执行限制,同时兼顾系统安全性。
重启PowerShell后,错误问题消失
更换国内源
新建conda环境,速度比较慢,可以在.condarc中用镜像地址替换(.condarc全局设置一般位于C:\Users\xxx下,若在特定虚拟环境中操作,会有环境独立配置,环境独立配置可能会覆盖全局设置),打开看下里边内容,
channels:
- defaults
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r
- https://repo.anaconda.com/pkgs/msys2
或者运行下面命令查看,
# 查看当前配置的镜像源
> conda config --show channels
channels:
- defaults
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r
- https://repo.anaconda.com/pkgs/msys2
# 如果不是默认的,需要执行下面命令恢复默认
> conda config --remove-key channels
执行以下命令查看实际生效的配置路径(包括全局配置、环境独立配置),
(base) PS C:\Users\xxx> conda config --show-sources
==> D:\tools\anaconda3\.condarc <==
channels:
- defaults
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r
- https://repo.anaconda.com/pkgs/msys2
==> C:\Users\xxx\.condarc <==
channels:
- defaults
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r
- https://repo.anaconda.com/pkgs/msys2
==> envvars <==
allow_softlinks: False
执行下面命令,或者直接修改.condarc,添加清华大学镜像源,
> conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
> conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
> conda config --add channels http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
> conda config --set show_channel_urls yes
看最后.condarc配置如下,
channels:
- defaults
show_channel_urls: true
envs_dir: # 转换新创建环境的磁盘空间
- D:\CacheData\anacode\envs
pkgs_dir: # 转换新创建环境的磁盘空间
- D:\CacheData\anacode\pkgs
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai
- 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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
再查看实际生效的配置路径,发现已经变成了国内源了,
(base) PS C:\Users\xxx> conda config --show-sources
==> D:\tools\anaconda3\.condarc <==
channels:
- defaults
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai
- 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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
show_channel_urls: True
==> C:\Users\xxx\.condarc <==
channels:
- defaults
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai
- 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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
show_channel_urls: True
==> envvars <==
allow_softlinks: False
替换完国内镜像源后,再创建管理新环境,会比较快,可以试下,
切换新环境
使用cmd命令,或者图形界面切换环境,
(base) PS C:\Users\xxx> conda env list
# conda environments:
#
python310 C:\Users\xxx\.conda\envs\python310
python311 C:\Users\xxx\.conda\envs\python311
base * D:\tools\anaconda3
(base) PS C:\Users\xxx> conda activate python310
(python310) PS C:\Users\xxx> python --version
Python 3.10.16
创建一个新环境,在新环境中安装包,安装jupyter
不想创建新环境,也可以直接使用默认的环境,点击直接打开jupyter notebook。
创建新环境jupyterenv
(base) PS C:\Users\xxx> conda create --name jupyterenv
(base) PS C:\Users\xxx> conda activate jupyterenv
(jupyterenv) PS C:\Users\xxx> conda install numpy
(jupyterenv) PS C:\Users\xxx> conda list
# 等待jupyter安装完成
(jupyterenv) PS C:\Users\xxx> conda install jupyter
在jupyterenv环境下查看使用的镜像源,
(base) PS C:\Users\xxx> conda config --show-sources
==> D:\tools\anaconda3\.condarc <==
channels:
- defaults
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai
- 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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
show_channel_urls: True
==> C:\Users\xxx\.condarc <==
channels:
- defaults
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai
- 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/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
show_channel_urls: True
==> envvars <==
allow_softlinks: False
jupyter安装完成后,直接在本机jupyterenv环境下启动
(jupyterenv) PS C:\Users\xxx> jupyter notebook
[W 2025-03-25 11:06:16.038 ServerApp] A `_jupyter_server_extension_points` function was not found in jupyter_lsp. Instead, a `_jupyter_server_extension_paths` function was found and will be used for now. This function name will be deprecated in future releases of Jupyter Server.
[I 2025-03-25 11:06:16.149 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2025-03-25 11:06:16.154 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2025-03-25 11:06:16.160 ServerApp] jupyterlab | extension was successfully linked.
[I 2025-03-25 11:06:16.164 ServerApp] notebook | extension was successfully linked.
[I 2025-03-25 11:06:16.427 ServerApp] notebook_shim | extension was successfully linked.
[I 2025-03-25 11:06:16.463 ServerApp] notebook_shim | extension was successfully loaded.
[I 2025-03-25 11:06:16.465 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2025-03-25 11:06:16.465 ServerApp] jupyter_server_terminals | extension was successfully loaded.
[I 2025-03-25 11:06:16.468 LabApp] JupyterLab extension loaded from C:\Users\shouyuanman\.conda\envs\jupyterenv\Lib\site-packages\jupyterlab
[I 2025-03-25 11:06:16.468 LabApp] JupyterLab application directory is C:\Users\shouyuanman\.conda\envs\jupyterenv\share\jupyter\lab
[I 2025-03-25 11:06:16.469 LabApp] Extension Manager is 'pypi'.
[I 2025-03-25 11:06:16.738 ServerApp] jupyterlab | extension was successfully loaded.
[I 2025-03-25 11:06:16.744 ServerApp] notebook | extension was successfully loaded.
[I 2025-03-25 11:06:16.744 ServerApp] Serving notebooks from local directory: C:\Users\shouyuanman
[I 2025-03-25 11:06:16.745 ServerApp] Jupyter Server 2.15.0 is running at:
[I 2025-03-25 11:06:16.745 ServerApp] http://localhost:8888/tree?token=bfeeee2cf1f9a8d3d2812386abe18c9d60b3013317df58d9
[I 2025-03-25 11:06:16.745 ServerApp] http://127.0.0.1:8888/tree?token=bfeeee2cf1f9a8d3d2812386abe18c9d60b3013317df58d9
[I 2025-03-25 11:06:16.745 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 2025-03-25 11:06:16.809 ServerApp]
To access the server, open this file in a browser:
file:///C:/Users/xxx/AppData/Roaming/jupyter/runtime/jpserver-18556-open.html
Or copy and paste one of these URLs:
http://localhost:8888/tree?token=bfeeee2cf1f9a8d3d2812386abe18c9d60b3013317df58d9
http://127.0.0.1:8888/tree?token=bfeeee2cf1f9a8d3d2812386abe18c9d60b3013317df58d9
[I 2025-03-25 11:06:16.997 ServerApp] Skipped non-installed server(s): bash-language-server, dockerfile-language-server-nodejs, javascript-typescript-langserver, jedi-language-server, julia-language-server, pyright, python-language-server, python-lsp-server, r-languageserver, sql-language-server, texlab, typescript-language-server, unified-language-server, vscode-css-languageserver-bin, vscode-html-languageserver-bin, vscode-json-languageserver-bin, yaml-language-server
使用Jupyter,先试着新建一个Notebook,
输入一段Python,比如输出打印Hello World,运行看下效果,
Python和Anaconda先后安装问题
如果换个顺序(建议一组一组的动),比如D:\tools\anaconda3在上面,那它就会执行D:\tools\anaconda3里的Python,告诉你是Anaconda环境下的。
可以看到,直接cmd下运行Python,使用的事Anaconda下的版本,
注意,两个环境的Python,比如你以前用到requests模块下载过requests,它会在Python下载的site-package里,而使用Anaconda的话还要再去下载,虽然它下载时自带了一些工具,但没有requests,这两个是分开的。
哪怕把以前下载的python删了也没问题,打开以前写的PyCharm项目时,无非就是把设置里的Python(已经删掉了)换成Anaconda里的Python就行,有些东西比如一些库没下载,重新下载就可以了。这里Python和Anaconda两个都留着了,因为懒得弄也懒得合并,也不差那点内存。
Anaconda也有自己的命令conda,可以找到conda.exe文件,
C:\Users\xxx>conda --version conda 24.11.3 C:\Users\xxx>pip --version pip 24.2 from D:\tools\anaconda3\Lib\site-packages\pip (python 3.12)
这里,Anaconda的Python在上面,所以pip的路径来自于Python3.12,conda也是环境变量下面的Anaconda。Anaconda下载东西,可以直接在Anaconda环境下的Python(要启动)或是Anaconda Prompt用pip install xx,或者直接使用conda install xx即可,它两种命令都能用。
要点1:【要么所有的包通过使用conda安装,要么都使用PIP安装】
使用conda和pip时,最好保持一致性,以避免潜在的依赖性问题。如果你使用conda创建了一个环境,那么最好在该环境中使用conda来安装所有的包。同样地,如果你使用pip来安装了一个包,那么最好继续使用pip来安装该包的依赖项。
要点2:【本地安装Anaconda,考虑各个包的依赖性问题,建议使用conda安装包】
结论:【只使用conda安装包】为了后期不必要的麻烦,包的莫名其妙依赖性问题,不要用pip安装包。后期出现各个包依赖性问题时,耗费的时间和精力,特别是为了解决这种包依赖性的“低级问题”,折腾一天下来人非常颓丧。
PyCharm整合Anaconda
PyCharm
跑Python程序需要有解释器和编辑器。解释器就是Python2或Python3的python.exe,将编写的Python代码编译成机器代码。编辑器就是写代码的环境,比如PyCharm或者VSCode。
为什么我们下载安装Python,配置环境变量后,再去安装PyCharm,一点关系也没有,即不配置环境变量、以后配置也可以,并不影响你PyCharm使用。多数教程配置环境变量,仅是为了告诉你安装成功和方便以后使用,因为他们执行了 xx --version。而在你新建PyCharm项目或者文件时,因为它需要编译器,它会自动匹配上你下载的Python,所以你能print("Hello World") 成功。
下载、安装PyCharm(Windows)
官网地址:Download PyCharm: The Python IDE for data science and web development by JetBrains
整合Anaconda
conda路径如果在C盘会默认加载,其他盘上需要自行选择,
默认使用conda base环境,
如果不想用base,可以自行添加本地解释器,
看到选择的解释器版本被添加进来了,
运行查看效果
附录
pip命令使用汇总
pip一般跟着python一起安装了
官网:https://pypi.org/project/pip
pip --version
python -m ensurepip --upgrade
pip list
pip show panda
pip search panda
pip freeze
pip install -r requirements.txt
pip install my_math_package[numpy,scipy]
pip wheel package_name
pip cache purge
pip install package_name==version_number
pip install --find-links=URL package_name
conda命令使用汇总
要点:
anaconda安装后,需要配置环境变量
conda info
conda env list
python --version
conda init
conda activate base
python --version
新建conda环境,速度比较慢,可以在.condarc中用镜像地址替换
切换环境
conda activate python310创建环境:
conda create --name myenv
: 创建一个名为 myenv 的新环境。conda create --name myenv python=3.8
: 创建一个带有指定 Python 版本的环境。conda create --name myenv numpy pandas
: 创建一个包含指定软件包的环境。管理环境:
conda activate myenv
: 启动名为 myenv 的环境。conda deactivate
: 停用当前环境。conda env list
: 列出所有可用环境。
-conda env remove --name myenv
: 删除名为 myenv 的环境。安装/卸载软件包:
conda install numpy
: 安装 numpy 包。conda install numpy=1.19.2
: 安装指定版本的 numpy 包。conda install --file requirements.txt
: 从 requirements.txt 文件中安装所有指定的软件包。conda remove numpy
: 卸载 numpy 包。更新软件包:
conda update numpy
: 更新 numpy 包到最新版本。- conda update --all: 更新所有已安装的软件包到最新版本。
搜索软件包:
conda search numpy
: 搜索可用的 numpy 版本。conda search "*search_term*"
: 在 Conda 存储库中搜索指定的软件包。清理:
conda clean --all
: 清理不再需要的临时文件和缓存。参考conda官方文档
https://docs.conda.io/projects/conda/en/latest/commands/init.html