练习 46中的必填测验要求读者安装一个模块/包。我不明白我创建的模块和脚本是否适合练习,我不明白安装包后调用包的正确方法。任何关于脚本和模块交互的动态或其目的的见解也将不胜感激。
这是目录结构:
设置.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 install ex47_script.py 后安装在
/usr/local/share/python
并且 ex47-0.1-py2.7.egg 安装在
/usr/local/lib/python2.7/site-packages