[Python] Python 环境管理工具 Conda - Python 2 和 Python 3 环境切换

68 0
Honkers 昨天 23:25 来自手机 | 显示全部楼层 |阅读模式

Conda
https://conda.io/en/latest/
https://docs.conda.io/projects/conda/en/latest/index.html

Command reference
https://conda.io/projects/conda/en/latest/commands.html

Anaconda Documentation
https://docs.anaconda.com/

Conda 是一个开源的软件包管理系统和环境管理系统,用于安装多个版本的软件包及其依赖关系,并在它们之间轻松切换。

Package, dependency and environment management for any language - Python, R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN, and more.
Conda 是为 Python 程序创建的,适用于 Windows, macOS, Linux and z/OS,也可以打包和分发其他软件。

Conda is an open source package management system and environment management system that runs on Windows, macOS, Linux and z/OS. Conda quickly installs, runs and updates packages and their dependencies. Conda easily creates, saves, loads and switches between environments on your local computer. It was created for Python programs, but it can package and distribute software for any language.

Conda as a package manager helps you find and install packages. If you need a package that requires a different version of Python, you do not need to switch to a different environment manager, because conda is also an environment manager. With just a few commands, you can set up a totally separate environment to run that different version of Python, while continuing to run your usual version of Python in your normal environment.
Conda 作为软件包管理器可以帮助您查找和安装软件包。如果您需要一个需要使用其他版本的 Python 的软件包,则无需切换到其他环境管理器,因为 conda 也是环境管理器。仅需几个命令,您就可以设置一个完全独立的环境来运行该不同版本的 Python,同时继续在正常环境中运行您通常的 Python 版本。

The conda package and environment manager is included in all versions of Anaconda and Miniconda.
所有版本的 Anaconda 和 Miniconda 中都包含 conda 软件包和环境管理器。

1. Switching between Python 2 and Python 3 environments (在 Python 2 和 Python 3 环境之间切换)

You can easily maintain separate environments for Python 2 programs and Python 3 programs on the same computer, without worrying about the programs interacting with each other. Switching to an environment is called activating it.
您可以轻松地在同一台计算机上为 Python 2 程序和 Python 3 程序维护单独的环境,而不必担心程序相互交互。

  1. Create a Python 2 environment named py27, install Python 2.7:
  1. conda create --name py27 python=2.7
复制代码
  1. Create a new environment named py35, install Python 3.5:
  1. conda create --name py35 python=3.5
复制代码

Now you have two environments with which to work. You can install packages and run programs as desired in either one.

  1. Activate and use the Python 2 environment.

Windows:

  1. activate py27
复制代码

macOS, Linux:

  1. conda activate py27
复制代码
  1. Deactivate the Python 2 environment. Use your py27 environment to install packages and run programs as desired. When finished, deactivate the environment.

Windows:

  1. deactivate
复制代码

macOS, Linux:

  1. conda deactivate
复制代码
  1. Activate and use the Python 3 environment.

Windows:

  1. activate py35
复制代码

macOS, Linux:

  1. conda activate py35
复制代码

Use the py35 environment to install and run programs as desired. When finished, deactivate the environment

  1. Deactivate the Python 3 environment.

Windows:

  1. deactivate
复制代码

macOS, Linux:

  1. conda deactivate
复制代码

References

[1] Yongqiang Cheng (程永强), https://yongqiang.blog.csdn.net/
[2] Python 环境管理工具 Conda - Python 2 和 Python 3 环境切换, https://mp.weixin.qq.com/s/z5Km2pA9iHEVQyx_SQ8kFw

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行天