在 阿里云git上創(chuàng)建一個空項目yuesf08, 項目屬性為public, 并下拉到本地,如下圖所示git/yuesf08。
yuesf08文件下創(chuàng)建包yuesfpug, 第一個init函數(shù)必須存在,第二個是用戶編寫的函數(shù)。
# init.py # -*- coding:utf-8 -*- from . import add_num # add.num.py # -*- coding:utf-8 -*- def add_num(a,b): return a+b
from distutils.core import setup import setuptools packages = ['yuesfpug']# 唯一的包名 setup(name='yuesfpug', version='1.0', author='yuesf', packages=packages, package_dir={'requests': 'requests'},)
Copyright © 2021 yuesf Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
pip install twine pip install wheel
cmd一定要進入路徑D:\yuesf\shangfei\git\yuesf08
# 1. 編譯 python setup.py build # 2. 生成發(fā)布壓縮包: python setup.py sdist # 3. 生成網(wǎng)絡(luò)發(fā)布包wheel文件: python setup.py bdist_wheel
cmd一定要進入路徑D:\yuesf\shangfei\git\yuesf08\dist
pip install yuesfpug-1.0-py3-none-any.whl
通過測試我們發(fā)現(xiàn),add_num.py實際上可以看作一個模塊,里面的函數(shù)也是add_num,所以調(diào)用是add_num.add_num(a,b)
cmd一定要進入路徑D:\yuesf\shangfei\git\yuesf08\dist
在pypi官網(wǎng)注冊,上傳代碼時填寫pypi賬號、密碼。
twine upload dist/*
先刪除本地安裝的包,再安裝上傳的包,這個時候的路徑是C盤。
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
標簽:呼倫貝爾 湘西 銀川 呼倫貝爾 三亞 葫蘆島 安慶 烏魯木齊
巨人網(wǎng)絡(luò)通訊聲明:本文標題《如何將自己的python代碼發(fā)布在pip install給別人使用你知道嗎》,本文關(guān)鍵詞 如何,將,自己的,python,代碼,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。