pip install的背后,究竟是怎样的?

回想一下,当你发现某个模块不存在,会怎么办?
在这里插入图片描述
你是手忙脚乱的找帮忙,还是从容不迫的找帮忙?

选择题

|
|
___________________________________________________/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\/防剧透助手已上线\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/
//\\//\\\\\\\\\\\\\\\///\\/\/\\\\///\\/\

不会吧,这都不会?

C:\Users\M S I>pip install progressbar
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple/
Collecting progressbar
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/a6/b8e451f6cff1c99b4747a2f7235aa904d2d49e8e1464e0b798272aa84358/progressbar-2.5.tar.gz (10 kB)
Building wheels for collected packages: progressbar
  Building wheel for progressbar (setup.py) ... done
  Created wheel for progressbar: filename=progressbar-2.5-py3-none-any.whl size=12078 sha256=d71e341c551baa36e1db849830be828b0beb018ab8846e75b6229acb8c420f20
  Stored in directory: c:\users\m s i\appdata\local\pip\cache\wheels\bc\3c\4b\2670de9faa1634800f76dc07bd3c4bd26ae024572401bc29e4
Successfully built progressbar
Installing collected packages: progressbar
Successfully installed progressbar-2.5

不明白?OMG,还是问小度吧

恭喜你,可以往下读了

在这里插入图片描述


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1.搭建你的模块
make your own module



举个例子
在这里插入图片描述

C:.
│ 
│
├─Mydemos_pkg
    │  bytedesign.py
    │  chaos.py
    │  clock.py
    │  colormixer.py
    │  forest.py
    │  fractalcurves.py
    │  hanoi.py
    │  lindenmayer.py
    │  nim.py
    │  paint.py
    │  peace.py
    │  penrose.py
    │  pip_install.py
    │  planet_and_moon.py
    │  rosette.py
    │  round_dance.py
    │  sort.py
    │  sort_animate.py
    │  sort_test_cn.py
    │  tree.py
    │  two_canvas.py
    │  yinyang.py

,然后你必须要运行它来确保这模块是否 因 落掉某个语句或语法错误而“有毛病”

cd …

>>>import tree

Traceback (most recent call last):
File “<string>”, line 1, in <module>
list(a)
TypeError: map() must have at least two arguments.

万一出现,赶紧修改吧
在这里插入图片描述

2.创建setup及__init__
make setup.py and __init __.py

__doc__='''
your doc here
'''
name = 'Mydemos_pkg'
'''
注:
本名本人已用过,已经上传到pypi,所以您的模块不得以Mydemos_pkg命名。
'''

🐔
讲解:
此.py命名为__init__.py
你导入模块时导入的是这个。
__doc__中的内容将会在help('你的模块')时出现。
name是模块名。


setup.py的构建
新建一个setup.py,放在父目录下。
在这里插入图片描述
听没听见?父目录!

from setuptools import setup
 
NAME = 'Mydemos_pkg'
VERSION = '1.1.4.0'
PACKAGES = ['Mydemos_pkg']
setup(name = NAME
        , version = VERSION
        , packages = PACKAGES,
      description='a small pkg demos for you and everyone',
      long_description='''

pip install Mydemos_pkg

'''
      ,long_description_content_type='text/markdown'
) 

讲解:
setup.py是构建模块。
NAME是模块名
VERSION是版本号
PACKAGES是包含模块
description是创作原因
long_description是长的创作原因
long_description_content_typelong_description的格式
3.构建模块(机器自己做)
build modules(machine does it)


不要担心,成品.whl.tar.gz不需要你一个一个拖压缩文件。
上cmd!!!


C:\Users\M S I\OneDrive\桌面\turtlemodulesdemo>setup.py build
running build
running build_py

C:\Users\M S I\OneDrive\桌面\turtlemodulesdemo>setup.py sdist
running sdist
running egg_info
writing Mydemos_pkg.egg-info\PKG-INFO
writing dependency_links to Mydemos_pkg.egg-info\dependency_links.txt
writing top-level names to Mydemos_pkg.egg-info\top_level.txt
reading manifest file 'Mydemos_pkg.egg-info\SOURCES.txt'
writing manifest file 'Mydemos_pkg.egg-info\SOURCES.txt'
running check
warning: Check: missing required meta-data: url

warning: Check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied

creating Mydemos_pkg-1.1.4.0
creating Mydemos_pkg-1.1.4.0\Mydemos_pkg
creating Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying files to Mydemos_pkg-1.1.4.0...
copying setup.py -> Mydemos_pkg-1.1.4.0
copying Mydemos_pkg\.py -> Mydemos_pkg-1.1.4.0\Mydemos_pkg
copying Mydemos_pkg.egg-info\PKG-INFO -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying Mydemos_pkg.egg-info\SOURCES.txt -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying Mydemos_pkg.egg-info\dependency_links.txt -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying Mydemos_pkg.egg-info\top_level.txt -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
Writing Mydemos_pkg-1.1.4.0\setup.cfg
Creating tar archive
removing 'Mydemos_pkg-1.1.4.0' (and everything under it)

