Linux

如何在沒有網路或網際網路的情況下安裝 pip

  • October 18, 2019

我在redhat 7.5版本上使用如下方式安裝pip

我將 pkg - 下載pip-8.1.2-py2.py3-none-any.whl到沒有網路的機器上

我安裝它

python /root/pip-8.1.2-py2.py3-none-any.whl/pip install /root/pip-8.1.2-py2.py3-none-any.whl

但我不確定這是否是安裝 pip 的正確方法?

我們嘗試 -

clone https://github.com/psf/requests.git

然後將文件複製到沒有網路的機器上

然後

python setup.py install

,但是這樣我得到了錯誤,所以我們離開它

錯誤在最後一行

任何方式我們都可以從一些不清楚的原因中看到這種方法試圖獲得網際網路網路,所以我不明白為什麼?

python setup.py install
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'project_urls'
 warnings.warn(msg)
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
 warnings.warn(msg)
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
 warnings.warn(msg)
running install
running bdist_egg
running egg_info
writing requirements to requests.egg-info/requires.txt
writing requests.egg-info/PKG-INFO
writing top-level names to requests.egg-info/top_level.txt
writing dependency_links to requests.egg-info/dependency_links.txt
reading manifest file 'requests.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'NOTICE'
warning: no files found matching 'requirements.txt'
writing manifest file 'requests.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/__init__.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/__version__.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/_internal_utils.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/adapters.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/api.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/auth.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/certs.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/compat.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/cookies.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/exceptions.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/help.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/hooks.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/models.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/packages.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/sessions.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/status_codes.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/structures.py -> build/bdist.linux-x86_64/egg/requests
copying build/lib/requests/utils.py -> build/bdist.linux-x86_64/egg/requests
byte-compiling build/bdist.linux-x86_64/egg/requests/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/__version__.py to __version__.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/_internal_utils.py to _internal_utils.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/adapters.py to adapters.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/api.py to api.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/auth.py to auth.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/certs.py to certs.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/compat.py to compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/cookies.py to cookies.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/exceptions.py to exceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/help.py to help.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/hooks.py to hooks.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/models.py to models.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/packages.py to packages.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/sessions.py to sessions.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/status_codes.py to status_codes.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/structures.py to structures.pyc
byte-compiling build/bdist.linux-x86_64/egg/requests/utils.py to utils.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying requests.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying requests.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying requests.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying requests.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying requests.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying requests.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating 'dist/requests-2.22.0-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing requests-2.22.0-py2.7.egg
removing '/usr/lib/python2.7/site-packages/requests-2.22.0-py2.7.egg' (and everything under it)
creating /usr/lib/python2.7/site-packages/requests-2.22.0-py2.7.egg
Extracting requests-2.22.0-py2.7.egg to /usr/lib/python2.7/site-packages
requests 2.22.0 is already the active version in easy-install.pth

Installed /usr/lib/python2.7/site-packages/requests-2.22.0-py2.7.egg
Processing dependencies for requests==2.22.0
Searching for urllib3>=1.21.1,!=1.25.0,!=1.25.1,<1.26
Reading https://pypi.python.org/simple/urllib3/
Best match: urllib3 1.25.6
Downloading https://files.pythonhosted.org/packages/ff/44/29655168da441dff66de03952880c6e2d17b252836ff1aa4421fba556424/urllib3-1.25.6.tar.gz#sha256=9a107b99a5393caf59c7aa3c1249c16e6879447533d0887f4336dde834c7be86
Processing urllib3-1.25.6.tar.gz
Writing /tmp/easy_install-WI5FBQ/urllib3-1.25.6/setup.cfg
Running urllib3-1.25.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-WI5FBQ/urllib3-1.25.6/egg-dist-tmp-tEDlGM
error: Setup script exited with error in urllib3 setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.

使用最新的 pip 版本回答。

從這裡下載setuptools壓縮文件:

wget https://files.pythonhosted.org/packages/f4/d5/a6c19dcbcbc267aca376558797f036d9bcdff344c9f785fe7d0fe9a5f2a7/setuptools-41.4.0.zip

解壓縮,更改目錄然後安裝:python setup.py install

pip 從這裡下載:

wget https://files.pythonhosted.org/packages/ce/ea/9b445176a65ae4ba22dce1d93e4b5fe182f953df71a145f557cffaffc1bf/pip-19.3.1.tar.gz

解壓縮,更改目錄然後安裝它:python setup.py install

pip版本可以在這裡找到點 8.1.2

setuptools版本可以在這裡找到安裝工具 20.0.0

發行說明

引用自:https://unix.stackexchange.com/questions/547447