Поиск по блогу

суббота, 10 января 2015 г.

Пожарное обновление Scrapy с Conda и PIP

Зубы надо чистить два раза в день, а проверять обновления раз в неделю. К такому выводу я пришел после очередного вынужденного обновления модуля SCrаpy.
Решил записать эти рутинные действия, чтобы научиться выполнять эти операции "на автомате". Пока я еще не понимаю, как лучше организовать процесс "ухода" за "инфраструктурой" (Windows,Linux, Python...

Попытка "обновиться по памяти"

Привела к ошибкам, почему я попытался "вспомнить" команду, которую только освоил год назад и с тех пор месяцев 9 не пользовал. Надо было в документацию заглянуть... Но очень не хотелось, я в это время "обдумывал" и кодировал нового паука, и вдруг выяснилось, что некоторые классы уже depricated... Хотелось "по быстрому" все исправить..., да не тут то было.

In []:
C:\WINDOWS\system32>pip install scrapy
Requirement already satisfied (use --upgrade to upgrade): scrapy in c:\users\kiss\anaconda\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.2 in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): lxml in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in c:\users\kiss\anaconda\lib\site-packages (from Tw
isted>=10.0.0->scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.4.1 in c:\users\kiss\anaconda\lib\site-packages (from w3lib>=1.2->s
crapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\users\kiss\anaconda\lib\site-packages (from zope.interfac
e>=3.6.0->Twisted>=10.0.0->scrapy)
Cleaning up...

C:\WINDOWS\system32>pip install scrapy --upgrade
Downloading/unpacking scrapy from https://pypi.python.org/packages/2.7/S/Scrapy/Scrapy-0.24.4-py2-none-any.whl#md5=badb656b5a61b0add
f2502b012df3ca4
Downloading/unpacking pyOpenSSL from https://pypi.python.org/packages/source/p/pyOpenSSL/pyOpenSSL-0.14.tar.gz#md5=8579ff3a1d858858a
cfba5f046a4ddf7 (from scrapy)
  Running setup.py (path:c:\users\kiss\appdata\local\temp\pip_build_kiss\pyOpenSSL\setup.py) egg_info for package pyOpenSSL

    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    no previously-included directories found matching 'doc\_build'
Downloading/unpacking six>=1.5.2 from https://pypi.python.org/packages/3.3/s/six/six-1.9.0-py2.py3-none-any.whl#md5=9ac7e129a80f72d6
fc1f0216f6e9627b (from scrapy)
  Downloading six-1.9.0-py2.py3-none-any.whl
Downloading/unpacking queuelib from https://pypi.python.org/packages/2.7/q/queuelib/queuelib-1.2.2-py2.py3-none-any.whl#md5=ebf62dda
971ceff1c01f2a8f4acf9829 (from scrapy)
  Downloading queuelib-1.2.2-py2.py3-none-any.whl
Downloading/unpacking lxml from https://pypi.python.org/packages/2.7/l/lxml/lxml-3.4.1-cp27-none-win_amd64.whl#md5=052bfdfe41343b571
453812d66e7b3c7 (from scrapy)
Downloading/unpacking w3lib>=1.8.0 (from scrapy)
  Downloading w3lib-1.10.0-py2.py3-none-any.whl
Requirement already up-to-date: cssselect>=0.9 in c:\users\kiss\anaconda\lib\site-packages (from scrapy)
Downloading/unpacking Twisted>=10.0.0 from https://pypi.python.org/packages/2.7/T/Twisted/Twisted-14.0.2-cp27-none-win_amd64.whl#md5
=c83376b4e498080d831203ffa4bcc490 (from scrapy)
Downloading/unpacking cryptography>=0.2.1 from https://pypi.python.org/packages/cp27/c/cryptography/cryptography-0.7.1-cp27-none-win
_amd64.whl#md5=0decc1c2ddb7618e6a4b980884bd83f2 (from pyOpenSSL->scrapy)
Downloading/unpacking zope.interface>=3.6.0 from https://pypi.python.org/packages/source/z/zope.interface/zope.interface-4.1.2.tar.g
z#md5=04298faeaa70b4f3b23fa2ae8987262c (from Twisted>=10.0.0->scrapy)
  Running setup.py (path:c:\users\kiss\appdata\local\temp\pip_build_kiss\zope.interface\setup.py) egg_info for package zope.interfac
e

    warning: no previously-included files matching '*.dll' found anywhere in distribution
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.so' found anywhere in distribution
Downloading/unpacking pyasn1 (from cryptography>=0.2.1->pyOpenSSL->scrapy)
  Running setup.py (path:c:\users\kiss\appdata\local\temp\pip_build_kiss\pyasn1\setup.py) egg_info for package pyasn1

Requirement already up-to-date: cffi>=0.8 in c:\users\kiss\anaconda\lib\site-packages (from cryptography>=0.2.1->pyOpenSSL->scrapy)
Downloading/unpacking enum34 (from cryptography>=0.2.1->pyOpenSSL->scrapy)
  Downloading enum34-1.0.4.tar.gz
  Running setup.py (path:c:\users\kiss\appdata\local\temp\pip_build_kiss\enum34\setup.py) egg_info for package enum34

Downloading/unpacking setuptools from https://pypi.python.org/packages/3.4/s/setuptools/setuptools-11.3.1-py2.py3-none-any.whl#md5=5
9cd761f2f2b926313bed7f83337e4d7 (from cryptography>=0.2.1->pyOpenSSL->scrapy)
Requirement already up-to-date: pycparser in c:\users\kiss\anaconda\lib\site-packages (from cffi>=0.8->cryptography>=0.2.1->pyOpenSS
L->scrapy)
Installing collected packages: scrapy, pyOpenSSL, six, queuelib, lxml, w3lib, Twisted, cryptography, zope.interface, pyasn1, enum34,
 setuptools
  Found existing installation: Scrapy 0.20.1
    Uninstalling Scrapy:
      Successfully uninstalled Scrapy
  Found existing installation: pyOpenSSL 0.13
    Uninstalling pyOpenSSL:
      Successfully uninstalled pyOpenSSL
  Running setup.py install for pyOpenSSL

    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    no previously-included directories found matching 'doc\_build'
    Removing C:\Users\kiss\Anaconda\Lib\site-packages\pyOpenSSL-0.14-py2.7.egg-info
  Found existing installation: six 1.8.0
    Uninstalling six:
      Successfully uninstalled six
  Found existing installation: queuelib 1.1.1
    Uninstalling queuelib:
      Successfully uninstalled queuelib
  Found existing installation: lxml 3.4.0
    Uninstalling lxml:
      Successfully uninstalled lxml
Cleaning up...
Exception:

Выше можно прочитать, что стары модули успешно удалены, а вот с установкой новых проблемы (шрифт сообщения ниже был красным) :

In []:
Exception:
Traceback (most recent call last):
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\commands\install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\req.py", line 1443, in install
    requirement.commit_uninstall()
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\req.py", line 610, in commit_uninstall
    self.uninstalled.commit()
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\req.py", line 1860, in commit
    rmtree(self.save_dir)
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\util.py", line 43, in rmtree
    onerror=rmtree_errorhandler)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Users\kiss\Anaconda\lib\shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "C:\Users\kiss\Anaconda\lib\site-packages\pip\util.py", line 62, in rmtree_errorhandler
    func(path)
WindowsError: [Error 5] : 'c:\\users\\kiss\\appdata\\local\\temp\\pip-niporm-uninstall\\users\\kiss\\anaconda\\lib\\site-packages\\l
xml\\etree.pyd'

Storing debug log for failure in C:\Users\kiss\pip\pip.log

Копаться в логах очень не хотелось, потому я нашел и просмотрел свой старый пост Короткий пост об обновлении Anaconda "Conda update conda"

In []:
C:\WINDOWS\system32>conda update conda
Fetching package metadata: ..
# All requested packages already installed.
# packages in environment at C:\Users\kiss\Anaconda:
#
conda                     3.7.4                    py27_0

C:\WINDOWS\system32>conda update scrapy
Error: package 'scrapy' is not installed in C:\Users\kiss\Anaconda

C:\WINDOWS\system32>conda install scrapy
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment C:\Users\kiss\Anaconda:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    lxml-3.4.1                 |           py27_0         1.5 MB
    six-1.9.0                  |           py27_0          16 KB
    cssselect-0.9.1            |           py27_0          41 KB
    setuptools-11.3.1          |           py27_0         737 KB
    queuelib-1.2.2             |           py27_0          16 KB
    requests-2.5.1             |           py27_0         583 KB
    w3lib-1.8.1                |           py27_1          19 KB
    zope.interface-4.1.1       |           py27_0         140 KB
    twisted-14.0.0             |           py27_0         4.2 MB
    scrapy-0.24.4              |           py27_0         582 KB
    ------------------------------------------------------------
                                           Total:         7.7 MB

The following NEW packages will be INSTALLED:

    cssselect:      0.9.1-py27_0
    queuelib:       1.2.2-py27_0
    scrapy:         0.24.4-py27_0
    twisted:        14.0.0-py27_0
    w3lib:          1.8.1-py27_1
    zope.interface: 4.1.1-py27_0

The following packages will be UPDATED:

    lxml:           3.4.0-py27_0 --> 3.4.1-py27_0
    requests:       2.5.0-py27_0 --> 2.5.1-py27_0
    setuptools:     7.0-py27_0   --> 11.3.1-py27_0
    six:            1.8.0-py27_0 --> 1.9.0-py27_0

Proceed ([y]/n)? y

Fetching packages ...
lxml-3.4.1-py2 100% |###############################| Time: 0:00:03 392.18 kB/s
six-1.9.0-py27 100% |###############################| Time: 0:00:00 105.96 kB/s
cssselect-0.9. 100% |###############################| Time: 0:00:00 126.85 kB/s
setuptools-11. 100% |###############################| Time: 0:00:01 378.41 kB/s
queuelib-1.2.2 100% |###############################| Time: 0:00:00 108.23 kB/s
requests-2.5.1 100% |###############################| Time: 0:00:30  19.69 kB/s
w3lib-1.8.1-py 100% |###############################| Time: 0:00:00 124.77 kB/s
zope.interface 100% |###############################| Time: 0:00:00 210.62 kB/s
twisted-14.0.0 100% |###############################| Time: 0:00:11 391.41 kB/s
scrapy-0.24.4- 100% |###############################| Time: 0:00:01 363.92 kB/s
Extracting packages ...
[      COMPLETE      ] |#################################################| 100%
Unlinking packages ...
[      COMPLETE      ] |#################################################| 100%
Linking packages ...
[      COMPLETE      ] |#################################################| 100%

Попробовал запустить безобидную команду, а здесь что-то надо доустановить

In []:
C:\Users\kiss\SkyDrive\Docs\mailru\cars_mail_1\carmailPrice>scrapy genspider -l
C:\Users\kiss\Anaconda\lib\site-packages\twisted\internet\_sslverify.py:184: UserWarning: You do not have the service_identity modul
e installed. Please install it from <https://pypi.python.org/pypi/service_identity>. Without the service_identity module and a recen
t enough pyOpenSSL tosupport it, Twisted can perform only rudimentary TLS client hostnameverification.  Many valid certificate/hostn
ame mappings may be rejected.
  verifyHostname, VerificationError = _selectVerifyImplementation()
Available templates:
  basic
  crawl
  csvfeed
  xmlfeed

Пробуем доустановить модуль с Conda

In []:
C:\WINDOWS\system32>conda install service_identity
Fetching package metadata: ..
Error: No packages found in current win-64 channels matching: service_identity

You can search for this package on Binstar with

    binstar search -t conda service_identity

C:\WINDOWS\system32> binstar search -t conda service_identity
Run 'binstar show <USER/PACKAGE>' to get more details:
Packages:
                          Name | Access       | Package Types   | Summary
     ------------------------- | ------------ | --------------- | --------------------
     stuwilkins/service_identity | public       | conda           | Service identity verification for pyOpenSSL
Found 1 packages

C:\WINDOWS\system32>conda install stuwilkins/service_identity
Fetching package metadata: ..
Error: No packages found in current win-64 channels matching: stuwilkins/service_identity

You can search for this package on Binstar with

    binstar search -t conda stuwilkins/service_identity

Но в дефолтном репозитории его нет, и я не знаю, как устанавливать его из binstar... В документацию лезть не хочется, потому ищу модуль в других местах и быстро нахожу на pypi.python.org

Доустановить модули можно (нужно?) при помощи PIP.

Я просто попробовал запустить PIP в дефолтном пространстве имен C:\Users\kiss\Anaconda...

Кроме того,установить (обновить) не "все сразу", а только нужную программу.

Попробовал словосочетание "service_identity", безо всяких номеров версий (откуда я это знаю? Не помню... год назад что-то проситал )

In []:
C:\Users\kiss\Anaconda>pip install service_identity
Downloading/unpacking service-identity
  Downloading service_identity-14.0.0-py2.py3-none-any.whl
Downloading/unpacking pyasn1 (from service-identity)
  Running setup.py (path:c:\users\kiss\appdata\local\temp\pip_build_kiss\pyasn1\setup.py) egg_info for package pyasn1

Downloading/unpacking pyasn1-modules (from service-identity)
  Downloading pyasn1-modules-0.0.5.tar.gz
  Running setup.py (path:c:\users\kiss\appdata\local\temp\pip_build_kiss\pyasn1-modules\setup.py) egg_info for package pyasn1-module
s

Requirement already satisfied (use --upgrade to upgrade): pyopenssl>=0.12 in c:\users\kiss\anaconda\lib\site-packages (from service-
identity)
Downloading/unpacking characteristic>=14.0.0 (from service-identity)
  Downloading characteristic-14.3.0-py2.py3-none-any.whl
Installing collected packages: service-identity, pyasn1, pyasn1-modules, characteristic
  Running setup.py install for pyasn1

  Running setup.py install for pyasn1-modules

Successfully installed service-identity pyasn1 pyasn1-modules characteristic
Cleaning up...

Так и что? Все установилось? -ДА!

Да, сообщения об ошибках в консоли не появляются. Пробую сгенерировать нового паука и надеюсь, что шаблон должен быть с новыми классами... Да новый паук полностью соответствет онлайн документациии...

In [2]:
!pip help
Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  zip                         DEPRECATED. Zip individual packages.
  unzip                       DEPRECATED. Unzip individual packages.
  bundle                      DEPRECATED. Create pybundles.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output.
  --log-file <path>           Path to a verbose non-appending log, that only
                              logs failures. This log is active by default at
                              C:\Users\kiss\pip\pip.log.
  --log <path>                Path to a verbose appending log. This log is
                              inactive by default.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup.
  --cert <path>               Path to alternate CA bundle.

Надо было бы с самого начала проверить, установлен ли pip у меня (на windows w8)... Когда и как установил? Не помню, надо было записать в свое время...



Посты чуть ниже также могут вас заинтересовать

7 комментариев:

  1. Я столкнулся с аналогичной проблемой при установке модуля service_identity через conda. Но способ, который вы предлагаете, - установка через pip - это лошарский способ. Более правильно установить service_identity через conda skeleton pypi service_identity, затем сделать conda build service_identity и затем после успешной сборки установить service_identity в нужный environment из локальных файлов. У меня все это получилось

    ОтветитьУдалить
  2. Согласен, спасибо, при случае попробую

    ОтветитьУдалить
  3. И вот через три года опять понадобился питон на этом же компьютере. Начинаем разбираться с " ...установить service_identity через conda skeleton pypi" и "Creating Virtual Environments"

    https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments

    Creating Virtual Environments
    Python “Virtual Environments” allow Python packages to be installed in an isolated location for a particular application, rather than being installed globally.

    Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications?

    ОтветитьУдалить
  4. Building conda packages with conda skeleton
    https://conda.io/docs/user-guide/tutorials/build-pkgs-skeleton.html

    Здесь, вроде бы все, что надо...

    ОтветитьУдалить
    Ответы
    1. И о том же, но из части документации для widows
      https://conda.io/docs/user-guide/tutorials/build-windows.html#edit-the-skeleton-files

      Удалить
  5. Использовать pip внутри Conda можно:
    https://conda.io/docs/user-guide/tasks/manage-environments.html#using-pip-in-an-environment

    To use pip in your environment, in your Terminal window or an Anaconda Prompt, run:

    conda install -n myenv pip
    source activate myenv
    pip

    ОтветитьУдалить
    Ответы
    1. В том же документе о том, что надо ставить все пакеты (в окружение) одной коммандой:

      To create an environment with a specific version of Python and multiple packages:

      conda create -n myenv python=3.4 scipy=0.15.0 astroid babel

      TIP: Install all the programs that you want in this environment at the same time. Installing 1 program at a time can lead to dependency conflicts.

      Удалить