gpt4 book ai didi

python - console_scripts 入口点被忽略?

转载 作者:行者123 更新时间:2023-12-04 05:25:17 25 4
gpt4 key购买 nike

我在 Windows 上使用 setuptools(版本 0.6c11),并指定要通过 console_scripts 安装的控制台脚本入口点。它在 Linux 上运行良好,但在 Windows 下,使用 MinGW 编译器,没有安装脚本。我在安装输出中没有看到任何相关消息。

其他软件包,如 ipython,运行良好,运行 setup.py install 后有工作的 .exe 文件。 .

有人可以建议一种调试方法吗?

import setuptools
setup(
# ...
entry_points={
'console_scripts':[
'myprog = myMod:main'
]
}
)

更新:

根据 Vinay 提出的示例(谢谢!),我能够隔离问题:如果模块安装在嵌套子目录中,则不会创建脚本:
import setuptools, os.path, shutil

SOURCE = '''
def main():
print('Hello, world!')
'''

### ERROR: when level of subdir is > 1, script is not created
subdir='subdir/subdir2'

### OK: with single-level subdirectory, everything works just fine
# subdir='subdir'

def prepare():
# remove previous source
if os.path.exists('subdir'): shutil.rmtree('subdir')
# create subdirs as necessary
os.makedirs(subdir)
with open(subdir+'/my_mod.py', 'w') as f: f.write(SOURCE)

prepare()

setuptools.setup(
name = 'myprog',
version = '0.1',
url = 'http://dummy.com/',
author = 'Me',
author_email = 'me@dummy.com',
py_modules=['my_mod'],
package_dir={'':subdir},
entry_points={
'console_scripts':['myprog = my_mod:main']
},
zip_safe=False
)

我误解了什么是 package_dir为了?

最佳答案

好吧,这对我有用:

# This file is setup.py
import setuptools

SOURCE = '''
def main():
print('Hello, world!')
'''

def prepare():
with open('my_mod.py', 'w') as f:
f.write(SOURCE)

prepare()

setuptools.setup(
name = 'woo',
version = '0.1',
url = 'http://dummy.com/',
author = 'Me',
author_email = 'me@dummy.com',
py_modules=['my_mod'],
entry_points={
'console_scripts':['myprog = my_mod:main']
}
)

当我在 virtualenv 中运行它时:
(venv) C:\temp\exemplar>python setup.py install
running install
running bdist_egg
running egg_info
writing woo.egg-info\PKG-INFO
writing top-level names to woo.egg-info\top_level.txt
writing dependency_links to woo.egg-info\dependency_links.txt
writing entry points to woo.egg-info\entry_points.txt
reading manifest file 'woo.egg-info\SOURCES.txt'
writing manifest file 'woo.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib
copying my_mod.py -> build\lib
creating build\bdist.win32
creating build\bdist.win32\egg
copying build\lib\my_mod.py -> build\bdist.win32\egg
byte-compiling build\bdist.win32\egg\my_mod.py to my_mod.pyc
creating build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\PKG-INFO -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\SOURCES.txt -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\dependency_links.txt -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\entry_points.txt -> build\bdist.win32\egg\EGG-INFO
copying woo.egg-info\top_level.txt -> build\bdist.win32\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist\woo-0.1-py2.7.egg' and adding 'build\bdist.win32\egg' to it
removing 'build\bdist.win32\egg' (and everything under it)
Processing woo-0.1-py2.7.egg
creating c:\temp\venv\lib\site-packages\woo-0.1-py2.7.egg
Extracting woo-0.1-py2.7.egg to c:\temp\venv\lib\site-packages
Adding woo 0.1 to easy-install.pth file
Installing myprog-script.py script to C:\temp\venv\Scripts
Installing myprog.exe script to C:\temp\venv\Scripts

Installed c:\temp\venv\lib\site-packages\woo-0.1-py2.7.egg
Processing dependencies for woo==0.1
Finished processing dependencies for woo==0.1

(venv) C:\temp\exemplar>pip uninstall woo
Uninstalling woo:
c:\temp\venv\lib\site-packages\woo-0.1-py2.7.egg
c:\temp\venv\scripts\myprog-script.py
c:\temp\venv\scripts\myprog.exe
Proceed (y/n)? y
Successfully uninstalled woo

(venv) C:\temp\exemplar>

更新:

您的问题是没有使用正确的路径分隔符:使用

子目录='子目录\\子目录2'

为我工作。当然,您可能应该使用 os.path.join() .

关于python - console_scripts 入口点被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13271085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com