2017-10-08 99 views
0

最近放了一個小項目來熟悉Python。在進行項目分配的過程中,我創建了以下setup.py安裝我的Python 3軟件包問題

# -*- 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,我得到一個大「醇語法錯誤:

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版本。

回答

0

看起來你也安裝使用python2.7「BYI」包可能使用python setup.py install

當您運行控制檯腳本BYI,墊片腳本可能指向Python 2.7版。您可以通過查看生成的填充腳本的第一行來確認: head -1 /usr/local/bin/byi

您可以嘗試刪除腳本/usr/local/bin/byi並使用python3重新運行安裝程序。這應該會在源代碼中生成一個新的shim腳本。您還可以通過添加附加選項來控制使用哪個python: options = { 'build_scripts': { 'executable': '/usr/bin/env python3', }, } setup.py

此外,它看起來像您的軟件包與python 2.7不兼容。錯誤的行將在python 2.7上失敗,因爲舊版本除了一個元組而不是函數參數: print '➲ ',而不是print('➲ ', end='')

如果你想要的Python 2.x的支持,您可以安裝six module

+0

有沒有在你的下一個到最後一個段落中的兩個'print'語句之間沒有什麼區別。 –

+0

有一個小的差異。看到打印後的空間。首先,由於空間的原因,它將被視爲一個元組。而在第二,它將被視爲功能參數。 – sukrit007

+0

我知道空間在那裏。我的意思是說沒有功能上的差異。空間並不重要。無論空間是否在它之前,對於元組來說這都是無效的語法。 –