python开发模式下安装包失败

1 投票
1 回答
780 浏览
提问于 2025-04-17 19:44

我正在尝试设置一个简单的开发模式包:

setup.py

from setuptools import setup, find_packages

setup(
    name='rocflavors',
    version='0.0.1',
    packages=find_packages(exclude=['ez_setup','examples','tests']),
    license='Creative Commons Attribution-Noncommercial-Share Alike license',
    long_description=open('README').read(),
    install_requires=[],
)

尝试设置:(如果我用 python setup.py install,能成功)

(relux)roc-web5537:roc-flavors cmuench$ python setup.py install develop
running install
running bdist_egg
running egg_info
writing rocflavors.egg-info/PKG-INFO
writing top-level names to rocflavors.egg-info/top_level.txt
writing dependency_links to rocflavors.egg-info/dependency_links.txt
reading manifest file 'rocflavors.egg-info/SOURCES.txt'
writing manifest file 'rocflavors.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.7-intel/egg
running install_lib
running build_py
creating build/bdist.macosx-10.7-intel/egg
creating build/bdist.macosx-10.7-intel/egg/rocflavors
copying build/lib/rocflavors/__init__.py -> build/bdist.macosx-10.7-intel/egg/rocflavors
copying build/lib/rocflavors/models.py -> build/bdist.macosx-10.7-intel/egg/rocflavors
creating build/bdist.macosx-10.7-intel/egg/rocflavors/templatetags
copying build/lib/rocflavors/templatetags/__init__.py -> build/bdist.macosx-10.7-intel/egg/rocflavors/templatetags
copying build/lib/rocflavors/templatetags/rocflavors_extras.py -> build/bdist.macosx-10.7-intel/egg/rocflavors/templatetags
copying build/lib/rocflavors/urls.py -> build/bdist.macosx-10.7-intel/egg/rocflavors
copying build/lib/rocflavors/views.py -> build/bdist.macosx-10.7-intel/egg/rocflavors
byte-compiling build/bdist.macosx-10.7-intel/egg/rocflavors/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.7-intel/egg/rocflavors/models.py to models.pyc
byte-compiling build/bdist.macosx-10.7-intel/egg/rocflavors/templatetags/__init__.py to __init__.pyc
byte-compiling build/bdist.macosx-10.7-intel/egg/rocflavors/templatetags/rocflavors_extras.py to rocflavors_extras.pyc
byte-compiling build/bdist.macosx-10.7-intel/egg/rocflavors/urls.py to urls.pyc
byte-compiling build/bdist.macosx-10.7-intel/egg/rocflavors/views.py to views.pyc
creating build/bdist.macosx-10.7-intel/egg/EGG-INFO
copying rocflavors.egg-info/PKG-INFO -> build/bdist.macosx-10.7-intel/egg/EGG-INFO
copying rocflavors.egg-info/SOURCES.txt -> build/bdist.macosx-10.7-intel/egg/EGG-INFO
copying rocflavors.egg-info/dependency_links.txt -> build/bdist.macosx-10.7-intel/egg/EGG-INFO
copying rocflavors.egg-info/top_level.txt -> build/bdist.macosx-10.7-intel/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/rocflavors-0.0.1-py2.7.egg' and adding 'build/bdist.macosx-10.7-intel/egg' to it
removing 'build/bdist.macosx-10.7-intel/egg' (and everything under it)
Processing rocflavors-0.0.1-py2.7.egg
Removing /Users/cmuench/.virtualenvs/relux/lib/python2.7/site-packages/rocflavors-0.0.1-py2.7.egg
Copying rocflavors-0.0.1-py2.7.egg to /Users/cmuench/.virtualenvs/relux/lib/python2.7/site-packages
rocflavors 0.0.1 is already the active version in easy-install.pth

Installed /Users/cmuench/.virtualenvs/relux/lib/python2.7/site-packages/rocflavors-0.0.1-py2.7.egg
Processing dependencies for rocflavors==0.0.1
Finished processing dependencies for rocflavors==0.0.1
running develop
Checking .pth file support in build/bdist.macosx-10.7-intel/egg
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 2] No such file or directory: 'build/bdist.macosx-10.7-intel/egg/test-easy-install-35540.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    build/bdist.macosx-10.7-intel/egg

This directory does not currently exist.  Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).

我有三个问题:

  1. 为什么在开发模式下不工作。
  2. 开发模式和不使用它有什么区别?
  3. 为什么它需要是一个包?如果我在包里的 .py 文件里做了修改,怎么才能把它更新到我的包目录里?我觉得我不太明白打包的意义。修改时会把编译后的 Python 代码放进包里吗?

1 个回答

0

确保你的虚拟环境已经激活。不要用 python setup.py install develop,试试用 pip install -e .。注意那个 .,它表示你必须在包含 setup.py 文件的目录下。如果这个方法失败了,可以试着加上 sudo

关于 pip 的文档可以查看这里:http://www.pip-installer.org/

撰写回答