【问题标题】:Issue installing my Python 3 package安装我的 Python 3 包时出现问题
【发布时间】:2017-10-08 06:25:17
【问题描述】:

最近整理了一个小项目来熟悉一下Python。在使项目可分发的过程中,我创建了以下setup.py

# -*- coding: utf-8 -*-


import re
from setuptools import setup


setup(
    name = 'bfi',
    packages = ['bfi'],
    entry_points = {
        'console_scripts' : ['bfi = bfi.bfi:main']
    },
    version = '1.0',
    description = 'Brainf*ck Interpreter w/Shell-Mode',
    author = 'Kyle Martinez',
    install_requires = ['getch', 'overloading']
)

然后我尝试从命令行安装软件包,如下所示:

python3 setup.py install

这似乎有效!运行命令会给我以下输出:

running install
running bdist_egg
running egg_info
writing requirements to bfi.egg-info/requires.txt
writing top-level names to bfi.egg-info/top_level.txt
writing bfi.egg-info/PKG-INFO
writing dependency_links to bfi.egg-info/dependency_links.txt
writing entry points to bfi.egg-info/entry_points.txt
reading manifest file 'bfi.egg-info/SOURCES.txt'
writing manifest file 'bfi.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.6-intel/egg
running install_lib
running build_py
creating build/bdist.macosx-10.6-intel/egg
creating build/bdist.macosx-10.6-intel/egg/bfi
copying build/lib/bfi/__init__.py -> build/bdist.macosx-10.6-intel/egg/bfi
copying build/lib/bfi/__main__.py -> build/bdist.macosx-10.6-intel/egg/bfi
copying build/lib/bfi/bfi.py -> build/bdist.macosx-10.6-intel/egg/bfi
copying build/lib/bfi/bficore.py -> build/bdist.macosx-10.6-intel/egg/bfi
byte-compiling build/bdist.macosx-10.6-intel/egg/bfi/__init__.py to __init__.cpython-34.pyc
byte-compiling build/bdist.macosx-10.6-intel/egg/bfi/__main__.py to __main__.cpython-34.pyc
byte-compiling build/bdist.macosx-10.6-intel/egg/bfi/bfi.py to bfi.cpython-34.pyc
byte-compiling build/bdist.macosx-10.6-intel/egg/bfi/bficore.py to bficore.cpython-34.pyc
creating build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying bfi.egg-info/PKG-INFO -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying bfi.egg-info/SOURCES.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying bfi.egg-info/dependency_links.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying bfi.egg-info/entry_points.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying bfi.egg-info/requires.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
copying bfi.egg-info/top_level.txt -> build/bdist.macosx-10.6-intel/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating 'dist/bfi-1.0-py3.4.egg' and adding 'build/bdist.macosx-10.6-intel/egg' to it
removing 'build/bdist.macosx-10.6-intel/egg' (and everything under it)
Processing bfi-1.0-py3.4.egg
Removing /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bfi-1.0-py3.4.egg
Copying bfi-1.0-py3.4.egg to /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
bfi 1.0 is already the active version in easy-install.pth
Installing bfi script to /Library/Frameworks/Python.framework/Versions/3.4/bin
Installed /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bfi-1.0-py3.4.egg 
Processing dependencies for bfi==1.0
Searching for overloading==0.5.0
Best match: overloading 0.5.0
Adding overloading 0.5.0 to easy-install.pth file

Using /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Searching for getch==1.0
Best match: getch 1.0
Adding getch 1.0 to easy-install.pth file

Using /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages
Finished processing dependencies for bfi==1.0 

但是,当我转到命令行并运行 bfi 时,我得到一个很大的 'ol SyntaxError:

Traceback (most recent call last):
  File "/usr/local/bin/bfi", line 9, in <module>
    load_entry_point('bfi==1.0', 'console_scripts', 'bfi')()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", li
ne 357, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", li
ne 2394, in load_entry_point
    return ep.load()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", li
ne 2108, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/Library/Python/2.7/site-packages/bfi-1.0-py2.7.egg/bfi/bfi.py", line 42
    print('➲ ', end='')
                     ^
SyntaxError: invalid syntax 

我对这一切有点陌生,所以如果我能得到任何帮助,我将不胜感激!我该如何解决这个问题?

注意:您可能已经推断,我的 Macbook 安装了多个版本的 Python。

【问题讨论】:

    标签: python packages setup.py


    【解决方案1】:

    看起来您还使用 python2.7 安装了“byi”包,可能使用 python setup.py install

    当您运行控制台脚本 byi 时,shim 脚本可能指向 python 2.7。您可以通过查看生成的 shim 脚本的第一行来确认: head -1 /usr/local/bin/byi

    您可以尝试删除脚本 /usr/local/bin/byi 并使用 python3 重新运行设置。这应该在源代码中生成一个带有 python3 的新 shim 脚本。您还可以通过添加其他选项来控制要使用的 python: options = { 'build_scripts': { 'executable': '/usr/bin/env python3', }, } 在 setup.py 中

    此外,您的软件包似乎与 python 2.7 不兼容。错误行将在 python 2.7 上失败,因为旧版本除了元组而不是函数 args: print '➲ ', 而不是 print('➲ ', end='')

    如果你确实想要 python 2.x 支持,你可以安装six module

    【讨论】:

    • 倒数第二段中的两个print 语句没有区别。
    • 略有不同。打印后查看空格。首先,由于空间的原因,它将被视为一个元组。而在第二个中,它将被视为函数参数。
    • 我知道空间在那里。我的意思是没有功能区别。空间无所谓。无论空格是否在它之前,这对于元组来说都是无效的语法。
    • 所以我删除了 /usr/local/bin 中的脚本并使用 python3 重新安装。但是,调用 bfi 不是一个有效的命令。回顾安装日志,bfi 似乎被安装到:“/Library/Frameworks/Python.framework/Versions/3.4/bin”。将其添加到我的路径中,现在它可以工作了。我有必要这样做吗?为什么用 Python3 安装时不安装到 /usr/local/bin?
    • @sukrit007 有什么想法吗?
    猜你喜欢
    • 2013-09-06
    • 2016-10-11
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    相关资源
    最近更新 更多