Python2环境下使用pip安装django-haystack失败解决方法

系统环境

Python:2.7.5
django-haystack:2.8.1

遇到的问题

重新部署一个使用Python2开发的项目,使用默认源安装时,有安装进度但报错:

$ pip install django-haystack==2.8.1
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: http://172.18.0.62/pypi/simple/
Collecting django-haystack==2.8.1
  Downloading http://172.18.0.62/pypi/packages/69/43/3e247b7b2134b48e9a53fb387e191e5e05b5f38f2faf78ca892097c2b441/django-haystack-2.8.1.tar.gz (1.6 MB)
     |████████████████████████████████| 1.6 MB 4.7 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /root/.virtualenvs/THCMPHelpCenter/bin/python2.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-xYf4n0/django-haystack/setup.py'"'"'; __file__='"'"'/tmp/pip-install-xYf4n0/django-haystack/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-xYf4n0/django-haystack/pip-egg-info
         cwd: /tmp/pip-install-xYf4n0/django-haystack/
    Complete output (25 lines):
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
    WARNING: The repository located at 172.18.0.62 is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host 172.18.0.62'.
    ERROR: Could not find a version that satisfies the requirement setuptools_scm (from versions: none)
    ERROR: No matching distribution found for setuptools_scm
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-xYf4n0/django-haystack/setup.py", line 71, in <module>
        setup_requires=['setuptools_scm'],
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/setuptools/__init__.py", line 144, in setup
        _install_setup_requires(attrs)
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/setuptools/__init__.py", line 139, in _install_setup_requires
        dist.fetch_build_eggs(dist.setup_requires)
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/setuptools/dist.py", line 721, in fetch_build_eggs
        replace_conflicting=True,
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/pkg_resources/__init__.py", line 782, in resolve
        replace_conflicting=replace_conflicting
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1065, in best_match
        return self.obtain(req, installer)
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1077, in obtain
        return installer(requirement)
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/setuptools/dist.py", line 777, in fetch_build_egg
        return fetch_build_egg(self, req)
      File "/root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages/setuptools/installer.py", line 130, in fetch_build_egg
        raise DistutilsError(str(e))
    distutils.errors.DistutilsError: Command '['/root/.virtualenvs/THCMPHelpCenter/bin/python2.7', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', '/tmp/tmpyA0zVE', '--quiet', 'setuptools_scm']' returned non-zero exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

错误原因

setuptools版本过低,或缺少依赖的下载工具setuptools-scm

解决方法

如果是因为setuptools版本过低,就升级版本:

$ pip install --upgrade setuptools

如果升级后依然报错,就安装setuptools-scm

$ pip install setuptools_scm

之后重新安装django-haystack,成功:

pip install django-haystack==2.8.1
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. t Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: http://172.18.0.62/pypi/simple/
Collecting django-haystack==2.8.1
  Downloading http://172.18.0.62/pypi/packages/69/43/3e247b7b2134b48e9a53fb387e191e5e05b5f38f2faf78ca892097c2b441/django-haystack-2.8.1.tar.gz (1.6 MB)
     |████████████████████████████████| 1.6 MB 2.9 MB/s 
Requirement already satisfied: Django>=1.11 in /root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages (from django-haystack==2.8.1) (1.11.29)
Requirement already satisfied: pytz in /root/.virtualenvs/THCMPHelpCenter/lib/python2.7/site-packages (from Django>=1.11->django-haystack==2.8.1) (2019.3)
Building wheels for collected packages: django-haystack
  Building wheel for django-haystack (setup.py) ... done
  Created wheel for django-haystack: filename=django_haystack-2.8.1-py2-none-any.whl size=131002 sha256=c4ed6d0f3b31377bd0be7ea97afbedf51e5a1dccb430e3b1dc4c80c7f60e3e7f
  Stored in directory: /root/.cache/pip/wheels/26/e1/87/e5b97c5111704b6145052f3d9ba5f6b030200edec6c42c76f1
Successfully built django-haystack
Installing collected packages: django-haystack
Successfully installed django-haystack-2.8.1

其它问题

不知道是不是因为2020年1月1日起官方不再支持Python2,还是机器代理设置的原因,在搭环境的时候还遇到了一些大大小小的问题,比如国内各种源都无法使用了,这也是为什么都2020年了,我还在用默认源装module。(这个问题可能是代理设置的锅,留存一下,以后有时间再研究):

$ pip install django-haystack==2.8.1 -i https://mirrors.cloud.aliyuncs.com/pypi/simple/
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in indexes: https://mirrors.cloud.aliyuncs.com/pypi/simple/
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x2427810>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/simple/django-haystack/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x242d090>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/simple/django-haystack/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x242d210>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/simple/django-haystack/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x242d350>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/simple/django-haystack/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x242d4d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /pypi/simple/django-haystack/
ERROR: Could not find a version that satisfies the requirement django-haystack==2.8.1 (from versions: none)
ERROR: No matching distribution found for django-haystack==2.8.1

扩展资料

Django:haystack全文检索详细教程

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章