首页 > 解决方案 > pip 脚本未运行

问题描述

我使用这个命令来上传 pypi pkg

python2 setup.py sdist
python2 setup.py bdist_wheel
python2 -m twine upload dist/* --skip-exis

我的包 https://pypi.org/project/abir/0.1/

当我 inatall pip install abir in install 成功但是当我运行 abir 它告诉我这个错误任何人都可以帮助我解决这个问题

/data/data/com.termux/files/usr/bin/abir: line 2: import: command not found
/data/data/com.termux/files/usr/bin/abir: line 3: from: command not found
/data/data/com.termux/files/usr/bin/abir: line 4: try:: command not found
/data/data/com.termux/files/usr/bin/abir: line 5: import: command not found
/data/data/com.termux/files/usr/bin/abir: line 6: except: command not found
/data/data/com.termux/files/usr/bin/abir: line 7: syntax error near unexpected token `'pip2 install mechanize''
/data/data/com.termux/files/usr/bin/abir: line 7: `    os.system('pip2 install mechanize')'

检查那个pypi文件并告诉我 这个脚本版本是python2.7的答案

我的 setup.py 文件

import setuptools
with open("README.md", "r") as fh:
    long_description = fh.read()
setuptools.setup(
     name='abir',
     version='0.1',
     scripts=['abir'] ,
     author="ABIR HOSSAIN",
     author_email="abirhossain200019@gmail.com",
     description="this is a test file",
     long_description=long_description,
   long_description_content_type="text/markdown",
     url="https://github.com/ABIRHOSSAIN10/test",
     packages=setuptools.find_packages(),
     classifiers=[
         "Programming Language :: Python :: 2.7",
         "License :: OSI Approved :: MIT License",
         "Operating System :: OS Independent",
     ],
 )

标签: python-3.xpython-2.7pippypi

解决方案


您的脚本abir不是以shebang开头的,因此命令行 shell 假定它是一个 shell 脚本。因此,这不是这些语法错误。

要修复脚本:

添加一个shebang:插入

#!/usr/bin/python

或者

#!/usr/bin/env python

作为脚本的第一行。

增加版本;做它0.1.10.2

生成一个新的 sdist 和一个新的 wheel 包。

将新包上传到 PyPI。升级:

pip install -U abir

测试:

abir

推荐阅读