C:\Users\M S I\OneDrive\桌面\turtlemodulesdemo>python setup.py sdist bdist_wheel
running sdist
running egg_info
writing Mydemos_pkg.egg-info\PKG-INFO
writing dependency_links to Mydemos_pkg.egg-info\dependency_links.txt
writing top-level names to Mydemos_pkg.egg-info\top_level.txt
reading manifest file 'Mydemos_pkg.egg-info\SOURCES.txt'
writing manifest file 'Mydemos_pkg.egg-info\SOURCES.txt'
running check
warning: Check: missing required meta-data: url

warning: Check: missing meta-data: either (author and author_email) or (maintainer and maintainer_email) must be supplied

creating Mydemos_pkg-1.1.4.0
creating Mydemos_pkg-1.1.4.0\Mydemos_pkg
creating Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying files to Mydemos_pkg-1.1.4.0...
copying setup.py -> Mydemos_pkg-1.1.4.0
copying Mydemos_pkg\.py -> Mydemos_pkg-1.1.4.0\Mydemos_pkg
copying Mydemos_pkg.egg-info\PKG-INFO -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying Mydemos_pkg.egg-info\SOURCES.txt -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying Mydemos_pkg.egg-info\dependency_links.txt -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
copying Mydemos_pkg.egg-info\top_level.txt -> Mydemos_pkg-1.1.4.0\Mydemos_pkg.egg-info
Writing Mydemos_pkg-1.1.4.0\setup.cfg
Creating tar archive
removing 'Mydemos_pkg-1.1.4.0' (and everything under it)
running bdist_wheel
running build
running build_py
installing to build\bdist.win-amd64\wheel
running install
running install_lib
creating build\bdist.win-amd64\wheel
creating build\bdist.win-amd64\wheel\Mydemos_pkg
copying build\lib\Mydemos_pkg\.py -> build\bdist.win-amd64\wheel\.\Mydemos_pkg
copying build\lib\setup.py -> build\bdist.win-amd64\wheel\.
running install_egg_info
Copying Mydemos_pkg.egg-info to build\bdist.win-amd64\wheel\.\Mydemos_pkg-1.1.4.0-py3.7.egg-info
running install_scripts
creating build\bdist.win-amd64\wheel\Mydemos_pkg-1.1.4.0.dist-info\WHEEL
creating 'dist\Mydemos_pkg-1.1.4.0-py3-none-any.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'setup.py'
adding 'Mydemos_pkg/.py'
adding 'Mydemos_pkg-1.1.4.0.dist-info/METADATA'
adding 'Mydemos_pkg-1.1.4.0.dist-info/WHEEL'
adding 'Mydemos_pkg-1.1.4.0.dist-info/top_level.txt'
adding 'Mydemos_pkg-1.1.4.0.dist-info/RECORD'
removing build\bdist.win-amd64\wheel

C:\Users\M S I\OneDrive\桌面\turtlemodulesdemo>

反正就是

>setup.py sdist
>python setup.py sdist bdist_wheel

4.注册Pypi账号
register pypi


终于要上传了。
Pypi,等着我!到这里来 注册点这里 登录点这里

对不起,因第四章太短,我们实行防剧透。
---------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------------------














------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
------------------------------------------------------------------------------------------------------
---------------------------------------------------------------
------------------------------------

5.上传
upload


首先,要安装twine
/{[(<-居然用到pip了…->)]}\

pip install twine

然后,upload你的模块

C:\Users\M S I\OneDrive\桌面\turtlemodulesdemo>twine upload dist/Mydemos_pkg-1.1.4.0*
Uploading distributions to https://upload.pypi.org/legacy/
Enter your username: <username>
Enter your password:
Uploading Mydemos_pkg-1.1.4.0-py3-none-any.whl
 29%|██████████████████████▍                                                      | 8.00k/27.5k [100%|█████████████████████████████████████████████████████████ ████████████████████| 27.5k/27.5k [00:02<00:00, 9.48kB/s]
Uploading Mydemos_pkg-1.1.4.0.tar.gz
100%|█████████████████████████████████████████████████████████ ████████████████████| 20.0k/20.0k [00:01<00:00, 17.6kB/s]

View at:
https://pypi.org/project/Mydemos-pkg/1.1.4.0/

C:\Users\M S I\OneDrive\桌面\turtlemodulesdemo>

神奇的是,你输入密码
上面不会显示!

然后找到View at:后面的网址查看即可。
6.测试
debug


先别得意,等几个小时后pip install Mydemos_pkg试试,如果成功,哈哈哈…
为什么等一天呢
在这里插入图片描述
因为
在这里插入图片描述
为什么呢
原来,镜像源(pypi或conda)传到镜像(清华或百度或阿里云,哦,小度又来了)需要时间。
昨天晚上睡觉后今天才看见。
7.分享
share


你可以把项目放到GitHub 上,也可以放到知乎 ,简书,上介绍你的模块。
如果你的模块好,你可以写一本教材,这样可不是发布那么简单了…你的模块也许会被某些网站报道。

最后考一考大家: 的图标是如何显示的呢?

好了,今天的文章就到这里,多多留言哦!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值