利用setup.py將框架安裝到python環境中,作為第三方模組來呼叫,
from os.path import dirname, join
# from pip.req import parse_requirements
from setuptools import (
find_packages,
setup,
)def parse_requirements(filename):
""" load requirements from a pip requirements file """
lineiter = (line.strip() for line in open(filename))
return [line for line in lineiter if line and not line.startswith("#")]
with open(join(dirname(__file__), './version.txt'), 'rb') as f:
version = f.read().decode('ascii').strip()
setup(
name='py-plus', # 模組名稱
version=version,
description='a mini web framework', # 描述
packages=find_packages(exclude=),
author='xx',
author_email='[email protected]',
license='apache license v2',
package_data=,
url='#',
install_requires=parse_requirements("requirements.txt"), # 所需的執行環境
zip_safe=false,
classifiers=[
'programming language :: python',
'operating system :: microsoft :: windows',
'operating system :: unix',
'programming language :: python :: 2.7',
'programming language :: python :: 3.4',
'programming language :: python :: 3.5',
'programming language :: python :: 3.6',
],)
注意: 上面**中可能會報錯需要額外安裝packaging模組,更新setuptools
pip.req可能不存在,對應的可以:
def parse_requirements(filename):
""" load requirements from a pip requirements file """
lineiter = (line.strip() for line in open(filename))
return [line for line in lineiter if line and not line.startswith("#")]
功能:
使用:
requests>=2.18.4
six>=1.11.0
功能:
使用:
1.0
步驟:
切換到對應需要python虛擬環境下
切換到setup.py所在目錄
在終端執行python setup.py install
end
手動製作python安裝模組
1.把所有寫好的模組放到乙個資料夾 test 2.在同級目錄新建乙個setup.py檔案如。setup.py檔案 from distuils.core import setup setup name mytest version 0.10 description my test module aut...
64 python 模組製作
在python中,每個python檔案都可以作為乙個模組,模組的名字就是檔案的名字。比如有這樣乙個檔案test.py,在test.py中定義了函式add test.py def add a,b return a b 那麼在其他檔案中就可以先import test,然後通過test.add a,b 來...
Python 模組和模組的常用方法
print name 結果 main if name main print print file 結果 d program files x86 pycharmprojects test 03day one.py 6666 print doc 結果 6666import random print ra...