过去几天我一直在使用Head First Python学习python。
我已经达到了这样的程度,我必须构建一个我所制作的模块的分发包,称为nester,并将其安装在我的系统上。安装模块后,我必须将其导入脚本并使用导入模块中的函数。
当尝试从我保存原始nester.py的文件夹以外的任何文件夹导入模块时,我收到以下错误(这表明模块未正确安装):
james@james-Inspiron-1764:~$ python3.3
Python 3.3.0 (default, Sep 29 2012, 17:14:58)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nester
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'nester'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 64, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 4, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 20, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 21, in <module>
import apt_pkg
ImportError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'nester'
>>>
这就是我构建和安装模块的方法:
james@james-Inspiron-1764:~/python/headfirst/chapter2/nester$ python3.3 setup.py sdist
/usr/lib/python3.3/distutils/dist.py:257: UserWarning: Unknown distribution option: 'pymodules'
warnings.warn(msg)
running sdist
running check
warning: sdist: manifest template 'MANIFEST.in' does not exist (using default file list)
warning: sdist: standard file not found: should have one of README, README.txt
writing manifest file 'MANIFEST'
creating nester_jc-1.4.0
making hard links in nester_jc-1.4.0...
hard linking setup.py -> nester_jc-1.4.0
Creating tar archive
removing 'nester_jc-1.4.0' (and everything under it)
james@james-Inspiron-1764:~/python/headfirst/chapter2/nester$ sudo python3.3 setup.py install
[sudo] password for james:
/usr/lib/python3.3/distutils/dist.py:257: UserWarning: Unknown distribution option: 'pymodules'
warnings.warn(msg)
running install
running build
running install_egg_info
Removing /usr/local/lib/python3.3/dist-packages/nester_jc-1.4.0.egg-info
Writing /usr/local/lib/python3.3/dist-packages/nester_jc-1.4.0.egg-info
如果从@ / python / headfirst / chapter2 / nester内部启动python,我可以成功导入nester,但如果我从任何其他位置开始,则不能。 这是我安装模块的方式有问题,还是我的python安装有问题?