Python setup.py install 后的包无法导入

2017-06-30 11:05:49 +08:00
 beeeta

本人试用 python 打包工具 setuptools

使用 python setup.py install 安装本地创建的测试项目 topackage:

console 的日志如下: running install running bdist_egg running egg_info writing topackage.egg-info\PKG-INFO writing dependency_links to topackage.egg-info\dependency_links.txt writing top-level names to topackage.egg-info\top_level.txt reading manifest file 'topackage.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'topackage.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py creating build\bdist.win-amd64\egg creating build\bdist.win-amd64\egg\pack copying build\lib\pack\prt.py -> build\bdist.win-amd64\egg\pack copying build\lib\pack_init_.py -> build\bdist.win-amd64\egg\pack byte-compiling build\bdist.win-amd64\egg\pack\prt.py to prt.cpython-35.pyc byte-compiling build\bdist.win-amd64\egg\pack_init_.py to init.cpython-35.pyc creating build\bdist.win-amd64\egg\EGG-INFO copying topackage.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO copying topackage.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO copying topackage.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO copying topackage.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO zip_safe flag not set; analyzing archive contents... creating 'dist\topackage-0.1-py3.5.egg' and adding 'build\bdist.win-amd64\egg' to it removing 'build\bdist.win-amd64\egg' (and everything under it) Processing topackage-0.1-py3.5.egg Removing d:\python35\lib\site-packages\topackage-0.1-py3.5.egg Copying topackage-0.1-py3.5.egg to d:\python35\lib\site-packages topackage 0.1 is already the active version in easy-install.pth

Installed d:\python35\lib\site-packages\topackage-0.1-py3.5.egg Processing dependencies for topackage==0.1 Finished processing dependencies for topackage==0.1

安装完成后: 进入 python console 界面,输入 import topackage ,提示 topackage 找不到..

6676 次点击
所在节点    Python
4 条回复
beeeta
2017-06-30 11:08:24 +08:00
+ _ + 找到原因了。安装的项目,但是导入的时候不能导入项目名称而应该选择项目下的包名。
比如我这里的目录结构:
topackage
|
---pack
beeeta
2017-06-30 11:15:21 +08:00
上一条操作失误,直接飞出去了....找不到 V2EX 的删除评论按钮...重新来一发

+ _ + 找到原因了。安装的项目,但是导入的时候不能导入项目名称而应该选择项目下的包名。
比如我这里的目录结构:
topacakge
|
|---pack
| |- prt.py
| |-__init__.py
|---READM.rst
|---MANIFEST.in
|---setup.py

安装的时候在 topackage 目录下:
python setup.py install
导入包的时候使用:
import pack.prt
或者 import pack

=======================
小白的青涩领域与记忆
beeeta
2017-06-30 11:15:43 +08:00
青涩领悟...
bravecarrot
2017-06-30 11:25:30 +08:00
倒入的包名字问题 十有八九是这样

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/372112

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX