centos7利用nexus离线搭建局域网pypi源
1、官网下载nexus oss版本
https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.2-02-unix.tar.gz
[root@localhost bin]# wget https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.2-02-unix.tar.gz
2、解压nexus至本地目录
[root@localhost bin]# tar -zxvf nexus-3.29.2-02-unix.tar.gz
3、启动nexus服务 ,如果提示JAVA_HOME没有设置,请安装java的JDK环境
[root@localhost bin]# cd /opt/nexus-3.29.2-02/bin/
[root@localhost bin]# ./nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
4、创建pypi仓库
hosted – 宿主仓库
,用户可以 deploy 到 hosted 中,也可以手工上传构件到 hosted 里,在 central repository 是获取不到的,就需要手工上传到hosted里
group – 仓库组
,将上述多个仓库聚合,对用户暴露统一的地址
5、上传pypi包
1)通过web页面上传(适合包比较少时)
2)命令行上传,需要先安装twine(适合批量上传)
pip3 install twine
twine upload --repository-url
twine upload --repository-url http://10.4.7.23:8081/repository/pypi-hosted/ -u admin -p admin123 /opt/pypi/* //要上传的路径为http://10.4.7.23:8081/repository/pypi-hosted/ 登录用户名为admin 密码为admin123pypi包所在的路径为/opt/pypi/
3)twine 各参数含义
$ twine upload -h
usage: twine upload [-h] [-r REPOSITORY] [--repository-url REPOSITORY_URL][-s] [--sign-with SIGN_WITH] [-i IDENTITY] [-u USERNAME][-p PASSWORD] [-c COMMENT] [--config-file CONFIG_FILE][--skip-existing] [--cert path] [--client-cert path][--verbose] [--disable-progress-bar]dist [dist ...]positional arguments:dist The distribution files to upload to the repository(package index). Usually dist/* . May additionallycontain a .asc file to include an existing signaturewith the file upload.optional arguments:-h, --help show this help message and exit-r REPOSITORY, --repository REPOSITORYThe repository (package index) to upload the packageto. Should be a section in the config file (default:pypi). (Can also be set via TWINE_REPOSITORYenvironment variable.)--repository-url REPOSITORY_URLThe repository (package index) URL to upload thepackage to. This overrides --repository. (Can also beset via TWINE_REPOSITORY_URL environment variable.)-s, --sign Sign files to upload using GPG.--sign-with SIGN_WITHGPG program used to sign uploads (default: gpg).-i IDENTITY, --identity IDENTITYGPG identity used to sign files.-u USERNAME, --username USERNAMEThe username to authenticate to the repository(package index) as. (Can also be set viaTWINE_USERNAME environment variable.)-p PASSWORD, --password PASSWORDThe password to authenticate to the repository(package index) with. (Can also be set viaTWINE_PASSWORD environment variable.)--non-interactive Do not interactively prompt for username/passwordif the required credentials are missing. (Can alsobe set via TWINE_NON_INTERACTIVE environmentvariable.)-c COMMENT, --comment COMMENTThe comment to include with the distribution file.--config-file CONFIG_FILEThe .pypirc config file to use.--skip-existing Continue uploading files if one already exists. (Onlyvalid when uploading to PyPI. Other implementationsmay not support this.)--cert path Path to alternate CA bundle (can also be set viaTWINE_CERT environment variable).--client-cert path Path to SSL client certificate, a single filecontaining the private key and the certificate in PEMformat.--verbose Show verbose output.--disable-progress-barDisable the progress bar.
6、上传后结果
7、pip使用本地源进行安装
[root@localhost bin]# pip install requests -i http://10.4.7.23:8081/repository/pypi-group/simple --trusted-host 10.4.7.23 //-i 指定pypi源
Collecting requestsDownloading http://10.4.7.23:8081/repository/pypi-group/packages/requests/2.25.1/requests-2.25.1-py2.py3-none-any.whl (61kB)100% |████████████████████████████████| 61kB 6.3MB/s
Collecting certifi>=2017.4.17 (from requests)Downloading http://10.4.7.23:8081/repository/pypi-group/packages/certifi/2020.12.5/certifi-2020.12.5-py2.py3-none-any.whl (147kB)