V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
beeeta
V2EX  ›  Python

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

  •  
  •   beeeta · 2017-06-30 11:05:49 +08:00 · 6812 次点击
    这是一个创建于 2709 天前的主题,其中的信息可能已经有所发展或是发生改变。

    本人试用 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 找不到..

    4 条回复    2017-06-30 11:25:30 +08:00
    beeeta
        1
    beeeta  
    OP
       2017-06-30 11:08:24 +08:00
    + _ + 找到原因了。安装的项目,但是导入的时候不能导入项目名称而应该选择项目下的包名。
    比如我这里的目录结构:
    topackage
    |
    ---pack
    beeeta
        2
    beeeta  
    OP
       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
        3
    beeeta  
    OP
       2017-06-30 11:15:43 +08:00
    青涩领悟...
    bravecarrot
        4
    bravecarrot  
       2017-06-30 11:25:30 +08:00 via iPhone
    倒入的包名字问题 十有八九是这样
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2198 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 00:48 · PVG 08:48 · LAX 16:48 · JFK 19:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.