2015-10-17 5 views
5

私のWindows 7システムでは、condaを使って多くのパッケージをインストールしようとしています。これらは、残念ながらいくつかのパッケージがcondaには表示されませんcondaから来ていないすべてのpipパッケージを更新します

conda update all 

で更新するのは簡単ですが、ピップから入手できますので、それらのために、私はピップを使用してインストールします。窓の上のすべてのPIPパッケージを更新することはより困難なようだが、

for /F "delims===" %i in ('pip freeze -l') do pip install -U %i 

は、私が見つけた1つの方法です。

しかし、これはすべてのパッケージを更新しようとしていますが、コンドーマによってインストールされたパッケージも含めて更新されます。

pipでインストールされたパッケージのみをアップデートする方法はありますか?

答えて

1

Pipパッケージはcondaパッケージとは異なるため、これは難しいことです。 Anacondaはpipをインストールの選択肢として追加し、環境に配置しますが、管理しません。ピップは、すべてをアップグレードするのは簡単コマンドなしではまだですが、あなたがしようとしたとして、いくつかの提案があり、これは別である:ここでは

pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U 
+0

あなたの回答は窓では機能しませんし、condが管理しているパッケージをアップグレードすることも避けられません。 – eleanora

3

conda env exportの出力を解析し、任意のPIPパッケージをアップグレードしますシェルスクリプトで私の試みです。

#!/bin/sh 

############################################################################### 
# Script to scan an Anaconda environment and upgrade any PIP packages. 
# 
# Usage: 
# $ ./upgrade_pip_packages.sh 
# or explicitly give it an environment file to parse: 
# $ ./upgrade_pip_packages.sh <environment.yml file> 
# 
# Author: Marijn van Vliet <[email protected]> 
# 
# Version: 1.0 (29-09-2017) 
# - Initial version of the script. 

# Check for optional command line argument 
if [ "$#" = 0 ] 
then 
    ENV_OUTPUT=`conda env export` 
elif [ "$#" = 1 ] 
then 
    ENV_OUTPUT=`cat $1` 
else 
    echo "Usage: $0 [environment file]" >&2 
    exit 1 
fi 

PIP=0 # Whether we are parsing PIP packages 
IFS=$'\n' # Split on newlines 
PIP_PACKAGES="" # PIP packages found thus far 

# Loop over the output of "conda env export" 
for line in $ENV_OUTPUT 
do 
    # Don't do anything until we get to the packages installed by PIP 
    if [ "$line" = "- pip:" ] 
    then 
     PIP=1 # From this point, start doing things. 
    elif [[ "$line" = prefix:* ]] 
    then 
     PIP=0 # End of PIP package list. Stop doing things. 
    elif [ $PIP = 1 ] 
    then 
     # Packages are listed as " - name==version==python_version" 
     # This is a regular expression that matches only the name and 
     # strips quotes in git URLs: 
     REGEXP='^ - "\?\([^="]*\)"\?.*$' 

     # Find PIP package name (or git URL) 
     PIP_PACKAGES="$PIP_PACKAGES `echo "$line" | sed -n "s/$REGEXP/\1/p"`" 
    fi 
done 

# From now on, split on spaces 
IFS=' ' 

echo "The following packages are marked for upgrade using PIP:" 
echo 
for package in $PIP_PACKAGES 
do 
    echo " - $package" 
done 
echo 

read -r -p "Shall we proceed with the upgrade? [y/N] " response 
case "$response" in 
    [yY][eE][sS]|[yY]) 
     # Upgrade each package 
     for package in $PIP_PACKAGES 
     do 
      pip install --upgrade $package 
     done 
     ;; 
    *) 
     echo "Aborting" 
     ;; 
esac 
関連する問題