Exercise 46 中的必需测验要求读者安装模块/包。我不明白我创建的模块和脚本是否适合练习,我不知道安装后调用包的正确方法。任何关于脚本和模块交互的动态或其目的的见解也将受到赞赏。
以下是目录结构:
setup.py:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
'description': 'My Project',
'author': 'John',
'url': 'URL to get it at.',
'download_url': 'Where to download it.',
'author_email': 'john@',
'version': '0.1',
'install_requires': ['nose'],
'packages': ['ex47package'],
'scripts': ['bin/ex47_script.py'],
'name': 'ex47'
}
setup(**config)
ex47_module.py:
def explainIt():
print "root_package"
print "\tsetup.py"
print "\tbin: a standard place to put scripts that are run on the command line, \
not a place to put modules."
print"\t\tmyScipt.py"
print "\tdocs"
print "\ttests"
print "\t\t__init__.py : tells Python that this directory is indeed a package; can be blank"
print "\tmyPackage: the folder containing your Python code;\
should be the name you specify to 'packages' below"
print "\t\t__init__.py : tells Python that this directory is indeed a package; can be blank"
print "\t\tmyModule.py : your actual code; name doesn't matter"
print "\nto install: python setup.py install"
print "to uninstall: pip uninstall (name from setup.py)"
ex47_script.py:
#!/usr/bin/env python
print "This is the script in the bin directory"
xxx = raw_input("Enter some stuff to print: ")
print xxx
运行python setup.py后安装ex47_script.py已安装在
中的/ usr /本地/共享/蟒
和ex47-0.1-py2.7.egg安装在
中/usr/local/lib/python2.7/site-packages