広告 Linux Python

pip使用時の注意点

pipでパッケージを入れようとした際に色々苦労したのでその記録を残します。

RHEL系のOSはpipがインストールされていないので、↓のようにインストールする必要があります。

% yum install epel-release
% yum install pip

普通はyumでサクッとインストールできるはずなのに、何故か「そんなパッケージはない!」と怒られてインストールできませんでした。

yum でインストールできない場合は↓のようにrpmで入れるとよいです

% rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
% pip --version
pip 7.1.0 from /usr/lib/python2.6/site-packages (python 2.6)

これでpipが入りました。

pipをインストールしてすぐにパッケージを入れようとすると↓のように怒られてしまいます。

% pip install psycopg2
You are using pip version 7.1.0, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting psycopg2
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading psycopg2-2.7.tar.gz (421kB)
    100% |████████████████████████████████| 421kB 639kB/s 
Collecting curses
  Could not find a version that satisfies the requirement curses (from versions: )
No matching distribution found for curses

なので、pipをアップグレードしましょう。

% pip install --upgrade pip

pipアップグレードすると大抵はスルッとパッケージをインストールできるのですが、ものによっては下記のように怒られてしまいます。

% pip2.6 install  pg-view
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting pg-view
  Using cached pg-view-1.4.0.tar.gz
    Complete output from command python setup.py egg_info:

    Installed /tmp/easy_install-HFTwCi/flake8-3.3.0/temp/easy_install-ZIyuXd/pytest-runner-2.11.1/setuptools_scm-1.15.1rc1-py2.6.egg
    your setuptools is too old (<12)
    setuptools_scm functionality is degraded
    zip_safe flag not set; analyzing archive contents...

    Installed /tmp/easy_install-HFTwCi/flake8-3.3.0/pytest_runner-2.11.1-py2.6.egg
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-build-gaYbrc/pg-view/setup.py", line 128, in 
        setup_package()
      File "/tmp/pip-build-gaYbrc/pg-view/setup.py", line 123, in setup_package
        entry_points={'console_scripts': CONSOLE_SCRIPTS},
      File "/usr/lib64/python2.6/distutils/core.py", line 113, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/lib/python2.6/site-packages/setuptools/dist.py", line 221, in __init__
        self.fetch_build_eggs(attrs.pop('setup_requires'))
      File "/usr/lib/python2.6/site-packages/setuptools/dist.py", line 245, in fetch_build_eggs
        parse_requirements(requires), installer=self.fetch_build_egg
      File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 538, in resolve
        dist = best[req.key] = env.best_match(req, self, installer)
      File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 780, in best_match
        return self.obtain(req, installer) # try and download/install
      File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 792, in obtain
        return installer(requirement)
      File "/usr/lib/python2.6/site-packages/setuptools/dist.py", line 293, in fetch_build_egg
        return cmd.easy_install(req)
      File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 472, in easy_install
        return self.install_item(spec, dist.location, tmpdir, deps)
      File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 502, in install_item
        dists = self.install_eggs(spec, download, tmpdir)
      File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 681, in install_eggs
        return self.build_and_install(setup_script, setup_base)
      File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 958, in build_and_install
        self.run_setup(setup_script, setup_base, args)
      File "/usr/lib/python2.6/site-packages/setuptools/command/easy_install.py", line 947, in run_setup
        run_setup(setup_script, args)
      File "/usr/lib/python2.6/site-packages/setuptools/sandbox.py", line 29, in run_setup
        lambda: execfile(
      File "/usr/lib/python2.6/site-packages/setuptools/sandbox.py", line 70, in run
        return func()
      File "/usr/lib/python2.6/site-packages/setuptools/sandbox.py", line 31, in 
        {'__file__':setup_script, '__name__':'__main__'}
      File "setup.py", line 134, in 

      File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
        dist.run_commands()
      File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
        self.run_command(cmd)
      File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
        cmd_obj.run()
      File "/usr/lib/python2.6/site-packages/setuptools/command/bdist_egg.py", line 167, in run
        self.run_command("egg_info")
      File "/usr/lib64/python2.6/distutils/cmd.py", line 333, in run_command
        self.distribution.run_command(command)
        File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
          cmd_obj.run()
        File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 179, in run
          self.find_sources()
        File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 254, in find_sources
          mm.run()
        File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 308, in run
          self.add_defaults()
        File "/usr/lib/python2.6/site-packages/setuptools/command/egg_info.py", line 335, in add_defaults
          rcfiles = list(walk_revctrl())
        File "/usr/lib/python2.6/site-packages/setuptools/command/sdist.py", line 46, in walk_revctrl
          for item in ep.load()(dirname):
        File "/usr/lib/python2.6/site-packages/pkg_resources.py", line 1948, in load
          entry = __import__(self.module_name, globals(),globals(), ['__name__'])
      ImportError: No module named setuptools_scm.integration

      ----------------------------------------
  Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-gaYbrc/pg-view/

これは、setuptoolsのバージョンが古いと怒られました。

同様にバージョンを上げましょう。

% pip install --upgrade setuptools
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Collecting setuptools
  Downloading setuptools-34.3.1-py2.py3-none-any.whl (389kB)
    100% |████████████████████████████████| 399kB 1.7MB/s 
Collecting six>=1.6.0 (from setuptools)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting appdirs>=1.4.0 (from setuptools)
  Downloading appdirs-1.4.3-py2.py3-none-any.whl
Collecting packaging>=16.8 (from setuptools)
  Downloading packaging-16.8-py2.py3-none-any.whl
Collecting pyparsing (from packaging>=16.8->setuptools)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 5.7MB/s 
Installing collected packages: six, appdirs, pyparsing, packaging, setuptools
  Found existing installation: setuptools 0.6rc11
    DEPRECATION: Uninstalling a distutils installed project (setuptools) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling setuptools-0.6rc11:
      Successfully uninstalled setuptools-0.6rc11
Successfully installed appdirs-1.4.3 packaging-16.8 pyparsing-2.2.0 setuptools-34.3.1 six-1.10.0

これで入るようになりました。

% pip install pg_view
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting pg_view
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached pg-view-1.4.0.tar.gz
Collecting psycopg2 (from pg_view)
  Using cached psycopg2-2.7-cp26-cp26mu-manylinux1_x86_64.whl
Installing collected packages: psycopg2, pg-view
  Running setup.py install for pg-view ... done
Successfully installed pg-view-1.4.0 psycopg2-2.7

Sponsor Link

-Linux, Python