Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Windows上安装Python脚本?_Python_Python 3.x - Fatal编程技术网

如何在Windows上安装Python脚本?

如何在Windows上安装Python脚本?,python,python-3.x,Python,Python 3.x,我用Python编写了一个小的命令行实用程序。我还创建了setup.py脚本: try: from setuptools import setup except ImportError: from distutils.core import setup config = { 'name': 'clitool', 'author': 'aa', 'author_email': 'ww', 'version': '1.0-rc', 'inst

我用Python编写了一个小的命令行实用程序。我还创建了setup.py脚本:

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

config = {
    'name': 'clitool',
    'author': 'aa',
    'author_email': 'ww',
    'version': '1.0-rc',
    'install_requires': ['nose'],
    'packages': [],
    'scripts': ['clitool']
}

setup(**config)
当我打电话时:

setup.py install
我的脚本复制到
C:\Python34\Scripts
path。此路径位于path变量中,但Windows在尝试从某些目录写入启动clitool时:

"clitool" not recognized as an internal or external command
可以从任何目录运行,仅从扩展名为exe的
C:\Python34\Scripts
中的文件运行。
但是我的脚本被复制为一个没有扩展名的文件,在Windows中它不会运行它。

解决方案:

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

config = {
    'name': 'clitool',
    'author': 'aa',
    'author_email': 'ww',
    'version': '1.0-rc',
    'install_requires': ['nose'],
    'packages': [],    
    'entry_points' : {
        'console_scripts': ['clitool=clitool.cli:main'],
    }
}

setup(**config)

您是从Windows资源管理器还是cmd.exe运行此操作?您是否尝试过
clitool.py
?它应该有一个
.py
扩展名(尽管还有其他扩展名)@cdarke,
clitool.py
是可以工作的,但是我想编写它,以便在没有.py扩展名的情况下调用该实用程序为什么?在Windows上(与UNIX/Linux/OS X不同),除非您设置文件扩展名,否则shell(Windows资源管理器、cmd.exe、powershell)无法识别文件的类型。shell使用它作为Windows注册表的查找,以发现应该运行哪个程序。有一个默认值,但您必须编写一个
.cmd
文件来运行python。这就是你想要的吗?不,我想了解像
django admin
这样的实用程序是如何工作的5月份的入口点示例