anaconda 常用指令


管理包

它是一个类似pip的包管理器:

  • 但是更偏向于data science
  • 而且它不像pip那样只能安装python包, conda is not Python specific like pip is, it can also install non-Python packages. It is a package manager for any software stack. That being said, not all Python libraries are available from the Anaconda distribution and conda.

安装包

# multi packages
conda install numpy pandas scipy matplotlib
conda install jupyter notebook
conda install -c menpo opencv
conda install --channel https://conda.anaconda.org/menpo opencv3
#anaconda show menpo/opencv3
#This was the output:
#To install this package with conda run:
     conda install --channel https://conda.anaconda.org/menpo opencv3
conda install Pillow


# specify version
conda install numpy=1.10

Conda also automatically installs dependencies for you. For example scipy depends on numpy, it uses and requires numpy. If you install just scipy (conda install scipy), Conda will also install numpy if it isn’t already installed.

卸载包

To uninstall, use
conda remove package_name.

更新包

To update a package conda update package_name. If you want to update all packages in an environment, which is often useful, use conda update --all

查找包

searching with conda search search_term

list installed packagesconda list

管理环境

Along with managing packages, Conda is also a virtual environment manager.

Environments allow you to separate and isolate the packages you are using for different projects.

You can also export the list of packages in an environment to a file, then include that file with your code. This allows other people to easily load all the dependencies for your code. Pip has similar functionality with pip freeze > requirements.txt.

创建环境

#create an environment with a specific Python version, 
#These commands will install the most recent version of Python 3 and 2
conda create -n py3 python=3
conda create -n py2 python=2

#To install a specific version, use 
conda create -n py python=3.3

#create an environment named my_env and install numpy in it
conda create -n my_env numpy.

进入环境

use source activate my_env to enter it on OSX/Linux.
On Windows, use activate my_env.

The environment has only a few packages installed by default, plus the ones you installed when creating it. You can check this out with conda list. Installing packages in the environment is the same as before: conda install package_name. Only this time, the specific packages you install will only be available when you’re in the environment.

退出环境

To leave the environment, type source deactivate (on OSX/Linux). On Windows, use deactivate.

列举所有环境

conda info --envs
conda env list

导出导入环境配置

A really useful feature is sharing environments so others can install all the packages used in your code, with the correct versions. You can save the packages to a YAML file with conda env export > environment.yaml.

To create an environment from an environment file use
conda env create -f environment.yaml

移除环境

If there are environments you don’t use anymore, conda env remove -n env_name will remove the specified environment

Best practices

  • having separate environments for Python 2 and Python 3. I usedconda create -n py2 python=2 and conda create -n py3 python=3 to create two separate environments
  • I’ve also found it useful to create environments for each project I’m working on. It works great for non-data related projects
  • When sharing your code on GitHub, it’s good practice to make an environment file and include it in the repository. This will make it easier for people to install all the dependencies for your code. I also usually include a pip requirements.txt file using pip freeze (learn more here) for people not using conda
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值